达梦sql优化实践7

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

select
table1.table1_ID as ZDBH ,
table1.RELICCODE as CPBH ,
table1.RELICNAME as CPMC ,
table1.COLLECTIONCODE as ZJBH ,
table1.ORIGINALNAME as YMC ,
table1.ACTUALQUANTITY as SJSL ,
table1.GRADE as JB ,
table1.MATERIAL as PCZDLB2,
table1.YEARID as SD ,
table1.MATERIALTYPE as ZD ,
table1.SIZEDESCRIPTION as CC ,
table1.SOURCE as LY ,
table1.SOURCETYPE as LYLX ,
table1.INJURY as WCQK ,
table1.INGRADLIST ,
table1.ISGRAD ,
table1.CONFIRMGRADE ,
table1.ADDRESS as CTDD ,
table1.INSTORE_DATE as RKRQ ,
table1.DJ_USERSURNAME as USERSURNAME ,
table1.DJ_USERNAME as USERNAME ,
table1.RELICTYPEID as PCWWLB ,
GB_WORKGROUP.WORKGROUPNAME as GROUPNAME ,
table1.GROUPID
from
table1
LEFT JOIN GB_WORKGROUP
ON
GB_WORKGROUP.ID = table1.GROUPID
where
/* 1=1

--and
and*/
    (
            (
                    table1.STOREID     = 23
                AND table1.RELICTYPEID = 204
            )
         OR
            (
                    table1.STOREID     = 23
                AND table1.RELICTYPEID = 205
            )
         OR
            (
                    table1.STOREID = 19
                AND table1.CLASSID = 41
            )
         OR
            (
                    table1.STOREID = 19
                AND table1.CLASSID = 42
            )
         OR
            (
                    table1.STOREID = 19
                AND table1.CLASSID = 43
            )
         OR
            (
                    table1.STOREID = 75
                AND table1.CLASSID = 76
            )
    )
      and table1.STATUS='RZ' limit 10;

其中加粗部分,等号后的数值与STOREID 、CLASSID 字段类型不匹配,发生隐式类型转换导致相关索引不能被使用。
修改为如下:

select
table1.table1_ID as ZDBH ,
table1.RELICCODE as CPBH ,
table1.RELICNAME as CPMC ,
table1.COLLECTIONCODE as ZJBH ,
table1.ORIGINALNAME as YMC ,
table1.ACTUALQUANTITY as SJSL ,
table1.GRADE as JB ,
table1.MATERIAL as PCZDLB2,
table1.YEARID as SD ,
table1.MATERIALTYPE as ZD ,
table1.SIZEDESCRIPTION as CC ,
table1.SOURCE as LY ,
table1.SOURCETYPE as LYLX ,
table1.INJURY as WCQK ,
table1.INGRADLIST ,
table1.ISGRAD ,
table1.CONFIRMGRADE ,
table1.ADDRESS as CTDD ,
table1.INSTORE_DATE as RKRQ ,
table1.DJ_USERSURNAME as USERSURNAME ,
table1.DJ_USERNAME as USERNAME ,
table1.RELICTYPEID as PCWWLB ,
GB_WORKGROUP.WORKGROUPNAME as GROUPNAME ,
table1.GROUPID
from
table1
LEFT JOIN GB_WORKGROUP
ON
GB_WORKGROUP.ID = table1.GROUPID
where
/* 1=1

--and
and*/
    (
            (
                    table1.STOREID     = '23'
                AND table1.RELICTYPEID = '204'
            )
         OR
            (
                    table1.STOREID     = '23'
                AND table1.RELICTYPEID = '205'
            )
         OR
            (
                    table1.STOREID = '19'
                AND table1.CLASSID = '41'
            )
         OR
            (
                    table1.STOREID = '19'
                AND table1.CLASSID = '42'
            )
         OR
            (
                    table1.STOREID = '19'
                AND table1.CLASSID = '43'
            )
         OR
            (
                    table1.STOREID = '75'
                AND table1.CLASSID = '76'
            )
    )

 and table1.STATUS='RZ' limit 10;

优化后,执行时间从5秒,下降到0.09秒。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值