Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
11.8, 12.0(EOL), 11.8.2
-
None
-
Linux localhost.localdomain 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Description
Summary
In MariaDB, executing an UPDATE statement may raise ERROR 1020 (HY000): Record has changed since last read in table even when the previous SELECT returns an empty result set. This behavior differs from MySQL and seems overly aggressive.
Reproduction Steps
create table t (a int primary key, b int); |
insert into t values(1,1),(2,2); |
|
session1 > begin; |
session1 > select * from t where b > 3; --empty |
session2 > insert into t values(4,4); |
session1 > update t set b=b+1 where a=1; --success |
session1 > update t set b=b-1 where b=2; --fail, ERROR 1020 (HY000): Record has changed since last read in table 't' |
Expected Behavior
In MySQL, this sequence does not raise any error. The final UPDATE is successful, as no previous read touched the record b = 2.
Actual Behavior in MariaDB
MariaDB raises the following error on the last statement:
ERROR 1020 (HY000): Record has changed since last read in table 't'
|
This is unexpected because:
1. The prior SELECT * FROM t WHERE b > 3 returns no rows.
2. The final UPDATE targets a record that was not involved in the previous SELECT.
3. The first UPDATE (UPDATE t SET b = b + 1 WHERE a = 1) updates the same record but success.