parallel並行度的相關操作、概念、引數解釋

lusklusklusk發表於2017-12-02
哪些場景可以使用並行度
table scan、fast full index scans、partition index range scans(僅限local索引)
create table as、create index、rebuild index、move、split、DML(insert\update\delete)

當使用了並行執行,SQL的執行計劃中就會多出一列:in-out。相關檢視為:v$pq_sysstat、v$pq_tqstat


alter session force parallel query parallel N  --強制使用N個並行度,force parallel會覆蓋預設的parallel設定
alter session enable parallel query  --使用預設的並行度數量

表開啟並行的方法
alter table sales parallel;
alter table sales parallel 8;

hint開啟表查詢的並行度
select /*+ parallel(tablename,8) */ * from tablename
select /*+ parallel(sales,8) */ * from sales

DML使用hint開啟並行時,表必須開啟並行,因為update時,是要先查出表的資料即先執行select,所以update開啟了並行度,select也要開啟並行度,否則只有update是並行,但select卻不是。


並行度GRANULES
1.並行工作的一個基本單元被稱為GRANULES
2,一個GRANULES只能有一個並行執行的server進行讀的操作
3,並行的一個server可以從一個GRANULES到另外一個GRANULES的執行任務,即當一個任務完成了就去接著執行下一個任務。

並行度GRANULES分兩種
1.block range granules(自動根據塊的數目範圍為分)
Block range granules: Server程式在執行的時候就動態的產生。
2.partition granules(用於分割槽表,比如有8個分割槽,它可能會分四個並行度,這樣四個並行度可能在四個不同分割槽上)
Partition granules : 有分割槽的數量靜態的決定。



三個著名引數的應用場景
PARALLEL_DEGREE_POLICY
PARALLEL_MIN_PERCENT
PARALLEL_SERVERS_TARGET

比如80個CPU、現在已經使用了60個,剩下20個(PARALLEL_SERVERS_TARGET),現在來了一個60個並行度的查詢,怎麼辦?
如果PARALLEL_MIN_PERCENT=10,就是10%可以用,就是最少使用60*10%=6個並行度,6<20,可以使用
如果PARALLEL_MIN_PERCENT=50,就是使用60*50%=30,30>20,如果PARALLEL_DEGREE_POLICY=MANUAL,則不夠,直接報錯,如果PARALLEL_DEGREE_POLICY=AUTO,則進入佇列。


PARALLEL_FORCE_LOCAL controls parallel execution in an Oracle RAC environment. By default, the parallel server processes selected to execute a SQL statement can operate on any or all Oracle RAC nodes in the cluster. By setting PARALLEL_FORCE_LOCAL to true, the parallel server processes are restricted so that they can only operate on the same Oracle RAC node where the query coordinator resides (the node on which the SQL statement was executed on).
控制Oracle RAC環境中的並行執行。預設情況下,選擇執行SQL語句的並行伺服器程式可以在群集中的任何或所有Oracle RAC節點上執行。透過將PARALLEL_FORCE_LOCAL設定為true,並行伺服器程式受到限制,因此它們只能在查詢協調程式所在的同一個Oracle RAC節點(執行SQL語句的節點)上執行
預設FORCE,就是可以使用其他節點的CPU,並不是說在其他節點執行SQL,執行SQL還是本節點(即PX在本節點),但是可以使用其他節點的資源做coordinator process即QC(就是管理下面這些並行度的一個程式,一個個的並行程式叫parallel execution servers即PX),此引數最好設定為TRUE

PARALLEL_MAX_SERVERS specifies the maximum number of parallel execution processes and parallel recovery processes for an instance. As demand increases, Oracle Database increases the number of processes from the number created at instance startup up to this value
PARALLEL_MAX_SERVERS指定例項的並行執行程式和並行恢復程式的最大數量。隨著需求的增加,Oracle資料庫將例項啟動時建立的程式數量增加到此值

PARALLEL_MIN_SERVERS specifies the minimum number of parallel execution processes for the instance. This value is the number of parallel execution processes Oracle creates when the instance is started
PARALLEL_MIN_SERVERS指定例項的最小並行執行程式數。 該值是在例項啟動時由Oracle建立的並行執行程式的數量
PARALLEL_MIN_SERVERS預設是0,如果修改為5,說明就算是空閒不用,也開啟5個程式,相關檢視v$px_process
比如一開機就有ora_p001_sid、ora_p002_sid、ora_p003_sid、ora_p004_sid、ora_p004_sid這樣5個程式,這就是partition slave process they do parallel dml ddl and query jobs..

PARALLEL_DEGREE_POLICY specifies whether or not automatic degree of Parallelism,statement queuing, and in-memory parallel execution will be enabled
PARALLEL_DEGREE_POLICY指定是否啟用並行度,語句排隊和記憶體中並行執行的自動程度

PARALLEL_MIN_PERCENT lets you specify the minimum percentage of the requested number of parallel execution processes required for parallel execution. This parameter controls the behavior for parallel operations when parallel statement queuing is not enabled (when PARALLEL_DEGREE_POLICY is set to manual or limited). It ensures that an operation always gets a minimum percentage of parallel execution servers or errors out. Setting this parameter ensures that parallel operations will not execute unless adequate resources are available. The default value of 0 means that no minimum percentage of processes has been set.
If 8 of the 10 parallel execution processes are busy, only 2 processes are available. If you then request a query with a degree of parallelism of 8, the minimum 50% will not be met.
PARALLEL_MIN_PERCENT可以指定並行執行所需的並行執行程式的最小數量百分比。 並行語句佇列未啟用時(PARALLEL_DEGREE_POLICY設定為manual or limited),此引數控制並行操作的行為。它確保操作始終獲得並行執行伺服器的最小百分比或出錯。設定此引數可確保並行操作不會執行,除非提供足夠的資源。預設值0意味著沒有設定最小程式百分比。

PARALLEL_SERVERS_TARGET specifies the number of parallel server processes allowed to run parallel statements before statement queuing will be used. When the parameter PARALLEL_DEGREE_POLICY is set to AUTO, Oracle will queue SQL statements that require parallel execution, if the necessary parallel server processes are not available.
PARALLEL_SERVERS_TARGE指定在使用語句排隊之前允許執行並行語句的並行伺服器程式的數量。當引數PARALLEL_DEGREE_POLICY設定為AUTO時,如果必需的並行伺服器程式不可用,Oracle將對需要並行執行的SQL語句進行排隊。

PARALLEL_MIN_TIME_THRESHOLD specifies the minimum execution time a statement should have before the statement is considered for automatic degree of parallelism. By default, this is set to 10 seconds. Automatic degree of parallelism is only enabled if PARALLEL_DEGREE_POLICY is set to AUTO or LIMITED.
PARALLEL_MIN_TIME_THRESHOLD指定語句在考慮自動並行度之前語句應該具有的最短執行時間。預設情況下,它被設定為10秒。自動並行度僅在PARALLEL_DEGREE_POLICY設定為AUTO或LIMITED時才能使用。

PARALLEL_ADAPTIVE_MULTI_USER, when set to true, enables an adaptive algorithm designed to improve performance in multiuser environments that use parallel execution. The algorithm automatically reduces the requested degree of parallelism based on the system load at query startup time. The effective degree of parallelism is based on the default degree of parallelism, or the degree from the table or hints, divided by a reduction facto
PARALLEL_ADAPTIVE_MULTI_USER,當設定為true時,啟用一個自適應演算法,旨在提高使用並行執行的多使用者環境的效能。該演算法根據查詢啟動時的系統負載自動降低請求的並行度。並行度的有效程度是基於預設的並行度,或者從表或者提示的程度除以還原因子

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2148192/,如需轉載,請註明出處,否則將追究法律責任。

相關文章