Search

OakieTags

Who's online

There are currently 0 users and 28 guests online.

Recent comments

Affiliations

Buffer Cacheにデータがない場合のparallel_degree_policy=autoの動き

前回、buffer cacheが足りなくなったら?というシナリオでテストをしたけど、なんとなく納得できない。
そもそもparallel_degree_policy=autoでIn-Memory PQが動くはず(動いているはず)と信じていいの?なんていう疑問が湧いてくる。
buffer cacheをflushしてbuffer cacheにデータがない状況で

parallel_degree_policy=auto:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0

SQL> alter system flush buffer_cache;
システムが変更されました。
SQL> alter system flush shared_pool;
システムが変更されました。
SQL> set timi on
SQL> set autot traceSQL> alter session set parallel_degree_policy=auto;
セッションが変更されました。
SQL> select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity)
2 from customer, orders, lineitem
3 where o_orderkey in
4 ( select l_orderkey
5 from lineitem
6 group by l_orderkey
7 having sum(l_quantity) > 313)
8 and c_custkey = o_custkey
9 and o_orderkey = l_orderkey
10 group by c_name, c_custkey
11 , o_orderkey
12 , o_orderdate
13 , o_totalprice
14 order by o_totalprice desc, o_orderdate;
12行が選択されました。
経過: 00:00:02.88
実行計画----------------------------------------------------------Plan hash value: 1448507623
---------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 15209 | 950K| | 20231 (2)| 00:04:03 | | | |
| 1 | PX COORDINATOR | | | | | | | | | |
| 2 | PX SEND QC (ORDER) | :TQ10005 | 15209 | 950K| | 20231 (2)| 00:04:03 | Q1,05 | P->S | QC (ORDER) |
| 3 | SORT GROUP BY | | 15209 | 950K| 1088K| 20231 (2)| 00:04:03 | Q1,05 | PCWP | |
| 4 | PX RECEIVE | | 15209 | 950K| | 20229 (2)| 00:04:03 | Q1,05 | PCWP | |
| 5 | PX SEND RANGE | :TQ10004 | 15209 | 950K| | 20229 (2)| 00:04:03 | Q1,04 | P->P | RANGE |
|* 6 | HASH JOIN | | 15209 | 950K| | 20229 (2)| 00:04:03 | Q1,04 | PCWP | |
| 7 | PX RECEIVE | | 3750 | 201K| | 13435 (3)| 00:02:42 | Q1,04 | PCWP | |
| 8 | PX SEND BROADCAST | :TQ10003 | 3750 | 201K| | 13435 (3)| 00:02:42 | Q1,03 | P->P | BROADCAST |
|* 9 | HASH JOIN | | 3750 | 201K| | 13435 (3)| 00:02:42 | Q1,03 | PCWP | |
| 10 | PX RECEIVE | | 3750 | 113K| | 13128 (3)| 00:02:38 | Q1,03 | PCWP | |
| 11 | PX SEND BROADCAST | :TQ10002 | 3750 | 113K| | 13128 (3)| 00:02:38 | Q1,02 | P->P | BROADCAST |
|* 12 | HASH JOIN | | 3750 | 113K| | 13128 (3)| 00:02:38 | Q1,02 | PCWP | |
| 13 | PX RECEIVE | | 73952 | 433K| | 11166 (3)| 00:02:14 | Q1,02 | PCWP | |
| 14 | PX SEND BROADCAST | :TQ10001 | 73952 | 433K| | 11166 (3)| 00:02:14 | Q1,01 | P->P | BROADCAST |
| 15 | VIEW | VW_NSO_1 | 73952 | 433K| | 11166 (3)| 00:02:14 | Q1,01 | PCWP | |
|* 16 | FILTER | | | | | | | Q1,01 | PCWC | |
| 17 | HASH GROUP BY | | 185 | 649K| 114M| 11166 (3)| 00:02:14 | Q1,01 | PCWP | |
| 18 | PX RECEIVE | | 5997K| 51M| | 6773 (1)| 00:01:22 | Q1,01 | PCWP | |
| 19 | PX SEND HASH | :TQ10000 | 5997K| 51M| | 6773 (1)| 00:01:22 | Q1,00 | P->P | HASH |
| 20 | PX BLOCK ITERATOR | | 5997K| 51M| | 6773 (1)| 00:01:22 | Q1,00 | PCWC | |
| 21 | TABLE ACCESS FULL| LINEITEM | 5997K| 51M| | 6773 (1)| 00:01:22 | Q1,00 | PCWP | |
| 22 | PX BLOCK ITERATOR | | 1500K| 35M| | 1953 (1)| 00:00:24 | Q1,02 | PCWC | |
| 23 | TABLE ACCESS FULL | ORDERS | 1500K| 35M| | 1953 (1)| 00:00:24 | Q1,02 | PCWP | |
| 24 | PX BLOCK ITERATOR | | 150K| 3515K| | 306 (1)| 00:00:04 | Q1,03 | PCWC | |
| 25 | TABLE ACCESS FULL | CUSTOMER | 150K| 3515K| | 306 (1)| 00:00:04 | Q1,03 | PCWP | |
| 26 | PX BLOCK ITERATOR | | 5997K| 51M| | 6773 (1)| 00:01:22 | Q1,04 | PCWC | |
| 27 | TABLE ACCESS FULL | LINEITEM | 5997K| 51M| | 6773 (1)| 00:01:22 | Q1,04 | PCWP | |
---------------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

6 - access("O_ORDERKEY"="L_ORDERKEY")
9 - access("C_CUSTKEY"="O_CUSTKEY")
12 - access("O_ORDERKEY"="L_ORDERKEY")
16 - filter(SUM("L_QUANTITY")>313)

Note
-----
- automatic DOP: Computed Degree of Parallelism is 2


統計
----------------------------------------------------------
1079 recursive calls
0 db block gets
156736 consistent gets
89285 physical reads
0 redo size
1563 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
21 sorts (memory)
0 sorts (disk)
12 rows processed

automatic DOP: Computed Degree of Parallelism is 2と出た。
あれ?Parallelで動いてる?
間違ったことを書いちゃった!
そんなはずはない:

SQL> select n.name, m.value
2 from sys.v_$mystat m, sys.v_$statname n
3 where n.name in ('CPU used by this session','DB time','physical reads direct')
4 and n.statistic# = m.statistic#
5 /

NAME VALUE
---------------------------------------------------------------- ----------
CPU used by this session 511
DB time 1608
physical reads direct 0

「良かった。間違ってない」ちゃんとdirect path readはしていない。

確認のため、同じことをParallel Queryでやってみる(念のためbuffer_cacheもflushして)

force prallel query 2:

SQL> alter system flush buffer_cache;
システムが変更されました。
SQL> alter system flush shared_pool;
システムが変更されました。
SQL> set timi on
SQL> set autot trace
SQL> alter session force parallel query parallel 2;
セッションが変更されました。
SQL> select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity)
2 from customer, orders, lineitem
3 where o_orderkey in
4 ( select l_orderkey
5 from lineitem
6 group by l_orderkey
7 having sum(l_quantity) > 313)
8 and c_custkey = o_custkey
9 and o_orderkey = l_orderkey
10 group by c_name, c_custkey
11 , o_orderkey
12 , o_orderdate
13 , o_totalprice
14 order by o_totalprice desc, o_orderdate;

12行が選択されました。

経過: 00:00:02.77
....
.... same plan ...
....
統計
----------------------------------------------------------
1009 recursive calls
0 db block gets
156652 consistent gets
156241 physical reads
0 redo size
1563 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
21 sorts (memory)
0 sorts (disk)
12 rows processed

SQL> set autot off
SQL> select n.name, m.value
2 from sys.v_$mystat m, sys.v_$statname n
3 where n.name in ('CPU used by this session','DB time','physical reads direct')
4 and n.statistic# = m.statistic#
5 /

NAME VALUE
---------------------------------------------------------------- ----------
CPU used by this session 460
DB time 1532
physical reads direct 153219

physical reads direct=153219とphysical reads数とほぼ同じになっている。

実行時間を比べてみると、やはりdirect path readを行うParallel Queryの方が速い。

まとめると、
buffer cacheにデータが全くない場合parallel_degree_policy=autoだと、

  • Parallel Queryをしたのと同じ実行計画が出てくる
  • automatic DOP: Computed Degree of Parallelism is 2とも出る
  • でもParallel実行はされていない