關於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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 關於mysql的query_cacheMySql
- 關於 Angular view Query 的 id 選擇器問題的單步除錯AngularView除錯
- 關聯式資料庫 Query_Execution資料庫
- Oracle Parallel DMLOracleParallel
- 聊聊flink的Parallel ExecutionParallel
- reg query /?
- Query DSL
- ES 筆記十:Query String & Simple Query String筆記
- parallel rollback引數總結Parallel
- alter table nologging /*+APPEND PARALLEL(n)*/APPParallel
- Oracle's Parallel Execution Features(zt)OracleParallel
- 並行處理 Parallel Processing並行Parallel
- MU5IN160 – Parallel ProgrammingParallel
- Linux parallel 命令使用手冊LinuxParallel
- ASQuery:基於Query的時序動作分割新架構架構
- 關於IT,關於技術
- Flashback Query(轉)
- expdp query用法
- Elasticsearch——query stringElasticsearch
- coca SLOW QUERY
- [Vue CLI 3] 配置解析之 parallelVueParallel
- openGauss Parallel-Page-based-Redo-For-UstoreParallel
- 並行閘道器 Parallel Gateway並行ParallelGateway
- Mandelbrot set 以parallel_for_實現Parallel
- CSCI-UA.0480-051: Parallel ComputingParallel
- laravel-query-builder 對於欄位 值為 null的排序方式LaravelUINull排序
- react-query手把手教程①-入門react-queryReact
- pt-query-digest
- [Typescript] Query builder exampleTypeScriptUI
- jpa @Query demo 演示
- 0316理解db file parallel read等待事件Parallel事件
- Parallel Pattern Library(PPL)學習筆記Parallel筆記
- 關於++[[]][+[]]+[+[]]
- 關於
- 關於~
- ntpdate會導致mysql slow query log出現很大的query timeMySql
- Elasticsearch bool query小結Elasticsearch
- Rewrite %{QUERY_STRING}用法
- ORACLE Flashback Query偽列Oracle