在更新表中的所有行时,锁定方法是否对性能至关重要? [英] When it comes to updating all rows in a table, does the method of locking matter for performance?

查看:65
本文介绍了在更新表中的所有行时,锁定方法是否对性能至关重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是对的后续行动.

所讨论的SQL是

UPDATE stats SET visits = (visits+1)

问题是,出于性能目的,与锁定表stats相比,是否锁定stats中的所有行是否重要?或者,如果数据库使用页锁而不是表/行锁?

And the question is, for the purpose of performance, does it matter if you lock all rows in stats in comparison to locking the table stats? Or, if the database uses a page-lock rather than a table/row lock?

推荐答案

没有谓词.任何自尊的数据库引擎都应解决此问题,并意识到所有行都需要更新.

There is no predicate on this. Any self respecting DB engine should work this out and realise all rows need updated.

通常,不要第二次猜测数据库引擎:性能在主观上是相同的.

Generally, don't second guess the DB engine: performance is subjectively the same.

个人

  • 除非必要并且不知道为什么这样做,否则我不会使用表或锁定提示.
  • 无论如何,我都不会从没有WHERE子句的应用程序发出这样的查询

这篇关于在更新表中的所有行时,锁定方法是否对性能至关重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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