1. 程式人生 > >append+parallel,並行度

append+parallel,並行度

1.append和並行同時使用時注意:
alter session enable parallel DML;
ALTER SESSION SET db_file_multiblock_read_count=128;
INSERT /+append parallel(b 2)/
並行:兩個並行包括三個程序,有一個程序是負責排程的。

2.並行度
並行度與CPU和當前的負載有關
—cmd下執行
SQL> set autot trace
—-開並行的時候,Oracle會分配一組或兩組Slave Set
–並行度4指的是Slave Set中的從屬程序的數量。
SQL> select /+ parallel(t1,4)

/ * from t1 order by 1;

並行度是4,很有可能開八個程序。一組用來生產資料(select),一組用來消費資料(order by)
測試結果:
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL

P000 IDLE 3 2 0 0 0 0 3 0 0 46 64
P001 IDLE 3 2 0 0 0 0 3 0 0 128 168
P002 IDLE 3 2 0 0 0 0 3 0 0 44 63
P003 IDLE 2 2 0 0 0 0 3 0 0 1242 1241
P004 IDLE 2 2 0 0 0 0 3 0 0 364 32
P005 IDLE 2 2 0 0 0 0 3 0 0 322 29
P006 IDLE 2 2 0 0 0 0 3 0 0 434 37
P007 IDLE 2 2 0 0 0 0 3 0 0 419 36
8 rows selected

—–IDLE是空閒狀態,BUSY是忙碌狀態,PMON程序會每隔一個時間去檢查,如果發現是IDLE狀態,就將程序關閉
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL

開4個程序的測試結果:
—-cmd下執行
SQL> set autot trace
SQL> select /+ parallel(t1,4)

/ * from t1;
—-PLSQL DEV
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL

P000 BUSY 4 0 0 0 173 13 0 0 0 219 77
P001 BUSY 4 0 0 0 187 14 0 0 0 315 182
P002 BUSY 4 0 0 0 176 13 0 0 0 220 76
P003 BUSY 3 0 0 0 174 13 0 0 0 1416 1254

SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL

P000 IDLE 4 0 0 0 0 0 0 0 0 226 78
P001 IDLE 4 0 0 0 0 0 0 0 0 322 183
P002 IDLE 4 0 0 0 0 0 0 0 0 238 78
P003 IDLE 3 0 0 0 0 0 0 0 0 1430 1256

select /+ parallel(t1,4) / object_id,count(*) from t1 group by object_id;