LINQ更新的“更新检查"有多少开销 [英] How much overhead does 'Update Check' have for LINQ UPDATES

查看:73
本文介绍了LINQ更新的“更新检查"有多少开销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用LINQ编辑的简单行.它大约有30列,包括一个主键数字序列.

I have a simple row that I edit using LINQ. It has about 30 columns, including a primary key numeric sequence.

通过LINQ执行UPDATE时,UPDATE语句包括表的所有列(用于并发检查).

When an UPDATE is performed through LINQ, the UPDATE statement includes all the columns of the table (for concurrency checking).

我想知道这有多低效-如果不是negligibiel.因为主键上有一个索引,所以我假设该列正用于初始行搜索,然后另外检查了其他字段.我不会认为这将花费不多的时间.

I'm wondering how inefficient this is - if not negligibiel. Since there is an index on the primary key I assume that column is being used for the initial row search and then the other fields are being checked in addition. I wouldn't have thought this would take more than a negligible amount of time.

我问的原因是,在某些情况下,我已经看到此UPDATE占用了一秒钟的时间,但这似乎并不正确.可能还会有其他长期运行的事情发生,但是这让我好奇我是否应该担心.

The reason I ask is that I've seen this UPDATE take over a second in some cases, which just doesnt seem right. There may be other long running operations things going on but it made me curious as to whether or not I should be worried.

我知道我可以将所有其他字段的"UpdateCheck"设置为从不,但是这很麻烦.

I know I can set 'UpdateCheck' to never for all the other fields, but this is a pain.

是否可以关闭单个SubmitChanges()的更新检查",还是必须通过更改每个字段的"UpdateCheck"来做到这一点?

Is there a way to turn off 'Update Check' for a single SubmitChanges(), or do I have to do it by changing 'UpdateCheck' for every field.

任何建议将不胜感激.

这是SQL更新:

exec sp_executesql N'UPDATE [dbo].[SiteVisit]
SET [TotalTimeOnSite] = @p12, [ContentActivatedTime] = @p13
WHERE ([SiteVisitId] = @p0) AND ([SiteUserId] IS NULL) AND ([ClientGUID] = @p1) AND ([ServerGUID] IS NULL) AND ([UserGUID] = @p2) AND ([SiteId] = @p3) AND ([EntryURL] = @p4) AND ([CampaignId] = @p5) AND ([Date] = @p6) AND ([Cookie] IS NULL) AND ([UserAgent] = @p7) AND ([Platform] IS NULL) AND ([Referer] = @p8) AND ([KnownRefererId] = @p9) AND ([FlashVersion] IS NULL) AND ([SiteURL] IS NULL) AND ([Email] IS NULL) AND ([FlexSWZVersion] IS NULL) AND ([HostAddress] IS NULL) AND ([HostName] IS NULL) AND ([InitialStageSize] IS NULL) AND ([OrderId] IS NULL) AND ([ScreenResolution] IS NULL) AND ([TotalTimeOnSite] IS NULL) AND ([CumulativeVisitCount] = @p10) AND ([ContentActivatedTime] IS NULL) AND ([ContentCompleteTime] IS NULL) AND ([MasterVersion] = @p11) AND ([VisitedHome] IS NULL) AND ([VisitedStore] IS NULL) AND ([VisitedVideoDemos] IS NULL) AND ([VisitedProducts] IS NULL) AND ([VisitedAdvantages] IS NULL) AND ([VisitedGallery] IS NULL) AND ([VisitedTestimonials] IS NULL) AND ([VisitedEvolution] IS NULL) AND ([VisitedFAQ] IS NULL)',N'@p0 int,@p1 uniqueidentifier,@p2 uniqueidentifier,@p3 int,@p4 varchar(46),@p5 varchar(3),@p6 datetime,@p7 varchar(164),@p8 varchar(36),@p9 int,@p10 int,@p11 int,@p12 int,@p13 int',@p0=1009772,@p1='039A0614-31EE-4DD9-9E1A-8A0F947E1719',@p2='C83C0E68-142A-47CB-B7F9-BAF462E79429',@p3=1,@p4='http://www.example.com/default.aspx?c=183',@p5='183',@p6='2008-11-30 18:22:59:047',@p7='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SIMBAR={85B62341-3F6B-4645-A473-53A2D2BB66DC}; FunWebProducts; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)',@p8='http://apps.facebook.com/inthemafia/',@p9=1,@p10=1,@p11=30,@p12=6,@p13=6

推荐答案

您认为更新检查的开销可以忽略的断言是正确的.如果where子句的任何部分都满足一个索引(或主键),则将使用该索引.检查其他列的成本可以忽略不计.您可以通过在SQL Management Studio(或旧版本的SQL Server的查询分析器)中启用执行计划显示并运行更新来确认这一点.

Your assertion that the overhead for the update check is negligible is correct. If there is an index (or primary key) that is satisfied by any part of the where clause, then that will be used. The cost for checking the other columns is negligible. You can confirm this by enabling the execution plan display in SQL management studio (or query analyzer for older versions of SQL Server) and run your update.

较长的执行时间很可能是由其他原因引起的.锁定是个不错的选择.如果可以重现,请使用SQL事件探查器找出正在发生的事情.

Long execution times is most likely caused by something else. Locking is a good candidate. If you can reproduce it, use SQL Profiler to find out what is going on.

这篇关于LINQ更新的“更新检查"有多少开销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆