实战上亿数据,如何实现秒查

文章来源:一氧化碳中毒   发布时间:2021-9-23 17:01:30   点击数:
  

作者:Java我人生

blog.csdn.net/chenleixing/article/details/

最近在忙着优化集团公司的一个报表。优化完成后,报表查询速度有从半小时以上(甚至查不出)到秒查的质变。从修改SQL查询语句逻辑到决定创建存储过程实现,花了我3天多的时间,在此总结一下,希望对朋友们有帮助。

数据背景

首先项目是西门子中国在我司实施部署的MES项目,由于项目是在产线上运作(3years+),数据累积很大。在项目的数据库中,大概上亿条数据的表有5个以上,千万级数据的表10个以上,百万级数据的表,很多…

(历史问题,当初实施无人监管,无人监控数据库这块的性能问题。ps:我刚入职不久…)

不多说,直接贴西门子中国的开发人员在我司开发的SSRS报表中的SQL语句:

selectdistinctb.MaterialIDasmatl_def_id,c.Descript,casewhenright(b.MESOrderID,12)thenright(b.MESOrderID,9)elseright(b.MESOrderID,12)endaspom_order_id,a.LotName,a.SourceLotNameasComLot,e.DefIDasComMaterials,e.DescriptasComMatDes,d.VendorID,d.DateCode,d.SNNote,b.OnPlantID,a.SNCUSTfrom(selectm.lotname,m.sourcelotname,m.opetypeid,m.OperationDate,n.SNCUSTfromView1mleftjoinco_sn_link_customerasnonn.SNMes=m.LotNamewhere(m.LotNamein(selectvalfromfn_String_To_Table(

sn,,,1))or(

sn)=)and(m.sourcelotnamein(selectvalfromfn_String_To_Table(

BatchID,,,1))or(

BatchID)=)and(n.SNCustlike%+

SN_ext+%or(

SN_ext)=))aleftjoin(select*fromTable1whereSNType=IntSNandSNRuleName=ProductSNRuleandOnPlantID=

OnPlant)bonb.SN=a.LotNameinnerjoinMMdefinitionsasconc.DefID=b.MaterialIDleftjoinTable1asdond.SN=a.SourceLotNameinnerjoinMMDefinitionsaseone.DefID=d.MaterialIDwherenotexists(selectdistinctLotName,SourceLotNamefromELCV_ASSEMBLE_OPSwhereLotName=a.SourceLotNameandSourceLotName=a.LotName)and(d.DateCodein(selectvalfromfn_String_To_Table(

DCode,,,1))or(

DCode)=)and(d.SNNotelike%+

SNNote+%or(

SNNote)=)and((casewhenright(b.MESOrderID,12)thenright(b.MESOrderID,9)elseright(b.MESOrderID,12)end)in(selectvalfromfn_String_To_Table(

order_id,,,1))or(

order_id)=)and(e.DefIDin(selectvalfromfn_String_To_Table(

转载请注明:http://www.lwblm.com/bzbk/12460.html
  • 上一篇文章:
  • 下一篇文章: 没有了