查询语句优化,现在遇到一个问题,语句我认为已经很简单了,但查询数据量大的时候还是很慢

查询语句优化,现在遇到一个问题,语句我认为已经很简单了,但查询数据量大的时候还是很慢,即使我只选择了时间范围查询(比如去年到今天一年),其他控件都是空白的。

/*

SELECT

a.product_no,

a.batch_number,

a.busi_type,

a.furnace_no,

a.matrial_gz,

a.inv_gz,

a.inv_model,

a.define01,

a.executive_standard,

a.num,

a.update_date,

a.theory_weight,

a.inv_name,

a.define05,

a.define08,

a.remain_num,

a.define15,

a.icheck,

a.define06,

a.define07,

a.inv_code,

a.define09,

a.define10,

a.ware_name,

a.define02,

a.define03,

a.define13,

a.define14,

a.create_date,

a.check_time,

a.location_name,

a.define22,

c.realname AS check_name ,

d.realname as  create_name,

CASE

          WHEN a.remain_num = '0'   AND a.busi_type<>'OutInvol'

          THEN  '出库' 

          WHEN a.remain_num > '0'  AND a.busi_type<>'OutInvol'

          THEN  '库存' 

          ELSE '内盘出库'   

        END  AS  zt

FROM pd_store_record a  

LEFT JOIN sys_user c ON a.`check_user_id`=c.`id`

LEFT JOIN sys_user d ON a.`create_user_id`=d.`id`

WHERE  a.busi_type <> 'OutStock' AND  a.ideleted=0 and

a.create_date BETWEEN  '${startTime}' AND '${endTime}'

${if(kczt==1," and   a.remain_num > '0'  and   a.busi_type<>'OutInvol'","")}

     ${if(kczt==2," and   a.remain_num = '0'  and   a.busi_type<>'OutInvol'","")}

     ${if(kczt==3,"and a.busi_type='OutInvol'","")}

${if(len(icheck) == 0,"","and a.icheck='"+icheck+"'")}

${if(len(ck)==0,"","and a.ware_name='"+ck+"'")}

${if(len(inv_model) == 0,"","and a.inv_model like '%" + inv_model + "%'" )}

${if(len(define13) == 0,"","and a.define13 like '%" + define13 + "%'" )}

${if(len(define22) == 0,"","and a.define05 like '%" + define22 + "%'" )}

     ${if(len(TEXTT) == 0,"","and a.define22 like '%" + TEXTT + "%'" )}

${if(len(product_no) == 0,"","and a.product_no like '%" + product_no + "%'" )}

${if(len(define0222) == 0,"","and a.define02 in ('" + define0222 + "')")}

${if(len(furnace_no) == 0,"","and a.furnace_no like '%" + furnace_no + "%'" )}

${if(len(batch_number) == 0,"","and a.batch_number like '%" + batch_number + "%'" )}

${if(len(define03) == 0,"","and a.define03=  '" + define03 + "'" )}

${if(len(define01) == 0,"","and a.define01 like '" + define01 + "'" )}

${if(len(inv_gz) == 0,"","and a.inv_gz like '%" + inv_gz + "%'" )}

${if(len(executive_standard) == 0,"","and a.executive_standard like '%" + executive_standard + "%'" )}

${if(len(define07) == 0,"","and a.define07='"+define07+"'")}

${if(len(matrial_gz) == 0,"","and a.matrial_gz= '" + matrial_gz + "'" )}

*/

张三学帆软 发布于 2022-6-8 11:38 (编辑于 2022-6-8 11:39)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2022-6-8 11:40

直接在你的数据库管理工具里面查询速度咋样?

最佳回答
0
FuFuLv5初级互助
发布于2022-6-8 11:39

小表关联大表

  • 2关注人数
  • 362浏览人数
  • 最后回答于:2022-6-8 11:40
    请选择关闭问题的原因
    确定 取消
    返回顶部