OracleRAC环境对并行查询的支持
RAC环境中,一个并行的执行可能分布到多个实例上执行。
如果连接Oracle RAC数据库时,一个节点上的并发操作可以分布到多个节点上同时执行。
看一个简单的例子:
SQL> CONN TEST/TEST@TESTRAC已连接。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac2
SQL > SELECT INSTANCE_NAME FROM GV$INSTANCE;
INSTANCE_NAME
----------------
testrac1
testrac2
SQL > SELECT * FROM V$VERSION;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
这是一个10g的环境,下面建立一张测试表,建立过程中设置表的并行度:
SQL> CREATE TABLE T_PARALLEL PARALLEL 16
2 AS SELECT A.* FROM DBA_OBJECTS A, DBA_TABLES
3 WHERE ROWNUM <= 5000000;
表已创建。
SQL> SET AUTOT ON
SQL> SELECT COUNT(*) FROM T_PARALLEL;
COUNT(*)
----------
5000000
执行计划
----------------------------------------------------------
Plan hash value: 70256698
----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1081 (2)| 00:00:13 | | | |
| 1 | SORT AGGREGATE | | 1 | | | | | |
| 2 | PX COORDINATOR | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10000 | 1 | | | Q1,00 | P- >S | QC (RAND) |
| 4 | SORT AGGREGATE | | 1 | | | Q1,00 | PCWP | |
| 5 | PX BLOCK ITERATOR | | 4588K| 1081 (2)| 00:00:13 | Q1,00 | PCWC | |
| 6 | TABLE ACCESS FULL| T_PARALLEL | 4588K| 1081 (2)| 00:00:13 | Q1,00 | PCWP | |
----------------------------------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
从执行计划可以看到,Oracle选则了并行执行。
新连接一个会话,在执行上面这个并行查询的同时,检查GV$PX_PROCESS视图:
SQL> SELECT * FROM GV$PX_PROCESS;
INST_ID SERV STATUS PID SPID SID SERIAL#
---------- ---- --------- ---------- ------------ ---------- ----------
2 P000 IN USE 21 25120 265 13
2 PZ99 IN USE 42 25480 271 39
2 P001 IN USE 24 25122 279 1579
2 P002 IN USE 34 25124 280 602
2 P003 IN USE 35 25126 281 42
2 P004 IN USE 37 25155 284 106
2 P005 IN USE 41 25159 296 2212
1 P009 IN USE 44 27375 244 20
1 P004 IN USE 39 27336 246 504
1 P000 IN USE 24 27328 247 19
1 P005 IN USE 40 27349 251 363
1 P002 IN USE 37 27332 254 76
1 PZ99 IN USE 45 27725 265 28
1 P008 IN USE 43 27373 266 46
1 P006 IN USE 41 27369 270 64
1 P001 IN USE 32 27330 283 1980
1 P007 IN USE 42 27371 289 86
1 P003 IN USE 38 27334 311 21707
已选择18行。
很显然,并行查询的16个进程已经分布到两个节点上同时执行了。