SELECT 的事务隔离级别
给定一个在关系数据库上运行的事务,触发一系列 SELECT。
我假设,如果在此事务的中间,任何其他事务对数据库提交了一些 UPDATE 或 INSERT,则此新数据对于前一个事务中的其余剩余选择是可见的。这个假设正确吗?
我的意思是,我假设事务对于读取不是隔离的(它总是读取数据库的最后状态,即使它同时发生变化),而是仅用于写入,不是吗?
如果这取决于每个 RDBMS 的事务策略,那么 Oracle 的策略是什么?
Given a transaction running on a Relational Database, firing a series of SELECTS.
I am supposing that if in the middle of this transaction, any other transaction commits some UPDATE or INSERT against the database, this new data is VISIBLE for the rest of the remaining selects in the former transaction. Is this assumption correct?
I mean, I am supposing that the transaction is not isolated for reading (it always reads the last state of the Database even if it changes in the meanwhile), but only for the writings, is it?
If this depends on the the transactional policy of each RDBMS, what is the policy of Oracle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的假设是正确的,至少对于 Oracle 来说是这样。
Oracle 保证在给定时刻执行的读取的一致性。一旦启动读取,其他事务是否更改所选数据并不重要 - Oracle 保证数据是读取开始时数据库中的数据。如果它不能履行该保证,您将收到“ORA-01555 快照太旧”错误。然而,后续的选择可能不会得到相同的答案。
为了提供读隔离/可重复读,您必须放弃一些并发性,因为您必须锁定表以防止更新。 Oracle 选择高度并发——读者不会阻塞。
如果您只是查找给定时间点的数据,Oracle 确实提供闪回查询。
Your assumption is correct, at least for Oracle.
Oracle guarantees the consistency of a read performed at a given moment. Once the read is initiated, it doesn't matter if other transactions change the data being selected - Oracle guarantees the data is what was in the database at the start of the read. If it can't honor that guarantee, you get an "ORA-01555 snapshot too old" error. However, subsequent selects may not get the same answer.
In order to provide read isolation/repeatable reads, you have to give up some concurrency, because you have to lock the table against updates. Oracle chose to be highly concurrent - readers don't block.
If you're just looking for data at a given point in time, Oracle does provide flashback queries.
复制并粘贴作为问题注释给出的答案:
Oracle 中的默认隔离级别是“读已提交”(您“看到”其他事务提交的更改,即使它们是在您的事务启动后提交的)。 Oracle 还允许您将隔离级别设置为“可串行化”(您只能“看到”事务启动时其他事务已提交的更改)或“只读”(类似于“可串行化”,但它不会允许插入、更新或删除)。有关所有详细信息,请参阅链接。
Copy&Pasting the answer given as comment to the question:
The default isolation level in Oracle is "read committed" (you "see" changes committed by other transactions, even if they were committed after your transaction started). Oracle also allows you to set the isolation level to "serializable" (you only "see" changes that had been committed by other transactions at the time your transaction started) or "read only" (like "serializable", except that it does not allow to INSERT, UPDATE, or DELETE). For all the details, see link.