今天同事问我怎么提高一个查询的速度,非常着急要查询结果。查询语句执行计划如下:
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 52563 (2)| 00:10:31 |
| 1 | SORT GROUP BY | | 1 | 6 | | |
| 2 | INDEX FAST FULL SCAN| PK_IC40 | 540M| 310M| 52563 (2)| 00:10:31 |
---------------------------------------------------------------------------------
通过HINT并行的做法让查询时间仅用了10秒。查询执行计划:
SQL> SELECT DEGREE FROM user_indexes WHERE index_Name='PK_IC40';
DEGREE
----------------------------------------
1
已用时间: 00: 00: 00.05
SQL> explain plan for
2 SELECT /*+ parallel_index(ic40 pk_ic40 8)*/COUNT(DISTINCT aac001) FROM ic40;
已解释。
已用时间: 00: 00: 00.05
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------
--------
Plan hash value: 3375479740
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 52563 (2)| 00:10:31 | | | |
| 1 | SORT GROUP BY | | 1 | 6 | | | | | |
| 2 | PX COORDINATOR | | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10001 | 1 | 6 | | | Q1,01 | P->S | QC (RAND) |
| 4 | SORT GROUP BY | | 1 | 6 | | | Q1,01 | PCWP | |
| 5 | PX RECEIVE | | 1 | 6 | | | Q1,01 | PCWP | |
| 6 | PX SEND HASH | :TQ10000 | 1 | 6 | | | Q1,00 | P->P | HASH |
| 7 | SORT GROUP BY | | 1 | 6 | | | Q1,00 | PCWP | |
| 8 | PX BLOCK ITERATOR | | 540M| 310M| 52563 (2)| 00:10:31 | Q1,00 | PCWC | |
| 9 | INDEX FAST FULL SCAN| PK_IC40 | 540M| 310M| 52563 (2)| 00:10:31 | Q1,00 | PCWP | |
----------------------------------------------------------------------------------------------------------------------
已选择16行。
可是突然想起了之前看过一篇文章,说是对于index fast full scan操作,除非在索引上显式的设置并行度,否则采用HINT添加并行的做法,是不能达到并行效果的。文章链接如下:
http://yumianfeilong.com/html/2007/11/12/143.html
我的ORACLE版本,10.2.0.4.
莫非原文的意思是不能够使用parallel()提示来并行index fast full sacn。而不是说parallel_index()不可以让index fast full scan并行?
[ 本帖最后由 wei-xh 于 2010-7-10 13:43 编辑 ]
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 52563 (2)| 00:10:31 |
| 1 | SORT GROUP BY | | 1 | 6 | | |
| 2 | INDEX FAST FULL SCAN| PK_IC40 | 540M| 310M| 52563 (2)| 00:10:31 |
---------------------------------------------------------------------------------
通过HINT并行的做法让查询时间仅用了10秒。查询执行计划:
SQL> SELECT DEGREE FROM user_indexes WHERE index_Name='PK_IC40';
DEGREE
----------------------------------------
1
已用时间: 00: 00: 00.05
SQL> explain plan for
2 SELECT /*+ parallel_index(ic40 pk_ic40 8)*/COUNT(DISTINCT aac001) FROM ic40;
已解释。
已用时间: 00: 00: 00.05
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------
--------
Plan hash value: 3375479740
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 52563 (2)| 00:10:31 | | | |
| 1 | SORT GROUP BY | | 1 | 6 | | | | | |
| 2 | PX COORDINATOR | | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10001 | 1 | 6 | | | Q1,01 | P->S | QC (RAND) |
| 4 | SORT GROUP BY | | 1 | 6 | | | Q1,01 | PCWP | |
| 5 | PX RECEIVE | | 1 | 6 | | | Q1,01 | PCWP | |
| 6 | PX SEND HASH | :TQ10000 | 1 | 6 | | | Q1,00 | P->P | HASH |
| 7 | SORT GROUP BY | | 1 | 6 | | | Q1,00 | PCWP | |
| 8 | PX BLOCK ITERATOR | | 540M| 310M| 52563 (2)| 00:10:31 | Q1,00 | PCWC | |
| 9 | INDEX FAST FULL SCAN| PK_IC40 | 540M| 310M| 52563 (2)| 00:10:31 | Q1,00 | PCWP | |
----------------------------------------------------------------------------------------------------------------------
已选择16行。
可是突然想起了之前看过一篇文章,说是对于index fast full scan操作,除非在索引上显式的设置并行度,否则采用HINT添加并行的做法,是不能达到并行效果的。文章链接如下:
http://yumianfeilong.com/html/2007/11/12/143.html
我的ORACLE版本,10.2.0.4.
莫非原文的意思是不能够使用parallel()提示来并行index fast full sacn。而不是说parallel_index()不可以让index fast full scan并行?
[ 本帖最后由 wei-xh 于 2010-7-10 13:43 编辑 ]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22034023/viewspace-667704/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22034023/viewspace-667704/