Foxtable(狐表)用户栏目专家坐堂 → 请问sql查询显示查询超时,怎么解决?


  共有3225人关注过本帖树形打印复制链接

主题:请问sql查询显示查询超时,怎么解决?

帅哥哟,离线,有人找我吗?
hbhb
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5061 积分:13092 威望:0 精华:0 注册:2014/5/15 21:34:00
请问sql查询显示查询超时,怎么解决?  发帖心情 Post By:2019/7/4 9:17:00 [只看该作者]

大师:较复杂的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

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110790 积分:563882 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/7/4 9:52:00 [只看该作者]

1、添加必要的索引
2、尽量不要在sql里使用函数
3、使用SQLCommand,增加超时时间

 回到顶部