關於Parallel query
關於Parallel query
select 語句要能夠並行執行,必須滿足以下的條件:
1、至少一個表是透過full table scan 方式訪問的。或者index
range scan 涉及到了多個分割槽。
2、當執行一條select 語句涉及到full table scan 的時候,必須透過parallel hint
指定相應的表。或者表定義的時候設定了並行度。
3、當執行一條select 語句涉及到index range scan 跨多個分割槽的時候,必須
透過parallel_index 指定相應的索引,或者定義分割槽索引的時候設定了並行度。
oracle 如果決定select 語句的並行度的優先順序。
1、檢索出select語句涉及道德表和索引上的degree 和 instances 的規格說明。
選擇其中設定的最大值作為並行度。
2、檢查select 語句中是否有適用parallel hint 如果有適用,hint 指定的並行度
將會覆蓋掉前面一個步驟的確定的並行度。
注:你可以使用noparallel、noparallel_index hint 確保select 語句不會使用
並行執行。
*******************************************************************************
employees 表沒有設定並行度。
SQL> select table_name,degree
2 from user_tables
3 where table_name = 'EMPLOYEES';
TABLE_NAME DEGREE
---------- ----------
EMPLOYEES 1
2 from user_tables
3 where table_name = 'EMPLOYEES';
TABLE_NAME DEGREE
---------- ----------
EMPLOYEES 1
所有下面這條select 語句不會採取並行操作。
SQL> select employee_id,last_name,first_name
2 from employees;
Execution Plan
----------------------------------------------------------
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
2 from employees;
Execution Plan
----------------------------------------------------------
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
但是我們可以透過hint 來讓上面的select 語句採用並行執行。
1 select /*+parallel(emp,2)*/ employee_id,last_name,first_name
2* from employees emp
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 998304975
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
---------------------------------------------------------------------------------------------------------------
2* from employees emp
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 998304975
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
---------------------------------------------------------------------------------------------------------------
除了透過hint 提示外,我們可以透過在表級定義來讓select 語句採用並行執行。
SQL> alter table employees parallel (degree 2);
Table altered.
Table altered.
設定employees 表的並行度為2.再來執行上面的查詢。現在採用並行執行了。
SQL> select employee_id,last_name,first_name
2 from employees;
Execution Plan
----------------------------------------------------------
Plan hash value: 998304975
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
---------------------------------------------------------------------------------------------------------------
SQL> select employee_id,last_name,first_name
2 from employees;
Execution Plan
----------------------------------------------------------
Plan hash value: 998304975
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
---------------------------------------------------------------------------------------------------------------
我們可以透過noparallel hint 來確保select 語句執行的時候不會採用並行執行。
1 select /*+noparallel*/employee_id,last_name,first_name
2* from employees
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
2* from employees
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 108 | 2052 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMPLOYEES | 108 | 2052 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26110315/viewspace-732620/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Parallel query & viewsParallelView
- Parallel Query Wait EventsParallelAI
- 求救 關於parallel的問題Parallel
- 關於mysql的query_cacheMySql
- 關於查詢塊query blockBloC
- 關於fast_start_parallel_rollback引數ASTParallel
- Oracle並行操作——並行查詢(Parallel Query)Oracle並行Parallel
- Parallel Query Tuning(並行化查詢優化)Parallel並行優化
- alter session force parallel query與執行計劃變化SessionParallel
- How to Get a 10046 trace for a Parallel Query [ID 1102801.1]Parallel
- query rewrite和基於函式的索引有關係?函式索引
- ORA-12801: error signaled in parallel query server PZ99分析ErrorParallelServer
- 請問banq大哥,關於com.jdon.model.query.PageIteratorSolver
- oracle 10g sga手動管理mmm 基於並行查詢parallel query如何配置large_pool_size大池Oracle 10g並行Parallel
- 關於IE8下media query相容的解決方案探討
- clob欄位對於parallel ddl的限制Parallel
- clob欄位對於parallel dml的限制Parallel
- oracle hint_no_parallel_no_parallel_indexOracleParallelIndex
- oracle hint_parallel_parallel_indexOracleParallelIndex
- 關於 Angular view Query 的 id 選擇器問題的單步除錯AngularView除錯
- Tasks in parallelParallel
- Parallel DMLParallel
- about datapump parallelParallel
- 並行(Parallel)並行Parallel
- Oracle Parallel ParametersOracleParallel
- Oracle's ParallelOracleParallel
- Oracle Parallel ExecutionOracleParallel
- Oracle Parallel DMLOracleParallel
- phpmysqlimysqli_query()mysqli_real_query()PHPMySql
- parallel並行度的相關操作、概念、引數解釋Parallel並行
- oracle parallel並行_引數parameter_parallel_max_serverOracleParallel並行Server
- 解決mysql_query()報錯的相關問題MySql
- 關於IT,關於技術
- PARALLEL_DEGREE_POLICParallel
- parallel_max_serversParallelServer
- Parallel操作測試Parallel
- Parallel Execution of SQL StatementsParallelSQL
- oracle Parallel技術OracleParallel