环境:AIX 5.3.0.0
数据库版本:Informational tokens are "DB2 v9.5.0.4", "s090429", "U825478", and Fix Pack "4".
问题描述:有一个统计需求,需要根据该参数表a中的某些取值找到b表中对应的行业机构,再根据b表的行业机构找到对应的商户,跟根据这些商户最后找到对应的终端,并对上述商户和终端进行统计。编写完成SQL之后发现执行效率非常差,请问诸位如何进行性能调优。
问题SQL:
select
count(distinct b.m) as total_reg_mchnt,
count(distinct b.m||c.t) as total_reg_mchnt
from access_sys a,
mchnt_inf b,
pos_inf c
where a.spec= '5301'
and substr(a.access,3,8) = b.industry
and b.m = c.m
real 27m19.16s
user 0m0.01s
sys 0m0.01s
其他信息补充:
1.每张表的数据量
db2 "
select 'access_sys '||char(count(*)) from access_sys union all
select 'mchnt_inf '||char(count(*)) from mchnt_inf union all
select 'pos_inf '||char(count(*)) from pos_inf "
access_sys 1263
mchnt_inf 4854345
pos_inf 7994221
2.筛选因子
db2 "select count(case when spec = '5301' then 1 end) as result from access_sys"
RESULT
-----------
3
1 record(s) selected.
db2 "select ACCESS from access_sys where spec = '5301' "
ACCESS
----------------
0049910005S
0049914219S
0049917515S
db2 "select count(*) as result from mchnt_inf where industry in ('0049910005','0049914219','0049917515')"
RESULT
-----------
0
3.执行计划
附件:
db2expln.out (18.35 KB)
db2exfmt.out (67.44 KB)