简体   繁体   English

在INNODB引擎中进行事务处理

[英]Working of Transactions in INNODB engine

Consider a transaction T1, 考虑交易T1,

Start transaction;   
Update emp set emp_id=1 where emp_id=3;   
commit;

The engine i am using is INNODB engine. 我使用的引擎是INNODB引擎。
Before commit operation of the above shown transaction, I had accessed the table again it is showing the previous committed values. 在执行上面显示的事务的提交操作之前,我再次访问了该表,该表显示了先前的提交值。 If the Row Level locking is placed on the table, it might have shown the error ( you cannot access while some transaction is in the middle). 如果将行级别锁定放置在表上,则可能已显示错误( 当某些事务在中间时,您将无法访问)。 Is there any wrong in my understanding.? 我的理解有什么错误吗? Can any one help me on this? 谁可以帮我这个事?

Anything that is done as a part of a transaction is available to the same transaction even before the transaction is committed. 即使在提交事务之前,作为事务的一部分完成的任何操作都可用于同一事务。 The changes are not available in other transactions. 更改在其他事务中不可用。

To test this, you need to update in one transaction and then from another terminal start a new transaction and try to access. 要对此进行测试,您需要在一个事务中进行更新,然后从另一个终端启动一个新事务并尝试访问。 The second transaction will be able to read the data but if you try to update the update will block and wait for the first transaction to be committed. 第二个事务将能够读取数据,但是如果您尝试更新,更新将阻止并等待第一个事务被提交。

If you want the second select to wait and return the updated data you should use select for update. 如果希望第二个选择等待并返回更新的数据,则应使用select进行更新。

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

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