在一个交易中进行的更改是否“互相看”?

时间:2022-11-13 14:22:43

Suppose I do the following set of SQL queries (pseudocode) in a table with only one column CITY:

假设我在一个只有一列CITY的表中执行以下一组SQL查询(伪代码):

BEGIN TRANSACTION;
INSERT INTO MyTable VALUES( 'COOLCITY' );
SELECT * FROM MyTable WHERE ALL;
COMMIT TRANSACTION;

is the SELECT guaranteed to return COOLCITY?

SELECT保证返回COOLCITY?

1 个解决方案

#1


6  

Yes.

是。

The INSERT operation would take an X lock out on at least the newly added row. This won't get released until the end of the transaction thus preventing a concurrent transaction from deleting or updating this row.

INSERT操作将至少对新添加的行进行X锁定。这将在事务结束之前释放,从而防止并发事务删除或更新此行。

A transaction is not blocked by its own locks so the SELECT would return COOLCITY.

事务不会被自己的锁阻塞,因此SELECT将返回COOLCITY。

#1


6  

Yes.

是。

The INSERT operation would take an X lock out on at least the newly added row. This won't get released until the end of the transaction thus preventing a concurrent transaction from deleting or updating this row.

INSERT操作将至少对新添加的行进行X锁定。这将在事务结束之前释放,从而防止并发事务删除或更新此行。

A transaction is not blocked by its own locks so the SELECT would return COOLCITY.

事务不会被自己的锁阻塞,因此SELECT将返回COOLCITY。