SQL中並行操作

darren__chan發表於2014-11-23

                   --並行查詢
select /*+parallel(t 4)*/ count(*) from user_tables t;
select /*+parallel(t 4)*/ count(*) from t where object_name in(select /*+parallel(t1 4)*/ object_name from t1);
--一個並行查詢能夠執行,需要滿足下面其中一個:
a)sql語句中有hint提示,比如parallel或者parallel_index;
b)sql語句中引用的物件被設定了並行屬性;
c)多表關聯中至少有一個表執行全表掃描(full table scan)或者跨越分割槽的index range scan
d)在會話中執行:alter session force parallel query parallel 4;


--並行ddl操作:
create table t parallel 4 as select * from dba_objects;
alter table t move partition p1 parallel 4;
alter table t split partition p1 at(5000) into (partition p1,partition p2) parallel 4;
alter table t coalesce partition parallel 4;
create index t_ind on t(id) parallel 4;
alter index t_ind rebuild parallel 4;
alter index t_ind rebuild partition p1 parallel 4;
alter index t_ind split partition p1 at(5000) into (partition p11,partition p12) parallel 4;


--並行DML操作:
DML操作使用並行,必須顯示地在會話裡執行:
alter session enable parallel dml;
delete /*+ parallel(t 2)*/ from t;
update /*+ parallel(t 2)*/ t set name=name||'dcs';
merge /*+parallel(t 2)*/ into t using t1 on (t.id=t1.id) when matched then update set t.name=t1.name;
insert /*+parallel(t 4)*/ into t select /*+parallel(t1 4)*/ * from t1; 
insert into t select /*+parallel(t1 4)*/ * from t1; 
insert /*+parallel(t 4)*/ into t select * from t1; 
insert /*+ append parallel(t,2)*/ into t select * from t;
--sql*loader和parallel:
--如果使用sqlloader的並行直接載入選項,並且表上有索引,將導致載入失敗,可以調整引數:skip_index_maintenance=true,先把資料插入,在rebuild索引。
sqlldr userid=test/oracle control=t.ctl direct=true parallel=true skip_index_maintenance=true log=log.txt;
alter index t_ind rebuild parallel 4;

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

相關文章