可串行化隔离级别原子性
我有几个线程执行一些具有可序列化隔离级别的 SQL 选择查询。我不确定选择哪个实现。 This:
_repository.Select(...)
或 this
lock (_lockObject)
{
_repository.Select(...);
}
换句话说,是否有可能多个事务同时开始执行,并部分阻塞 Select 操作范围内的记录。
PS 我正在使用 MySQL,但我想这是一个更普遍的问题。
I have several threads executing some SQL select queries with serializable isolation level. I am not sure which implementation to choose. This:
_repository.Select(...)
or this
lock (_lockObject)
{
_repository.Select(...);
}
In other words, is it possible several transactions will start executing at the same time and partially block records inside Select operation range.
P. S. I am using MySQL but I guess it is a more general question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行 SELECT 查询的事务在行上放置共享锁,允许其他事务读取这些行,但阻止它们对行进行更改(包括将新记录插入到行中)间隙)
应用程序中的锁定正在做其他事情,它不会允许其他线程进入从存储库获取数据的代码块,这种方法可能会导致非常糟糕的性能,原因如下:
我建议的 这些情况您通读了第 13.2.8 节。 MySql 文档的 InnoDB 事务模型和锁定,它将让您深入了解 InnoDB 中的锁定是如何执行的。
Transactions performing
SELECT
queries place a shared lock on the rows, permitting other transactions to read those rows, but preventing them from making changes to the rows (including inserting new records into the gaps)Locking in the application is doing something else, it will not allow other threads to enter the code block which fetches the data from the repository, This approach can lead to very bad performance for a few reasons:
I suggest you read through Section 13.2.8. The InnoDB Transaction Model and Locking of the MySql docs, it will give you a great insight how locking in InnoDB is performed.