存储过程比单个语句慢,为什么?(50分)

  • 主题发起人 主题发起人 gxcddnk
  • 开始时间 开始时间
G

gxcddnk

Unregistered / Unconfirmed
GUEST, unregistred user!
我编写SQL语句,原来是用go一条一条运行,很快,后来把这些语句放在一个存储过程,这个存储过程还没有参数,但是发现存储过程运行起来没有用go一条一条运行快,慢很多,这是什么原因啊?
 
那肯定啊,过程是用来实现一个复杂功能的,<br>只一条语句没有必要用过程,
 
啥语句,贴出来看看啊
 
以下是我的存储过程<br><br><br>CREATE procedure yxh <br><br>as <br><br>begin <br>set nocount on<br><br>--------前两个月的成交量有效户<br>select left(ls.bizdate,6) ym,ls.fundid,ls.moneytype,sum(ls.matchamt) cjl,sum(ls.fee_jsxf) jsxf<br>&nbsp; &nbsp; &nbsp; &nbsp;into #Bcjlyxh <br>&nbsp; &nbsp; &nbsp; &nbsp;from his..h_logasset ls ,run..brokercust br ,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp;ls.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and ls.fundid=base.custid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and (ls.bizdate&gt;=20080201 and bizdate&lt;=20080331)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and (base.opendate&gt;=20080201 and base.opendate&lt;=20080331)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and ls.fee_jsxf&gt;0 &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;group by left(ls.bizdate,6),ls.fundid,ls.moneytype <br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp;(sum(ls.matchamt)&gt;=10000 &nbsp;and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/7.0 and moneytype=2)<br><br><br>--------前两个月的市值有效户<br>select zj.fundid,zj.moneytype,max(fundbal+marketvalue) gsz,max(marketvalue) valsz into #szyxh &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;from run..hiszjk zj,run..brokercust br <br>&nbsp; &nbsp; &nbsp; &nbsp;where zj.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (rq&gt;=20080201 and rq&lt;=20080331) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp;group by zj.fundid,zj.moneytype <br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp;(max(marketvalue)&gt;=20000 and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/7.0 and &nbsp;moneytype=2)<br><br><br>------ 以下为前两个月已转化的全部有效户详细信息<br>select moneytype,fundid into #allB1B2m from #Bcjlyxh <br>&nbsp; &nbsp; &nbsp; &nbsp;union &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;select moneytype,fundid jsxf from #szyxh <br><br>select t.*,fundname,opendate into #allB1B2m1 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #allB1B2m t,run..fundinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where t.fundid=base.fundid <br>&nbsp; &nbsp;<br><br>select t.*,base.fullname khjlname,br.brokerid custid into #allB1B2m2 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #allB1B2m1 t,run..custbaseinfo base,run..brokercust br <br>&nbsp; &nbsp; &nbsp; &nbsp;where t.fundid=br.fundid and br.brokerid=base.custid <br><br>select moneytype,fundid,fundname fullname,opendate,0 gsz,0 valsz,0 cjl,0 jsxf,khjlname,custid,1 Valid <br>&nbsp; &nbsp; &nbsp; &nbsp;into #allB1B2m3 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #allB1B2m2 where opendate&gt;=20080201<br>&nbsp; <br>----- 以上为前两个月已转化的全部有效户详细信息<br><br>select distinct fundid into #allB1B2 from #allB1B2m <br><br>------当月有效户计算<br>select ls.fundid,ls.moneytype,base.fullname,base.opendate,sum(ls.matchamt) cjl,sum(ls.fee_jsxf) jsxf <br>&nbsp; &nbsp; &nbsp; &nbsp;into #ttt <br>&nbsp; &nbsp; &nbsp; &nbsp;from his..h_logasset ls,run..brokercust br ,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; &nbsp; ls.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and ls.fundid=base.custid &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (ls.bizdate&gt;=20080401 and ls.bizdate&lt;=20080430)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (base.opendate&gt;=20080201 and base.opendate&lt;=20080430)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and ls.fee_jsxf&gt;0 &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;group by ls.fundid,ls.moneytype,base.fullname,base.opendate<br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp; &nbsp; (sum(ls.matchamt)&gt;=10000 &nbsp;and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/7.0 and moneytype=2)<br><br>select #ttt.*,base.fullname khjlname,base.custid into #cjlt <br>&nbsp; &nbsp; &nbsp; &nbsp;from #ttt,run..brokercust br,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where #ttt.fundid=br.fundid and br.brokerid=base.custid <br><br>select zj.fundid,zj.moneytype,max(fundbal+marketvalue) gsz,max(marketvalue) valsz into #tvalt3 <br>&nbsp; &nbsp; &nbsp; &nbsp;from run..hiszjk zj,run..brokercust br <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; &nbsp; zj.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (rq&gt;=20080401 and rq&lt;=20080430) &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp;group by zj.fundid,zj.moneytype<br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp; &nbsp; (max(marketvalue)&gt;=20000 and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/7.0 and &nbsp;moneytype=2)<br><br>select #tvalt3.*,base.fullname khjlname,base.custid into #tvalt4 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #tvalt3,run..brokercust br,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where #tvalt3.fundid=br.fundid and br.brokerid=base.custid <br><br>select #tvalt4.* into #tvalt5 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #tvalt4,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; &nbsp; #tvalt4.fundid=base.custid<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (base.opendate&gt;=20080201 and base.opendate&lt;=20080430)<br><br>select #tvalt5.moneytype,#tvalt5.fundid,base.fullname,base.opendate,#tvalt5.gsz,#tvalt5.valsz,#tvalt5.khjlname,<br>&nbsp; &nbsp; &nbsp; &nbsp;#tvalt5.custid<br>&nbsp; &nbsp; &nbsp; &nbsp;into #valt <br>&nbsp; &nbsp; &nbsp; &nbsp;from #tvalt5,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where #tvalt5.fundid=base.custid <br><br>select moneytype,fundid,fullname,opendate,gsz,valsz,0 cjl,0 jsxf,khjlname,custid into #tallt <br>&nbsp; &nbsp; &nbsp; &nbsp;from #valt<br>&nbsp; &nbsp; &nbsp; &nbsp;union all <br>&nbsp; &nbsp; &nbsp; &nbsp;select moneytype,fundid,fullname,opendate,0 gsz,0 valsz,cjl,jsxf,khjlname,custid from #cjlt <br><br><br>select moneytype,fundid,fullname,opendate,sum(gsz) gsz,sum(valsz) valsz,sum(cjl) cjl,sum(jsxf) jsxf,<br>&nbsp; &nbsp; &nbsp; &nbsp;khjlname,custid<br>&nbsp; &nbsp; &nbsp; &nbsp;into #allt<br>&nbsp; &nbsp; &nbsp; &nbsp;from #tallt<br>&nbsp; &nbsp; &nbsp; &nbsp;group by moneytype,fundid,fullname,opendate,khjlname,custid <br><br>select *,2 Valid into #yallrt<br>&nbsp; &nbsp; &nbsp; &nbsp;from #allt <br>&nbsp; &nbsp; &nbsp; &nbsp;where fundid not in (select fundid from #allB1B2)<br><br>elect #yallrt.*, mem.groupid gid,mem.groupname name into #y1 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from #yallrt<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left join xm..brokergroupmem mem <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on #yallrt.custid=mem.brokerid <br><br>select identity(int,1,1) as odr,moneytype,fundid,fullname,opendate,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gsz,valsz,cjl,jsxf,khjlname,custid,gid,name,Valid into #yaaw<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from #y1 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order by custid asc,Valid desc,fundid asc<br><br>select * from #yaaw<br><br>end<br><br><br>如果直接运行 &nbsp;exec yxh 则时间很长<br><br>但是如果不用存储过程,这样:<br><br>&nbsp;<br>set nocount on<br><br>--------前两个月的成交量有效户<br>select left(ls.bizdate,6) ym,ls.fundid,ls.moneytype,sum(ls.matchamt) cjl,sum(ls.fee_jsxf) jsxf<br>&nbsp; &nbsp; &nbsp; &nbsp;into #Bcjlyxh <br>&nbsp; &nbsp; &nbsp; &nbsp;from his..h_logasset ls ,run..brokercust br ,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp;ls.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and ls.fundid=base.custid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and (ls.bizdate&gt;=20080201 and bizdate&lt;=20080331)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and (base.opendate&gt;=20080201 and base.opendate&lt;=20080331)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and ls.fee_jsxf&gt;0 &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;group by left(ls.bizdate,6),ls.fundid,ls.moneytype <br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp;(sum(ls.matchamt)&gt;=10000 &nbsp;and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/7.0 and moneytype=2)<br>go<br><br>--------前两个月的市值有效户<br>select zj.fundid,zj.moneytype,max(fundbal+marketvalue) gsz,max(marketvalue) valsz into #szyxh &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;from run..hiszjk zj,run..brokercust br <br>&nbsp; &nbsp; &nbsp; &nbsp;where zj.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (rq&gt;=20080201 and rq&lt;=20080331) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp;group by zj.fundid,zj.moneytype <br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp;(max(marketvalue)&gt;=20000 and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/7.0 and &nbsp;moneytype=2)<br>go<br><br>------ 以下为前两个月已转化的全部有效户详细信息<br>select moneytype,fundid into #allB1B2m from #Bcjlyxh <br>&nbsp; &nbsp; &nbsp; &nbsp;union &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;select moneytype,fundid jsxf from #szyxh <br>go<br><br>select t.*,fundname,opendate into #allB1B2m1 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #allB1B2m t,run..fundinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where t.fundid=base.fundid <br>go &nbsp; <br><br>select t.*,base.fullname khjlname,br.brokerid custid into #allB1B2m2 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #allB1B2m1 t,run..custbaseinfo base,run..brokercust br <br>&nbsp; &nbsp; &nbsp; &nbsp;where t.fundid=br.fundid and br.brokerid=base.custid <br>go<br><br>select moneytype,fundid,fundname fullname,opendate,0 gsz,0 valsz,0 cjl,0 jsxf,khjlname,custid,1 Valid <br>&nbsp; &nbsp; &nbsp; &nbsp;into #allB1B2m3 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #allB1B2m2 where opendate&gt;=20080201<br>go<br>&nbsp; <br>----- 以上为前两个月已转化的全部有效户详细信息<br><br>select distinct fundid into #allB1B2 from #allB1B2m <br>go<br><br>------当月有效户计算<br>select ls.fundid,ls.moneytype,base.fullname,base.opendate,sum(ls.matchamt) cjl,sum(ls.fee_jsxf) jsxf <br>&nbsp; &nbsp; &nbsp; &nbsp;into #ttt <br>&nbsp; &nbsp; &nbsp; &nbsp;from his..h_logasset ls,run..brokercust br ,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; &nbsp; ls.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and ls.fundid=base.custid &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (ls.bizdate&gt;=20080401 and ls.bizdate&lt;=20080430)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (base.opendate&gt;=20080201 and base.opendate&lt;=20080430)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and ls.fee_jsxf&gt;0 &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;group by ls.fundid,ls.moneytype,base.fullname,base.opendate<br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp; &nbsp; (sum(ls.matchamt)&gt;=10000 &nbsp;and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (sum(ls.matchamt)&gt;=10000/7.0 and moneytype=2)<br>go<br><br>select #ttt.*,base.fullname khjlname,base.custid into #cjlt <br>&nbsp; &nbsp; &nbsp; &nbsp;from #ttt,run..brokercust br,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where #ttt.fundid=br.fundid and br.brokerid=base.custid <br>go<br><br>select zj.fundid,zj.moneytype,max(fundbal+marketvalue) gsz,max(marketvalue) valsz into #tvalt3 <br>&nbsp; &nbsp; &nbsp; &nbsp;from run..hiszjk zj,run..brokercust br <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; &nbsp; zj.fundid=br.fundid <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (rq&gt;=20080401 and rq&lt;=20080430) &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and substring(cast(br.brokerid as char(12)),5,2)='92'<br>&nbsp; &nbsp; &nbsp; &nbsp;group by zj.fundid,zj.moneytype<br>&nbsp; &nbsp; &nbsp; &nbsp;having &nbsp; &nbsp; (max(marketvalue)&gt;=20000 and moneytype=0) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/0.9 and moneytype=1) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or (max(marketvalue)&gt;=20000/7.0 and &nbsp;moneytype=2)<br>go<br><br>select #tvalt3.*,base.fullname khjlname,base.custid into #tvalt4 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #tvalt3,run..brokercust br,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where #tvalt3.fundid=br.fundid and br.brokerid=base.custid <br>go<br><br>select #tvalt4.* into #tvalt5 <br>&nbsp; &nbsp; &nbsp; &nbsp;from #tvalt4,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where &nbsp; &nbsp; #tvalt4.fundid=base.custid<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and (base.opendate&gt;=20080201 and base.opendate&lt;=20080430)<br>go<br><br>select #tvalt5.moneytype,#tvalt5.fundid,base.fullname,base.opendate,#tvalt5.gsz,#tvalt5.valsz,#tvalt5.khjlname,<br>&nbsp; &nbsp; &nbsp; &nbsp;#tvalt5.custid<br>&nbsp; &nbsp; &nbsp; &nbsp;into #valt <br>&nbsp; &nbsp; &nbsp; &nbsp;from #tvalt5,run..custbaseinfo base <br>&nbsp; &nbsp; &nbsp; &nbsp;where #tvalt5.fundid=base.custid <br>go<br><br>select moneytype,fundid,fullname,opendate,gsz,valsz,0 cjl,0 jsxf,khjlname,custid into #tallt <br>&nbsp; &nbsp; &nbsp; &nbsp;from #valt<br>&nbsp; &nbsp; &nbsp; &nbsp;union all <br>&nbsp; &nbsp; &nbsp; &nbsp;select moneytype,fundid,fullname,opendate,0 gsz,0 valsz,cjl,jsxf,khjlname,custid from #cjlt <br>go<br><br>select moneytype,fundid,fullname,opendate,sum(gsz) gsz,sum(valsz) valsz,sum(cjl) cjl,sum(jsxf) jsxf,<br>&nbsp; &nbsp; &nbsp; &nbsp;khjlname,custid<br>&nbsp; &nbsp; &nbsp; &nbsp;into #allt<br>&nbsp; &nbsp; &nbsp; &nbsp;from #tallt<br>&nbsp; &nbsp; &nbsp; &nbsp;group by moneytype,fundid,fullname,opendate,khjlname,custid <br>go<br><br>select *,2 Valid into #yallrt<br>&nbsp; &nbsp; &nbsp; &nbsp;from #allt <br>&nbsp; &nbsp; &nbsp; &nbsp;where fundid not in (select fundid from #allB1B2)<br>go<br><br>elect #yallrt.*, mem.groupid gid,mem.groupname name into #y1 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from #yallrt<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left join xm..brokergroupmem mem <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on #yallrt.custid=mem.brokerid <br>go<br><br>select identity(int,1,1) as odr,moneytype,fundid,fullname,opendate,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gsz,valsz,cjl,jsxf,khjlname,custid,gid,name,Valid into #yaaw<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; from #y1 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order by custid asc,Valid desc,fundid asc<br>go<br><br>select * from #yaaw<br>go<br><br>就会快很多,我算了一下,会快10倍,不知道什么原因
 
不知道啥原因,用查询分析器里面的 查询-&gt;显示执行计划, 看看执行存储过程的时候哪消耗资源最多吧。<br>表的索引啥的都建好了吗?
 
试试commit;
 
中间生成了很多的临时结果集,那些临时结果集都没有索引,<br>我想是否是事务的原因,用go一条一条运行每条语句都是一个事务,执行完就写盘了,如果编成存储过程,一个存储过程是一个事务,中间那些结果集不会马上写盘,而且会写大量的日志,占用很多的内存,所以速度慢,<br>该如何解决呢,加commit也不起作用,因为一个存储过程就是一个事务,加了也没用,<br>能不能让一个存储过程运行时不要事务处理?
 
我的意思是每条语句后面都加commit
 
试过了,每条语句都加上<br>&nbsp; &nbsp; &nbsp; begin tran<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; commit tran<br>也没用
 

Similar threads

后退
顶部