达梦sql优化实践6

tablep项目sql语句优化
原sql如下:

select
count(0)
from
tablepxx j
where
j.djsj >= ?
and j.djsj < ?
and j.djbmdm in (?)
and exists (
select
1
from
table1r
where
r.tablepid = j.recordid
and r.xh = 1
and r.table3djsj >= ?
and r.table3djsj < ?
)
and exists (
select
1
from
table2m
where
m.sstablepid = j.recordid
and m.xfbmpjzt = ‘2’
)
通过建立djbmdm、djsj字段的联合索引完成优化,优化后执行计划如下:
1 #NSET2: [93, 1, 108]
2 #PRJT2: [93, 1, 108]; exp_num(1), is_atom(FALSE)
3 #AAGR2: [93, 1, 108]; grp_num(0), sfun_num(1) slave_empty(0)
4 #INDEX JOIN SEMI JOIN2: [93, 223, 108];
5 #INDEX JOIN SEMI JOIN2: [91, 332, 108];
6 #BLKUP2: [11, 10661, 108]; IDX_tablepXX_DJBMDM_DJSJ(J)
7 #SSEK2: [11, 10661, 108]; scan_type(ASC), IDX_tablepXX_DJBMDM_DJSJ(tablepXX as J), scan_range[(exp_param(no:2),exp_param(no:0)),(exp_param(no:2),exp_param(no:1)))
8 #SSEK2: [47, 1, 0]; scan_type(ASC), INDEX_tablepID_XH_table3DJSJ(table1as R), scan_range[(J.RECORDID,exp_cast(1),exp_param(no:3)),(J.RECORDID,exp_cast(1),exp_param(no:4)))
9 #SSEK2: [1, 1, 0]; scan_type(ASC), INDEX_MYDPJ_XFBMPJZT_FJID(table2as M), scan_range[(‘2’,J.RECORDID),(‘2’,J.RECORDID)]

优化后,执行时间从26秒,下降到6秒左右。

达梦云适配技术社区的网址。https://eco.dameng.com

你可能感兴趣的:(sql,数据库,database)