简体   繁体   English

SQL SERVER,使用(TABLOCKX)选择查询比使用(NOLOCK)更快,反之亦然?

[英]SQL SERVER, will select query with (TABLOCKX) faster than with(NOLOCK) or vice versa?

I had question above question. 我对以上问题有疑问。 We are using with nolock through out the application. 我们在整个应用程序中使用nolock。 In some cases I need to work select faster, what ever the effect. 在某些情况下,无论效果如何,我都需要更快地选择。

So select with(TABLOCKX) will be faster or with(nolock) ? 所以select with(TABLOCKX)会更快或with(nolock)吗?

To answer your question, the with (nolock) table hint will be faster. 要回答您的问题, with (nolock)表提示会更快。

NOLOCK typically (depending on your DB engine) means give me your data, and I don't care what state it is in, and don't bother holding it still while you read from it. 通常,NOLOCK(取决于您的数据库引擎)意味着将您的数据提供给我,并且我不在乎它处于什么状态,并且在您读取数据时也不会保持它静止不动。 It is all at once faster, less resource-intensive, and very very dangerous. 它的速度更快,资源占用更少,非常危险。

As explained very well here NoLock 正如这里很好解释的

Nolock means you can read some locked rows (with shared locks). Nolock表示您可以读取一些锁定的行(带有共享锁)。 But you still have to wait on other locks. 但是您仍然必须等待其他锁。

Tablockx means you block whole table with exclusive lock for other queries - other session cannot make locks, you cannot be blocked after you block whole table. Tablockx意味着您用排他锁来阻塞整个表以用于其他查询-其他会话无法进行锁定,阻塞整个表后也无法阻塞。 Tablockx is mostly used for rapid inserts. Tablockx主要用于快速插入。

Avoid using nolock everywhere. 避免在任何地方使用nolock。 Try to avoid exclusive locks for longer times or try minimalize your blocking and then you don't need nolocks. 尝试避免排他锁定更长的时间,或者尝试最小化阻塞,然后就不需要nolock。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM