日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)

發(fā)布時(shí)間:2025/3/19 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

How NOCOUNT affects ADO.NET一文中提到:

Previously, in Classic ASP and ADO, NOCOUNT was most commonly a factor if you were checking RecordsAffected on Command.Execute(). SqlDataReader does have a RecordsAffected property, but it's rarely used since it's not populated until the datareader has iterated all the rows and the datareader is closed. There are some possible implications if you're using DataAdapters to submit changes to the database, since it uses the rows affected result to determine if the update succeeded. Probably the easiest way to check for that case is to search the codebase for SqlDataAdapter and see if the Update() method is being called.

還有:

Tech notes if you're interested in tracing how RecordsAffected is set and used by pointing Reflector at System.Data:
System.Data.SqlClient.TdsParser.ProcessDone() sets RecordsAffected.
System.Data.Common.DbDataAdapter.UpdateRow() uses reader.RecordsAffected in determining whether to call AcceptChanges and ApplyToDataRow.

保險(xiǎn)一點(diǎn)來說,通過作者所說的調(diào)用Update()來做判斷似乎并不可靠,中間有很多步驟都有可能出問題從而影響最終的結(jié)果。同時(shí),debug起來的也有麻煩了,嵌入sql debug后對(duì)于調(diào)試程序很有用,而如果按作者所說這個(gè)debug的功能都被削減了。又把database和application給分開調(diào)了。

評(píng)論中有人寫了一個(gè)簡(jiǎn)單的測(cè)試程序,并給出了他的測(cè)試結(jié)果,他認(rèn)為還是SET NOCOUNT ON快。

測(cè)試使用的存儲(chǔ)過程
DECLARE?@Start?DATETIME,?@End?DATETIME,?@Counter?INT,?@NoCountOff?INT,?@NoCountOn?INT

CREATE?TABLE?#MyTable?(

Id?
INT?NOT?NULL?IDENTITY(1,1)?PRIMARY?KEY

,?FirstName?
VARCHAR(128)?NOT?NULL

,?LastName?
VARCHAR(128)?NOT?NULL

)

SET?NOCOUNT?OFF

SET?@Counter?=?1

SET?@Start?=?GETDATE()

WHILE?@Counter?<=?150000

BEGIN

INSERT?#MyTable?(FirstName,?LastName)?VALUES?('Scott',?'Whigham')

SET?@Counter?=?@Counter?+?1

END

SET?@End?=?GETDATE()

SELECT?@NoCountOff?=?DATEDIFF(ms,?@Start,?@End)

SET?NOCOUNT?ON

SET?@Counter?=?1

SET?@Start?=?GETDATE()

WHILE?@Counter?<=?150000

BEGIN

INSERT?#MyTable?(FirstName,?LastName)?VALUES?('Scott',?'Whigham')

SET?@Counter?=?@Counter?+?1

END

SET?@End?=?GETDATE()

SELECT?@NoCountOn?=?DATEDIFF(ms,?@Start,?@End)

SELECT?@NoCountOff?AS?'NoCountOff',?@NoCountOn?AS?'NoCountOn',?COUNT(*)?AS?NumberOfRows?FROM?#MyTable

DROP?TABLE?#MyTable


我與他測(cè)試的環(huán)境不同,在xp + SQL 2005 Ent with SP1上測(cè)試的,結(jié)果結(jié)論相反,把結(jié)果數(shù)據(jù)也share給大家:

NoCountOff?? |?? NoCountOn?|?xRate

7106????5893????20.58%
6156????6890????-10.61%
7093????7343????-3.41%
5780????6406????-9.77%
5563????6860????-18.91%
5610????7390????-24.09%
5810????6923????-21.38%
6296????7436????-15.33%

-- insert 1
46????0
16????0
0????0
0????0
16????0

-- insert 1000
420?????393?????6.88%
423?????390?????8.47%
966?????423?????128.37%

-- insert 100,000
43250????42860????0.91%

-- delete all then insert 100,000
42076????39826????5.65%

如果您也親自測(cè)試一下可以很明顯的發(fā)現(xiàn):結(jié)果對(duì)于證明起到的作用很小。

與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。