Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phantom rows caused by update statements which changes value of the primary key #48960

Closed
Reverie4u opened this issue Nov 28, 2023 · 3 comments
Closed
Labels
sig/transaction SIG:Transaction type/question The issue belongs to a question. type/stale This issue has not been updated for a long time.

Comments

@Reverie4u
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

/* init */ CREATE TABLE t(a INT PRIMARY KEY, b INT); 
/* init */ INSERT INTO t VALUES (1, 1);
/* init */ INSERT INTO t VALUES (2, 2);
/* t1 */ SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
/* t2 */ SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
/* t1 */ BEGIN;
/* t2 */ BEGIN;
/* t2 */ SELECT * FROM t;  -- [(1, 1), (2, 2)]
/* t1 */ UPDATE t SET a=3 WHERE b = 2;
/* t1 */ COMMIT;
/* t2 */ UPDATE t SET b=3;
/* t2 */ SELECT * FROM t; -- [(1, 3), (2, 2), (3, 3)] 
/* t2 */ COMMIT;

2. What did you expect to see? (Required)

The second consistent read of t2 should return [(1, 3), (3, 3)].

3. What did you see instead (Required)

Actual result is [(1, 3), (2, 2), (3, 3)] , though the final state of table t is [(1, 3), (3, 3)] after COMMIT of t2.

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.1.2
Edition: Community
Git Commit Hash: aa6ed99ae63191bc98e883fd4c369ae7482cccb7
Git Branch: heads/refs/tags/v7.1.2
UTC Build Time: 2023-10-21 07:46:04
GoVersion: go1.20.10
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

@Reverie4u Reverie4u added the type/bug The issue is confirmed as a bug. label Nov 28, 2023
@Reverie4u
Copy link
Author

This bug can also be reproduced in MySQL 8.2.0 and has been verified by MySQL Verification Team. Please see: https://bugs.mysql.com/bug.php?id=113228

@aytrack aytrack added the sig/transaction SIG:Transaction label Nov 29, 2023
@zyguan
Copy link
Contributor

zyguan commented Dec 1, 2023

I think this behaviour has been documented here. In practice, you should always use select for update in a write transaction. The issue is also related to #24195.

@jebter jebter added type/question The issue belongs to a question. and removed type/bug The issue is confirmed as a bug. labels Sep 4, 2024
@jebter
Copy link

jebter commented Sep 4, 2024

The issue has not been updated for too long, so I will close it,if there are any updates, you can reopen it.

@jebter jebter closed this as completed Sep 4, 2024
@jebter jebter added the type/stale This issue has not been updated for a long time. label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/transaction SIG:Transaction type/question The issue belongs to a question. type/stale This issue has not been updated for a long time.
Projects
None yet
Development

No branches or pull requests

4 participants