scott@TEST>select /*+ parallel(emp) */* from emp;
14 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2873591275
--------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 1218 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 14 | 1218 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 14 | 1218 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| EMP | 14 | 1218 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
--------------------------------------------------------------------------------------------------------------
从上面的执行计划中可以看出,走的是并行
3、使用alter session命令
使用alter session命令,可以在当前session中强制启用并行查询或并行DML。如果强制启用了并行查询或者并行DML,那就意味着从执行alter session命令强制开启并行的那个时间点开始,在这个session中随后执行的所有SQL都将以并行的方式执行,有如下四种方法在当前session中强制开启并行
1) alter session parallel query
在当前session中强制开启并行查询,没有指定并行度,Oracle使用默认并行度
2) alter session parallel query parallel n
在当前session中强制开启并行查询,并且指定并行度为n
3) alter session parallel dml
在当前session中强制开启并行DML,没有指定并行度,Oracle使用默认并行度
4) alter session parallel dml parallel n
在当前session中强制开启并行DML,并且指定并行度为n
表EMP并行度仍为1,在session中强制开启并行:
scott@TEST>select table_name,degree from user_tables where table_name='EMP';
TABLE_NAME DEGREE
------------------------------ ----------
EMP 1
scott@TEST>set autotrace traceonly
scott@TEST>alter session force parallel query;
Session altered.
scott@TEST>select * from emp;
14 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2873591275
--------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 1218 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 14 | 1218 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 14 | 1218 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| EMP | 14 | 1218 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
--------------------------------------------------------------------------------------------------------------
......
从执行计划中可以看出走的是并行。
取消当前session并行使用如下语句alter session disable parallel query;