HelloDBA [中文]
Search Internet Search HelloDBA
  Oracle Technology Site. email: fuyuncat@gmail.com  MSN: fuyuncat@hotmail.com Add to circle  acoug  acoug 

Test Around Small Table Threshold

[中文]

Author:  fuyuncat

Source:  www.HelloDBA.com

Date:  2011-12-29 08:53:12

Share to  Twitter Facebook GMail Blogger Orkut Google Bookmarks Sina Weibo QQ Renren Tieba Kaixin Douban Taobao

We know, the parameter "_small_table_threshold" decides a table is a small table or not. When full scan on large tables, in LRU algorithm, the data blocks will be put in a different position in LRU list other than small tables; while when performing some other data-intensive operations, such as parallel query or direct load, data blocks will be read directly from disk bypassing buffer cache.

Defaultly, it's automatically set by oracle as 2% of "_db_block_buffers" when instance start up. For instance, in my testing db (10.2.0.4)

SQL代码
  1. HELLODBA.COM>select name, value from all_parameters where name = '_db_block_buffers';  
  2.   
  3. NAME                           VALUE  
  4. ------------------------------ ------------------------------  
  5. _db_block_buffers              15918  
  6.   
  7. HELLODBA.COM>select name, value from all_parameters where name = '_small_table_threshold';  
  8.   
  9. NAME                           VALUE  
  10. ------------------------------ ------------------------------  
  11. _small_table_threshold         318  

Here, "_db_block_buffers" is 15918, thereby, "_small_table_threshold"=15918*0.02=318.

To show how it becomes effective, we can simply run a parallel query on a testing table.

SQL代码
  1. HELLODBA.COM>create table dummy_tab as select a.* from dba_tables a, dba_tables b where rownum<=10650;  
  2.   
  3. Table created.  
  4.   
  5. HELLODBA.COM>exec dba_seg_info('DEMO','TABLE','DUMMY_TAB');  
  6. Free Blocks.............................  
  7. Total Blocks............................384  
  8. Total Bytes.............................3145728  
  9. Unused Blocks...........................52  
  10. Unused Bytes............................425984  
  11. Last Used Ext FileId....................5  
  12. Last Used Ext BlockId...................265097  
  13. Last Used Block.........................76  
  14.  *************************************************  
  15. The segment is analyzed  
  16. 0% -- 25% free space blocks.............0  
  17. 0% -- 25% free space bytes..............0  
  18. 25% -- 50% free space blocks............0  
  19. 25% -- 50% free space bytes.............0  
  20. 50% -- 75% free space blocks............0  
  21. 50% -- 75% free space bytes.............0  
  22. 75% -- 100% free space blocks...........0  
  23. 75% -- 100% free space bytes............0  
  24. Unused Blocks...........................0  
  25. Unused Bytes............................0  
  26. Total Blocks............................318  
  27. Total bytes.............................2605056  
  28.   
  29. PL/SQL procedure successfully completed.  

We just created a test table, whose number of blocks is equal to the threshold. And now parallel query it,

SQL代码
  1. HELLODBA.COM>set autot trace  
  2. HELLODBA.COM>select /*+parallel(t 2)*/* from dummy_tab t;  
  3.   
  4. 10650 rows selected.  
  5.   
  6.   
  7. Execution Plan  
  8. ----------------------------------------------------------  
  9. Plan hash value: 2889160364  
  10.   
  11. ---------------------------------------------------------------------------------------------------------------  
  12. | Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |  
  13. ---------------------------------------------------------------------------------------------------------------  
  14. |   0 | SELECT STATEMENT     |           | 12237 |  5963K|   372   (1)| 00:00:02 |        |      |         |  
  15. |   1 |  PX COORDINATOR      |           |       |       |            |          |        |      |         |  
  16. |   2 |   PX SEND QC (RANDOM)| :TQ10000  | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | P->S | QC (RAND)  |  
  17. |   3 |    PX BLOCK ITERATOR |           | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | PCWC |         |  
  18. |   4 |     TABLE ACCESS FULL| DUMMY_TAB | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | PCWP |         |  
  19. ---------------------------------------------------------------------------------------------------------------  
  20.   
  21. Note  
  22. -----  
  23.    - dynamic sampling used for this statement  
  24.   
  25.   
  26. Statistics  
  27. ----------------------------------------------------------  
  28.        1587  recursive calls  
  29.           3  db block gets  
  30.         718  consistent gets  
  31.         318  physical reads  
  32.         780  redo size  
  33.      254481  bytes sent via SQL*Net to client  
  34.        8291  bytes received via SQL*Net from client  
  35.         711  SQL*Net roundtrips to/from client  
  36.           7  sorts (memory)  
  37.           0  sorts (disk)  
  38.       10650  rows processed  
  39.   
  40. HELLODBA.COM>select /*+parallel(t 2)*/* from dummy_tab t;  
  41.   
  42. 10650 rows selected.  
  43.   
  44.   
  45. Execution Plan  
  46. ----------------------------------------------------------  
  47. Plan hash value: 2889160364  
  48.   
  49. ---------------------------------------------------------------------------------------------------------------  
  50. | Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |  
  51. ---------------------------------------------------------------------------------------------------------------  
  52. |   0 | SELECT STATEMENT     |           | 12237 |  5963K|   372   (1)| 00:00:02 |        |      |         |  
  53. |   1 |  PX COORDINATOR      |           |       |       |            |          |        |      |         |  
  54. |   2 |   PX SEND QC (RANDOM)| :TQ10000  | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | P->S | QC (RAND)  |  
  55. |   3 |    PX BLOCK ITERATOR |           | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | PCWC |         |  
  56. |   4 |     TABLE ACCESS FULL| DUMMY_TAB | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | PCWP |         |  
  57. ---------------------------------------------------------------------------------------------------------------  
  58.   
  59. Note  
  60. -----  
  61.    - dynamic sampling used for this statement  
  62.   
  63.   
  64. Statistics  
  65. ----------------------------------------------------------  
  66.           6  recursive calls  
  67.           0  db block gets  
  68.         421  consistent gets  
  69.           0  physical reads  
  70.           0  redo size  
  71.      256926  bytes sent via SQL*Net to client  
  72.        8291  bytes received via SQL*Net from client  
  73.         711  SQL*Net roundtrips to/from client  
  74.           1  sorts (memory)  
  75.           0  sorts (disk)  
  76.       10650  rows processed  

In the 2nd round, there is no physical reads reported, which means the data blocks read in the 1st round has been cached and data blocks were read from buffer cache in the 2nd round, and also saying, it's small table, so far.

Now, we append some data into it, raise the HWM up.

SQL代码
  1. HELLODBA.COM>insert /*+append*/into dummy_tab select * from t_tables where rownum<=30;  
  2.   
  3. 30 rows created.  
  4.   
  5. HELLODBA.COM>commit;  
  6.   
  7. Commit complete.  
  8.   
  9. HELLODBA.COM>exec dba_seg_info('DEMO','TABLE','DUMMY_TAB');  
  10. Free Blocks.............................  
  11. Total Blocks............................384  
  12. Total Bytes.............................3145728  
  13. Unused Blocks...........................51  
  14. Unused Bytes............................417792  
  15. Last Used Ext FileId....................5  
  16. Last Used Ext BlockId...................265481  
  17. Last Used Block.........................77  
  18.  *************************************************  
  19. The segment is analyzed  
  20. 0% -- 25% free space blocks.............0  
  21. 0% -- 25% free space bytes..............0  
  22. 25% -- 50% free space blocks............0  
  23. 25% -- 50% free space bytes.............0  
  24. 50% -- 75% free space blocks............0  
  25. 50% -- 75% free space bytes.............0  
  26. 75% -- 100% free space blocks...........0  
  27. 75% -- 100% free space bytes............0  
  28. Unused Blocks...........................0  
  29. Unused Bytes............................0  
  30. Total Blocks............................319  
  31. Total bytes.............................2613248  
  32.   
  33. PL/SQL procedure successfully completed.  

Noted that 1 block was added, just over threshold. Now, run parallel query again,

SQL代码
  1. HELLODBA.COM>set autot trace statistics  
  2. HELLODBA.COM>select /*+parallel(t 2)*/* from dummy_tab t;  
  3.   
  4. 10680 rows selected.  
  5.   
  6.   
  7. Statistics  
  8. ----------------------------------------------------------  
  9.           6  recursive calls  
  10.           0  db block gets  
  11.         373  consistent gets  
  12.         319  physical reads  
  13.           0  redo size  
  14.      259280  bytes sent via SQL*Net to client  
  15.        8313  bytes received via SQL*Net from client  
  16.         713  SQL*Net roundtrips to/from client  
  17.           1  sorts (memory)  
  18.           0  sorts (disk)  
  19.       10680  rows processed  
  20.   
  21. HELLODBA.COM>select /*+parallel(t 2)*/* from dummy_tab t;  
  22.   
  23. 10680 rows selected.  
  24.   
  25.   
  26. Statistics  
  27. ----------------------------------------------------------  
  28.           6  recursive calls  
  29.           0  db block gets  
  30.         373  consistent gets  
  31.         319  physical reads  
  32.           0  redo size  
  33.      256259  bytes sent via SQL*Net to client  
  34.        8313  bytes received via SQL*Net from client  
  35.         713  SQL*Net roundtrips to/from client  
  36.           1  sorts (memory)  
  37.           0  sorts (disk)  
  38.       10680  rows processed  

physical reads never disappear, that means data blocks are read direct from disk bypassing buffer cache. Statistic data "Physical Reads Direct" shows this activity evidently.

SQL代码
  1. D:\HelloDBA.COM\perl scripts>perl getsqlstats.pl  
  2. tnsname (default is orcl):  
  3. user name (default is demo):  
  4. password:  
  5. Array size (Default is 32):  
  6. Execution plan format (Default is TYPICAL):  
  7. SQL to be executed (without ;):  
  8. select /*+parallel(t 2)*/* from dummy_tab t  
  9.   
  10. Seesion ID: 299 Process ID: 101596  
  11. SQL Prepared. Process paused, press ENTER to continue...  
  12. SQL is executing ...  
  13. SQL Executed. Process Paused, press ENTER to continue...  
  14. SQL_ID  9fjrktd5gkmmh, child number 0  
  15. -------------------------------------  
  16. select /*+parallel(t 2)*/* from dummy_tab t  
  17.   
  18. Plan hash value: 2889160364  
  19.   
  20. ---------------------------------------------------------------------------------------------------------------  
  21. | Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |  
  22. ---------------------------------------------------------------------------------------------------------------  
  23. |   0 | SELECT STATEMENT     |           |       |       |   372 (100)|          |        |      |            |  
  24. |   1 |  PX COORDINATOR      |           |       |       |            |          |        |      |            |  
  25. |   2 |   PX SEND QC (RANDOM)| :TQ10000  | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | P->S | QC (RAND)  |  
  26. |   3 |    PX BLOCK ITERATOR |           | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | PCWC |            |  
  27. |*  4 |     TABLE ACCESS FULL| DUMMY_TAB | 12237 |  5963K|   372   (1)| 00:00:02 |  Q1,00 | PCWP |            |  
  28. ---------------------------------------------------------------------------------------------------------------  
  29.   
  30. Predicate Information (identified by operation id):  
  31. ---------------------------------------------------  
  32.   
  33.    4 - access(:Z>=:Z AND :Z<=:Z)  
  34.   
  35. Note  
  36. -----  
  37.    - dynamic sampling used for this statement  
  38.   
  39.   
  40. statistics  
  41. -----------------------------------------  
  42. consistent changes: 0  
  43. consistent gets: 373  
  44. consistent gets direct: 319  
  45. consistent gets from cache: 54  
  46. db block changes: 0  
  47. db block gets: 0  
  48. db block gets direct: 0  
  49. db block gets from cache: 0  
  50. physical reads: 319  
  51. physical reads cache: 0  
  52. physical reads direct: 319  
  53. physical reads direct temporary tablespace: 0  
  54. session logical reads: 373  

Another message beyond this topic is that, there are 6 recursive calls for parallel query, which involved CR from caches. By tracing 10046 event, the actual CR number of the query itselt is just 3, which were reading the segment head to get data block number of the table.

--- Fuyuncat ---

Top

Copyright ©2005, HelloDBA.Com All reseverd.

Declaration
by fuyuncat