- 最后登录
- 2013-7-19
- 在线时间
- 6 小时
- 威望
- 0
- 金钱
- 24
- 注册时间
- 2013-4-8
- 阅读权限
- 10
- 帖子
- 8
- 精华
- 0
- 积分
- 0
- UID
- 1025
|
6#
发表于 2013-7-4 14:27:47
SQL> set timing on
SQL> set autotrace on
SQL> WITH natural_number AS
(SELECT ROWNUM AS nn FROM dual CONNECT BY ROWNUM <= 10000)
SELECT nn
,SUM(factor) AS sum_factor
FROM (SELECT t1.nn
,t2.nn AS factor
,MOD(t1.nn, t2.nn) AS remain
FROM natural_number t1
,natural_number t2
WHERE t1.nn > t2.nn)
WHERE remain = 0
GROUP BY nn
HAVING nn = SUM (factor) 2 3 4 5 6 7 8 9 10 11 12 13
14 /
NN SUM_FACTOR
---------- ----------
8128 8128
6 6
28 28
496 496
Elapsed: 00:00:54.26
Execution Plan
----------------------------------------------------------
Plan hash value: 1415001427
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 26 | 7 (15)| 00:00:01 |
| 1 | TEMP TABLE TRANSFORMATION | | | | | |
| 2 | LOAD AS SELECT | SYS_TEMP_0FD9D6761_52DB0D90 | | | | |
| 3 | COUNT | | | | | |
|* 4 | CONNECT BY WITHOUT FILTERING| | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 6 | FILTER | | | | | |
| 7 | HASH GROUP BY | | 1 | 26 | 5 (20)| 00:00:01 |
| 8 | NESTED LOOPS | | 1 | 26 | 4 (0)| 00:00:01 |
| 9 | VIEW | | 1 | 13 | 2 (0)| 00:00:01 |
| 10 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6761_52DB0D90 | 1 | 13 | 2 (0)| 00:00:01 |
|* 11 | VIEW | | 1 | 13 | 2 (0)| 00:00:01 |
| 12 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6761_52DB0D90 | 1 | 13 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter(ROWNUM<=10000)
6 - filter("T1"."NN"=SUM("T2"."NN"))
11 - filter(MOD("T1"."NN","T2"."NN")=0 AND "T1"."NN">"T2"."NN")
Note
-----
- 'PLAN_TABLE' is old version
Statistics
----------------------------------------------------------
2 recursive calls
23 db block gets
170019 consistent gets
16 physical reads
532 redo size
678 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4 rows processed
SQL> WITH natural_number AS
(SELECT /*+parallel(dual 4)*/ROWNUM AS nn FROM dual CONNECT BY ROWNUM <= 10000)
SELECT nn
,SUM(factor) AS sum_factor
FROM (SELECT/*+parallel(t1 4) parallel(t2 4)*/ t1.nn
,t2.nn AS factor
,MOD(t1.nn, t2.nn) AS remain
FROM natural_number t1
,natural_number t2
WHERE t1.nn > t2.nn)
WHERE remain = 0
GROUP BY nn
HAVING nn = SUM (factor)
2 3 4 5 6 7 8 9 10 11 12 13 14
SQL> /
NN SUM_FACTOR
---------- ----------
8128 8128
6 6
28 28
496 496
Elapsed: 00:00:30.17
Execution Plan
----------------------------------------------------------
Plan hash value: 505721961
--------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 26 | 5 (0)| 00:00:01 | | | |
| 1 | TEMP TABLE TRANSFORMATION | | | | | | | | |
| 2 | LOAD AS SELECT | SYS_TEMP_0FD9D6765_52DB0D90 | | | | | | | |
| 3 | COUNT | | | | | | | | |
|* 4 | CONNECT BY WITHOUT FILTERING| | | | | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 | | | |
| 6 | PX COORDINATOR | | | | | | | | |
| 7 | PX SEND QC (RANDOM) | :TQ10002 | 1 | 26 | 3 (0)| 00:00:01 | Q1,02 | P->S | QC (RAND) |
|* 8 | FILTER | | | | | | Q1,02 | PCWC | |
| 9 | HASH GROUP BY | | 1 | 26 | 3 (0)| 00:00:01 | Q1,02 | PCWP | |
| 10 | PX RECEIVE | | 1 | 26 | 3 (0)| 00:00:01 | Q1,02 | PCWP | |
| 11 | PX SEND HASH | :TQ10001 | 1 | 26 | 3 (0)| 00:00:01 | Q1,01 | P->P | HASH |
| 12 | HASH GROUP BY | | 1 | 26 | 3 (0)| 00:00:01 | Q1,01 | PCWP | |
| 13 | NESTED LOOPS | | 1 | 26 | 3 (0)| 00:00:01 | Q1,01 | PCWP | |
| 14 | PX RECEIVE | | | | | | Q1,01 | PCWP | |
| 15 | PX SEND BROADCAST | :TQ10000 | | | | | Q1,00 | P->P | BROADCAST |
| 16 | VIEW | | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
| 17 | PX BLOCK ITERATOR | | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 18 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6765_52DB0D90 | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
|* 19 | VIEW | | 1 | 13 | 2 (0)| 00:00:01 | Q1,01 | PCWP | |
| 20 | PX BLOCK ITERATOR | | 1 | 13 | 2 (0)| 00:00:01 | Q1,01 | PCWC | |
| 21 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6765_52DB0D90 | 1 | 13 | 2 (0)| 00:00:01 | Q1,01 | PCWP | |
--------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter(ROWNUM<=10000)
8 - filter("T1"."NN"=SUM(SYS_OP_CSR(SYS_OP_MSR(SUM("T2"."NN")),0)))
19 - filter(MOD("T1"."NN","T2"."NN")=0 AND "T1"."NN">"T2"."NN")
Note
-----
- 'PLAN_TABLE' is old version
Statistics
----------------------------------------------------------
56 recursive calls
23 db block gets
320071 consistent gets
17 physical reads
720 redo size
678 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4 rows processed
SQL>
个人觉得这个运算是非常消耗cpu操作的,因此通过添加并行的提示能有所优化,通过实验,发现采用4个并行度后,由原来的54秒优化30秒。 |
|