Oracle Parallel Query(OPQ)可以將一個(gè)SQL statement分成多個(gè)片(chunks),然后在獨(dú)自的CPU上通過(guò)多個(gè)process進(jìn)行并行運(yùn)行。典型的應(yīng)用是:full table scans, creating or rebuilding an index ,one or more partitions of an index,Partition operations such as moving or splitting partitions,CREATE TABLE AS SELECT operations if the SELECT involves a full table or partition scan 。INSERT INTO . . . SELECT operations, if the SELECT involves a full table or partition scan ,Update and delete operations on partitioned tables,sorts, sub_queries, data loading等.
而另一個(gè)PARALLEL的概念是Parallel Server Clusters(RAC),是利用Clustered 環(huán)境的multi-node來(lái)達(dá)到性能上的總體提高。通常用在一個(gè)非常大的數(shù)據(jù)庫(kù)應(yīng)用中。不在本次討論之列。
一:INIT.ORA相關(guān)參數(shù)
PARALLEL_MIN_SERVERS
PARALLEL_MAX_SERVERS
PARALLEL_AUTOMATIC_TUNING=TRUE (ORACLE會(huì)盡量使用PARALLEL)
二:OBJECT級(jí)啟用OPQ
ALTER TABLE /INDEX XXX PARALLEL (DEGREE 8)
OR
STATEMENT級(jí)
SELECT --+ PARALLEL (table_alias, degree, nodes) from table …..
或/*+ FULL(emp) PARALLEL(table_alias, 35) */
三:表級(jí)停止OPQ
ALTER TABLE/INDEX XXX PARALLEL (DEGREE 1 INSTANCES 1)
OR
ALTER TABLE/INDEX XXX NOPARALLEL;
四:INSTANCE級(jí)
Alter table customer parallel degree 35;
五:局限
Paralle Query并不一定是最好的,尤其是武斷的把所有TABLE都設(shè)置成Paralle Query更是危險(xiǎn)的,因?yàn)?/span>CBO會(huì)改變?cè)u(píng)估標(biāo)準(zhǔn)而盡量使用parallel full-table scans而不是index scans。因?yàn)?/span>CBO認(rèn)為parallel full-table scan的cost比full-table scan低,所以如果非要這么做,那么需要調(diào)整optimizer_index_cost_adj。此值默認(rèn)是1000,如果調(diào)整為10則基本都會(huì)用INDEX,那么可以調(diào)整為小于1000的某個(gè)值,然后及時(shí)監(jiān)控性能并再作調(diào)整。
六
相關(guān)數(shù)據(jù)字典
select * from v_$pq_sysstat;
select * from v_$px_process;
select * from v_$px_sesstat;
select * from v_$px_process_sysstat;
select * from v_$px_process;
select * from v_$px_sesstat;
select * from v_$px_process_sysstat;
七:其他OPQ用法
SQLLDR : SQLLOAD scott/tiger CONTROL=con1.ctl DIRECT=TRUE PARALLEL=TRUE
Parallel Recovery: 1, RECOVERY_PARALLELISM
2,RECOVER TABLESPACE tab PARALLEL (DEGREE 4);
RECOVER DATABASE PARALLEL (DEGREE DEFAULT);
八:名詞解釋
Instance: Specifies the number of instances to use(除非在OPS環(huán)境,否則只需要設(shè)置為1,其他的都是無(wú)意義的)
DEGREE: Specifies the number of slave processes to use on each instance