Implementation of parallel query of one column in oracle

Source: Internet
Author: User
Tags oracle rownum

It takes too long to execute SQL statements in oracle databases. The result set cannot be obtained at all. The load on the server is not high, and it is estimated that it is a query that consumes a lot of disks. This problem is solved through the parallel query of one column in oracle.

Sure enough, we found a million table and a hash join with more than million tables.
After a SQL statement is optimized, the SQL statement is as follows:

 
 
  1.     select     count(ui.usin_uid_fk)  
  2.      from table1 av, table2 ui  
  3. where av.av_usse_activatedate >= to_date('20090102', 'yyyymmdd')  
  4.      and av.av_usse_activatedate < to_date('20090401', 'yyyymmdd')  
  5.      and av.av_usse_uid_fk = ui.usin_uid_fk  
  6.      and ui.usin_mcnc_fk =XXX%' 

It is hard to imagine that the execution is not ideal. The execution time of the last 20 minutes is really crashing.

 
 
  1. COUNT(UI.USIN_UID_FK)  
  2. ---------------------  
  3.  1918591  
  4.  
  5. Elapsed: 00:19:03.07  
  6. Statistics  
  7. ----------------------------------------------------------  
  8. 0     recursive calls  
  9. 0     db block gets  
  10.      32921639     consistent gets  
  11.   352073     physical reads  
  12. 0     redo size  
  13.    395     bytes sent via SQL*Net to client  
  14.    503     bytes received via SQL*Net from client  
  15. 2     SQL*Net roundtrips to/from client  
  16. 0     sorts (memory)  
  17. 0     sorts (disk)  
  18. 1     rows processed  

For the large table of table 2 that meets the condition of more than 1100 million), it is decided to increase the execution speed through parallel. The SQL statement is as follows:

 
 
  1. select /*+parallel (tbl_userinfo 4)*/ count(ui.usin_uid_fk)  
  2. from table1 av, table2 ui  
  3. where av.av_usse_activatedate >= to_date('20090101', 'yyyymmdd')  
  4. and av.av_usse_activatedate < to_date('20090401', 'yyyymmdd')  
  5. and av.av_usse_uid_fk = ui.usin_uid_fk  
  6. and ui.usin_mcnc_fk like 'XXX%'; 

The execution effect is very obvious. From 19 minutes to 1 minute 45 seconds! The consistent gets is reduced by an order of magnitude.

 
 
  1.  COUNT(UI.USIN_UID_FK)  
  2. ---------------------  
  3.  1918591  
  4.  
  5. Elapsed: 00:01:45.15  
  6.  
  7. Statistics  
  8. ----------------------------------------------------------  
  9. 0     recursive calls  
  10. 0     db block gets  
  11.  2571109     consistent gets  
  12.   124523     physical reads  
  13. 0     redo size  
  14.    395     bytes sent via SQL*Net to client  
  15.    504     bytes received via SQL*Net from client  
  16. 2     SQL*Net roundtrips to/from client  
  17. 0     sorts (memory)  
  18. 0     sorts (disk)  
  19. 1     rows processed  

Because the server has a 2x4 Core cpu, it can be regarded as eight CPUs, so we can further reduce the execution time by increasing the degree of parallelism. The following SQL statement:

 
 
  1.     SQL> select /*+parallel (tbl_userinfo 8)*/ count(ui.usin_uid_fk)  
  2.      2  from table1 av, table2 ui  
  3.      3     where av.av_usse_activatedate >= to_date('20090101', 'yyyymmdd')  
  4.      4  and av.av_usse_activatedate < to_date('20090401', 'yyyymmdd')  
  5.      5  and av.av_usse_uid_fk = ui.usin_uid_fk  
  6.      6  and ui.usin_mcnc_fk like '460%';  
  7.  
  8. COUNT(UI.USIN_UID_FK)  
  9. ---------------------  
  10.  1949033  
  11.  
  12. Elapsed: 00:00:20.60  
  13.  
  14. Statistics  
  15. ----------------------------------------------------------  
  16. 0     recursive calls  
  17. 0     db block gets  
  18.   2607524     consistent gets  
  19.       55050     physical reads  
  20. 0     redo size  
  21.    395     bytes sent via SQL*Net to client  
  22.    503     bytes received via SQL*Net from client  
  23. 2     SQL*Net roundtrips to/from client  
  24. 0     sorts (memory)  
  25. 0     sorts (disk)  
  26. 1     rows processed  


It can be said that it is still ideal. It takes only about 20 s. Although the maximum degree of parallelism can reach CPU * 2, the effect may not be good. Perform a test on 16 parallel SQL statements.

 
 
  1.       COUNT(UI.USIN_UID_FK)  
  2. ---------------------  
  3.  1949033  
  4.  
  5. Elapsed: 00:00:20.64  
  6.  
  7. Statistics  
  8. ----------------------------------------------------------  
  9. 0     recursive calls  
  10. 0     db block gets  
  11.  2607524     consistent gets  
  12.       55299     physical reads  
  13. 0     redo size  
  14.    395     bytes sent via SQL*Net to client  
  15.    504     bytes received via SQL*Net from client  
  16. 2     SQL*Net roundtrips to/from client  
  17. 0     sorts (memory)  
  18. 0     sorts (disk)  
  19. 1     rows processed        
  20.  

There is no improvement, and the execution time is slightly higher than the SQL statement with a degree of parallelism of 8.

Through the above tests, we can easily find that:

When processing a large amount of data queries, such as hash join, oracle Parallel Processing is very effective. That is to say, parallel queries can be used in applications such as data warehouses ".

However, there are still many restrictions on the parallel use of oracle. For example, relatively small data queries and connections are counterproductive. Blindly increasing the degree of parallelism is also a big worry. Relatively speaking, the degree of parallelism is better than the number of CPUs. The number of CPUs here should be the number of cores. For example, if the CPU on the server is 4 cores and the degree of parallelism is 4, it is good.

It is difficult to have perfect technologies. The most important thing is that the use of specific technologies should be just right, to ensure the advantages and circumvent weaknesses.
 

Use of oracle rownum statements

Oracle index type

How to create an Oracle Index

C # connect to the Oracle database to query data

Instances that use oracle Stored Procedure Paging

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.