开启并行查询,但是发现开启并行查询反而不如不开启的sql执行效率高..
select
/*+ parallel(pre, 4) */
count(1)
from task t
inner join extract e on t.TASK_ID = e.TASKID
inner join GRKHXXB_PRE pre on e.extractid = pre.extid
where exists(
select 1
from GRBDB_PRE GP
inner join KHBDDZB_PRE KP on GP.GRBDH = KP.GRBDH
where KP.KHBH = pre.KHBH);
原因:如果针对单个表查询,开启并行必然提高效率,但是如果是联查,或者条件中带有子查询。则子查询必须也开启并行,否则会出现外层并行等待内层串行的效果,效果反而不如不开启并行。
以下开启并行有效果:
select /*+ parallel(pre, 4) */
count(1)
from task t
inner join extract e on t.TASK_ID = e.TASKID
inner join GRKHXXB_PRE pre on e.extractid = pre.extid
where exists(
select /*+ parallel(GP, 4) */ 1
from GRBDB_PRE GP
inner join KHBDDZB_PRE KP on GP.GRBDH = KP.GRBDH
where KP.KHBH = pre.KHBH);
同理,insert into select开启并行时,insert需要开启并行,后面的select也许要开启并行
开启并行执行insert
insert /*+ append parallel(pre, 2) nologging */ into ${TABLENAME}_PRE pre
select
/*+ parallel(imp, 2))*/
imp.*
from
IMPORT_DETAIL id
inner join IMPORT_LOG il on id.IMPORT_ID = #{IMPORTID} AND id.IMPORT_ID = il.IMPORT_ID
inner join ${TABLENAME}_IMP imp on imp.IMPORT_LOG_ID = il.IMPORT_LOG_ID