分析表,重新估算统计信息
ANALYZE TABLE tasharecurrents ESTIMATE statistics;
打开或关闭表的并行选项
ALTER TABLE tasharecurrents PARALLEL;
--ALTER TABLE tasharecurrents NOPARALLEL;
启用oracle hint,强制执行计划,分别记录有并行和无并行的执行时间
select --/*+ parallel(t)*/
b.fundname 基金名称,
sum(nvl(t.lastshares, 0)) 份额,
sum(decode(m.individualorinstitution, '1', 0, t.lastshares)) 机构投资者,
sum(decode(m.individualorinstitution, '1', t.lastshares, 0)) 个人投资者,
count(distinct(decode(m.individualorinstitution, '1', null, t.taaccountid))) 机构投资者数量, -- null的个数不计入count
count(distinct(decode(m.individualorinstitution, '1', t.taaccountid, null))) 个人投资者数量
from tasharecurrents t,
tafundtype b,
taaccoinfo m
where 1 = 1
and t.fundcode = b.fundcode
and t.taaccountid = m.taaccountid
AND t.transcfmdate <= to_date('20070430', 'yyyymmdd')
and t.sharevaliddate > to_date('20070430', 'yyyymmdd')
and t.lastshares > 0
group by b.fundname
;
执行计划为
SELECT STATEMENT, GOAL = CHOOSE Cost=22780 Cardinality=13 Bytes=832
SORT GROUP BY Cost=22780 Cardinality=13 Bytes=832
SORT GROUP BY Cost=22780 Cardinality=13 Bytes=832
SORT GROUP BY Cost=22780 Cardinality=13 Bytes=832
HASH JOIN Cost=17001 Cardinality=6908778 Bytes=442161792
TABLE ACCESS FULL Object owner=TA Object name=TAFUNDTYPE Cost=2 Cardinality=13 Bytes=195
HASH JOIN Cost=16999 Cardinality=6908778 Bytes=338530122
TABLE ACCESS FULL Object owner=TA Object name=TAACCOINFO Cost=2114 Cardinality=2590572 Bytes=33677436
TABLE ACCESS FULL Object owner=TA Object name=TASHARECURRENTS Cost=14885 Cardinality=6908778 Bytes=248716008
最后,比较发现并行对该查询没有效果,有无并行的执行时间基本相同。初步估计可能跟tasharecurrents的存储结构有关系。tasharecurrents有500万行,记录平均长度约150byte,taaccoinfo约200万行记录,记录平均长度约150byte。两个表没有分区。
其它相关sqlplus命令:
show parameter opt
alter system set optimizer_mode = ALL_ROWS scope = spfile;