以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请问sql查询显示查询超时,怎么解决?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=137353)

--  作者:hbhb
--  发布时间:2019/7/4 9:17:00
--  请问sql查询显示查询超时,怎么解决?
大师:较复杂的sql查询语句,执行后显示查询超时,如何优化,或怎么解决? 比如下面的语句
S————E_LECT pzFL.FVoucherID,pzM.FDate as date,pzM.FPeriod as month,pzM.FGroupID,pzM.FNumber,pzM.FPosted as 记账标志,pzFL.FEntryID,pzFL.FExplanation as zy,pzFL.FAccountID,(case when  pzfl.fdc = 1 then pzfl.famount end) as jej, (case  when pzfl.fdc <> 1 then pzfl.famount end) as jed, pzFL.FCurrencyID,pzFL.FExchangeRate,pzFL.FDC,pzFL.FAmountFor,pzFL.FAmount,pzFL.FQuantity,pzFL.FMeasureUnitID,pzFL.FUnitPrice,pzFL.FDetailID,pzfz.FName + \'-\' + Format(pzm.FNumber,\'\') as pzlbname,km.FNumber as kmid,km.FName as kmname,Item8.FName as xm,Item8.FNumber as xmdl,Item9.FName as xm2,Item9.FNumber as xmdl2,Item10.FName as xm3,Item10.FNumber as xmdl3,Item11.FName as xm4 FROM t_Voucher As pzM INNER JOIN t_VoucherEntry As pzFL ON pzM.FVoucherID = pzFL.FVoucherID left join t_VoucherGroup pzfz on pzM.FGroupID = pzfz.FGroupID left join t_Account km on km.FAccountID = pzfl.FAccountID left JOIN t_ItemDetailV tailV  ON pzfl.FDetailID = tailv.FDetailID left JOIN t_Item item8 ON item8.FItemID = tailv.fitemid And (tailv.fitemclassid = 1 Or  tailv.fitemclassid = 8) left JOIN t_Item item9 ON item9.FItemID = tailv.fitemid And (tailv.fitemclassid = 2) left JOIN t_Item item10 ON item10.FItemID = tailv.fitemid And (tailv.fitemclassid = 3) left JOIN t_Item item11 ON item11.FItemID = tailv.fitemid And (tailv.fitemclassid > 3 And  tailv.fitemclassid <> 8) where pzM.FYear = 2014 And pzM.FPeriod<= 12 ORDER BY pzM.FPeriod,pzm.FNumber,pzM.FVoucherID,pzFL.FEntryID

--  作者:有点蓝
--  发布时间:2019/7/4 9:52:00
--  
1、添加必要的索引
2、尽量不要在sql里使用函数
3、使用SQLCommand,增加超时时间