Oracle表的并行度
生活随笔
收集整理的這篇文章主要介紹了
Oracle表的并行度
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
查看dba_tables數(shù)據(jù)字典時,可以發(fā)現(xiàn)有“DEGREE”字段,這個字段表示的就是數(shù)據(jù)表的并行度。這個參數(shù)的設(shè)置,關(guān)系著數(shù)據(jù)庫的I/O,以及sql的執(zhí)行效率。
并行度的優(yōu)點(diǎn)就是能夠最大限度的利用機(jī)器的多個cpu資源,是多個cpu同時工作,從而達(dá)到提高數(shù)據(jù)庫工作效率的目的。在系統(tǒng)空閑時間,使用并行是個不錯的選擇,但是好東西總是相對而言,沒有絕對的好壞,不當(dāng)?shù)氖褂?#xff0c;同樣會引起數(shù)據(jù)庫的新的問題產(chǎn)生。
1、 ?此參數(shù)的大小設(shè)置
orcl@ SCOTT> select table_name,degree from user_tables;
TABLE_NAME ? ? ? ? ? ? ? ? ? ? DEGREE
------------------------------ ? ? ? ? --------------------
T1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
TAB_REGISTER ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
EMP ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1
EMP_BAK ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1
SALGRADE ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
BONUS ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1
DEPT ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
LETTER_USER ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1
T2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
BASE_LOG ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1
T ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1
通過上例的例子大家可以觀察,此參數(shù)的默認(rèn)值為1,這個數(shù)值,我們認(rèn)為的增加,當(dāng)設(shè)置表的并行度非常高的時候,sql優(yōu)化器將可能對表進(jìn)行全表掃描,引起 Direct Path Read 等待 。
在使用并行查詢前需要慎重考慮, 因?yàn)椴⑿胁樵儽M管能提高程序的響應(yīng)時間, 但是會
消耗比較多的資源。 對于低配置的數(shù)據(jù)庫服務(wù)器需要慎重。 此外, 需要確認(rèn)并行度的設(shè)置要與 IO 系統(tǒng)的配置相符(建議并行度為 2~4 * CPU 數(shù)) 。?
2、 ?并行度的修改
alter table t parallel(degree 1);------直接指定表的并行度
alter table t parallel; ? ?----------設(shè)置表的并行度為default
3、 ?如何在sql語句中使用表的并行度,并選擇合適的并行等級
示例:使用并行查詢的執(zhí)行計劃
并行度為4
orcl@ SCOTT> SELECT /*+ PARALLEL(4) */
2 ? MAX(sal),
3 ? AVG(comm)
4 ? ?FROM emp,dept
5 ? WHERE emp.deptno=dept.deptno
6 ? GROUP BY 1
7 ?;
已用時間: ?00: 00: 00.09
執(zhí)行計劃
----------------------------------------------------------
Plan hash value: 1358624651
---------------------------------------------------------------------------------------------------------------
| Id ?| Operation ? ? ? ? ? ? | Name ? ? | Rows ?| Bytes | Cost (%CPU)| Time ? ? | ? ?TQ ?|IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------
| ? 0 | SELECT STATEMENT ? ? ?| ? ? ? ? ?| ? ?14 | ? 126 | ? ? 2 ? (0)| 00:00:01 | ? ? ? ?| ? ? ?| ? ? ? ? |
| ? 1 | ?HASH GROUP BY ? ? ? ?| ? ? ? ? ?| ? ?14 | ? 126 | ? ? 2 ? (0)| 00:00:01 | ? ? ? ?| ? ? ?| ? ? ? ? |
| ? 2 | ? PX COORDINATOR ? ? ?| ? ? ? ? ?| ? ? ? | ? ? ? | ? ? ? ? ? ?| ? ? ? ? ?| ? ? ? ?| ? ? ?| ? ? ? ? |
| ? 3 | ? ?PX SEND QC (RANDOM)| :TQ10000 | ? ?14 | ? 126 | ? ? 2 ? (0)| 00:00:01 | ?Q1,00 | P->S | QC (RAND) ?|
| ? 4 | ? ? PX BLOCK ITERATOR | ? ? ? ? ?| ? ?14 | ? 126 | ? ? 2 ? (0)| 00:00:01 | ?Q1,00 | PCWC | ? ? ? ? |
|* ?5 | ? ? ?TABLE ACCESS FULL| EMP ? ? ?| ? ?14 | ? 126 | ? ? 2 ? (0)| 00:00:01 | ?Q1,00 | PCWP | ? ? ? ? |
---------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("EMP"."DEPTNO" IS NOT NULL)
Note
-----
- automatic DOP: computed degree of parallelism is 4
統(tǒng)計信息
----------------------------------------------------------
20 ?recursive calls
0 ?db block gets
5 ?consistent gets
0 ?physical reads
0 ?redo size
482 ?bytes sent via SQL*Net to client
416 ?bytes received via SQL*Net from client
2 ?SQL*Net roundtrips to/from client
1 ?sorts (memory)
0 ?sorts (disk)
1 ?rows processed
非并行度
SELECT /*+ no_parallel */ ename, dname FROM emp e, dept d
WHERE e.deptno=d.deptno;
自動并行度
SELECT /*+ parallel(auto) */ ename, dname FROM emp e, dept d
WHERE e.deptno=d.deptno;
4、 ?并行查詢的使用范圍
適用于:
大表查詢,join,分區(qū)索引的查詢,
創(chuàng)建大量的index,
創(chuàng)建大量的表(包括固化視圖),
批量的insert,update,delete;
查行執(zhí)行適合場景:
對稱多處理器,集群,并行系統(tǒng),
cpu利用不足,
足夠的內(nèi)存用于其他操作,排序,hash,緩存,
查行執(zhí)行適合與dss與數(shù)據(jù)倉庫,也適合于批量操作的OLTP系統(tǒng),不適合OLTP簡介的dml或select操作;
并行執(zhí)行不適合場景:
非常短的查詢或事務(wù)
基本硬件要求:
并行執(zhí)行設(shè)計需要多個cpu與io來實(shí)現(xiàn)快速的查詢,每個硬件都應(yīng)該維持在同一個吞吐量
哪些操作可以用并行
全表查詢,分區(qū)查詢,索引快速查詢
join操作
nested loop, sort merge, hash, and star transformation
DDL語句
CREATE TABLE AS SELECT, ?CREATEINDEX, REBUILDINDEX,
REBUILD INDEX PARTITION,?
And MOVE/SPLIT/COALESCEPARTITION
DML語句
INSERT AS SELECT,UPDATE,DELETE,
And MERGE operations
5、 ?在并行操作中默認(rèn)情況并行查詢和并行DDL操作可以無障礙使用并行,但是如果想使用并行DML,需要先修改dml并行配置
alter session enable parallel dml;
11g new feature:
For a statement-level PARALLEL hint:
■ PARALLEL: The statement always is run parallel, and the database computes the?
degree of parallelism, which can be 2 or greater.
■ PARALLEL (DEFAULT): The same as PARALLEL. The DEFAULT keyword is?
included for completeness.
■ PARALLEL (AUTO): The database computes the degree of parallelism, which can be?
1 or greater. If the computed degree of parallelism is 1, then the statement runs?
serially.
■ PARALLEL (MANUAL): The optimizer is forced to use the parallel settings of the?
objects in the statement.
■ PARALLEL (integer): The optimizer uses the degree of parallelism specified by?
integer.
In the following example, the optimizer calculates the degree of parallelism. The?
statement always runs in parallel.
SELECT /*+ PARALLEL */ last_name
? FROM employees;
In the following example, the optimizer calculates the degree of parallelism, but that?
degree may be 1, in which case the statement will run serially.
SELECT /*+ PARALLEL (AUTO) */ last_name
? FROM employees;
11g new feature:
For a statement-level PARALLEL hint:
■ PARALLEL: The statement always is run parallel, and the database computes the?
degree of parallelism, which can be 2 or greater.
■ PARALLEL (DEFAULT): The same as PARALLEL. The DEFAULT keyword is?
included for completeness.
■ PARALLEL (AUTO): The database computes the degree of parallelism, which can be?
1 or greater. If the computed degree of parallelism is 1, then the statement runs?
serially.
■ PARALLEL (MANUAL): The optimizer is forced to use the parallel settings of the?
objects in the statement.
■ PARALLEL (integer): The optimizer uses the degree of parallelism specified by?
integer.
In the following example, the optimizer calculates the degree of parallelism. The?
statement always runs in parallel.
SELECT /*+ PARALLEL */ last_name
? FROM employees;
In the following example, the optimizer calculates the degree of parallelism, but that?
degree may be 1, in which case the statement will run serially.
SELECT /*+ PARALLEL (AUTO) */ last_name
? FROM employees;
總結(jié)
以上是生活随笔為你收集整理的Oracle表的并行度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么使用NativeJdbcExtra
- 下一篇: 给控件添加小图标