存储过程竟比程序慢(估计也是并发递交的问题)(20分)

  • 主题发起人 主题发起人 xito_76
  • 开始时间 开始时间
X

xito_76

Unregistered / Unconfirmed
GUEST, unregistred user!
其实程序很简单,主要是insert,以前用一个adoquery逐条插入,后改为存储过程提交(共有200多人同时递交插入数据),竟然老出现死锁,提交死机的情况,是不是存储过程写的有问题,急死了,路过兄弟看一看:<br>CREATE PROCEDURE [SubPjABCD] <br>&nbsp; &nbsp; &nbsp; @name_ArrayA varchar(800),<br>&nbsp; &nbsp; &nbsp; @name_ArrayB varchar(800),<br>&nbsp; &nbsp; &nbsp; @name_ArrayC varchar(800),<br>&nbsp; &nbsp; &nbsp; @name_ArrayD varchar(800),<br>&nbsp; &nbsp; &nbsp; @SelfName varchar(50),<br>&nbsp; &nbsp; &nbsp; @class varchar(50),<br>&nbsp; &nbsp; &nbsp; @subject varchar(50)<br>AS<br>begin transaction<br>set NoCount on <br>delete &nbsp;from &nbsp;PJValue where &nbsp;studentName=@SelfName &nbsp;and class=@class and subject=@subject<br>Insert into PJValue(PJRenName,class,PJA,PJB,PJC,PJD,subject) values(@SelfName,@class, @name_ArrayA, @name_ArrayB, @name_ArrayC, @name_ArrayD,@subject)<br>set Nocount off<br>&nbsp;if @@error=0<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; commit transaction<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rollback transaction<br>&nbsp; &nbsp; end<br>GO<br>程序调用是:<br>&nbsp; &nbsp;with &nbsp;ASPPJ do //asppj是一个 TADOStoredProc;<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; close;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@name_ArrayA').Value:=strA;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@name_ArrayB').Value:=strB;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@name_ArrayC').Value:=strC;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@name_ArrayD').Value:=strD;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@SelfName').Value:=trim(FName.Text);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@class').Value:=trim(Fclass.Text);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Parameters.ParamByName('@subject').Value:=trim(CbSub.Text);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Prepared;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExecProc;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;
 
存储过程在insert前会删除一些已递交的数据,是不是这里会受到影响?
 
是否把下面这条语句取掉?(我看到其他人写的程序没有如此控制)<br>if @@error=0<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; commit transaction<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rollback transaction<br>&nbsp; &nbsp; end
 
只操作一个表,用不用事务都无所谓了,还有看仁兄的过程全是大字符串,感觉实在不妥,首先设计表时就不应该用过多的字符串字段,尽量用整数型比较好,效率很高,毕竟涉及IO操作,如浮点数也可以事先转化成整数来存取,CPU的速度比IO快得多,对大容量高并发尤其如此,还有一点小建议,把日期也分成年月日时分秒成存储,可减小异构数据库SQL语法差异,说得牛头不对马嘴了,见谅啊.
 
我分表插入会不会快一点,判断不同数据,将它们分别插入不同的表去(现在是全部都插入同一个表中)
 
如果是客户端提交数据到服务器,这个存储过程没有任何性能上的提升,和<br>create procedure ps1 <br>as select * from atable 的效率一样.
 
to bsense:如果是客户端提交数据到服务器,这个存储过程没有任何性能上的提升.<br>那么这样说来,存储过程并不能优化客户端提交数据速度,那存储过程一般用在哪里呢?
 
存储过程 不是用在这里的。
 
我的意思是:存储过程所用的场合在哪里?
 
影响性能的在你的删除语句上,插入语句没有关系。如果表过大时,出现堵塞的可能是比较大的。如果 studentName=@SelfName &nbsp;and class=@class and subject=@subject条件在多台机器上读可能产生相同数据(相同=@SelfName,=@class,=@subject)则删除时发生死锁的可能性也是很大的。
 
后退
顶部