Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
11.7.2
-
None
-
None
-
Ubuntu 22.04
Description
When I tested the database repeatable read isolation level, I found a issue.
As shown in the use case below, the delete statement is blocked. But in my opinion there is no lock conflict here and it should not be blocked.
--- I see
|
--- session 0 to init
|
SET GLOBAL innodb_lock_wait_timeout = 20; |
SET GLOBAL lock_wait_timeout = 20; |
DROP TABLE IF EXISTS tuEkZFXW; |
CREATE TABLE tuEkZFXW (ID INT, VAL INT, c0 DOUBLE PRIMARY KEY, c1 DECIMAL(55, 11) , c2 BOOLEAN ); |
INSERT INTO tuEkZFXW (ID, VAL, c0, c1, c2) VALUES (460, 561, 6537.3885, 7569.5750, 1); |
INSERT INTO tuEkZFXW (ID, VAL, c0, c1, c2) VALUES (464, 566, 4044.8689, 8585.5846, 1); |
|
--- session 1
|
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; |
BEGIN; |
--- session 2
|
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; |
BEGIN; |
--- session 1
|
INSERT INTO tuEkZFXW (ID, VAL, c0, c2) VALUES ( 468, 570, 7105.4030, 0); |
--- session 2
|
DELETE FROM tuEkZFXW WHERE ( tuEkZFXW.c2 > 0 OR tuEkZFXW.c2 < 0) AND (tuEkZFXW.c0 >= 100); ---blocked |
--- session 1
|
SELECT ID, VAL, tuEkZFXW.c0, tuEkZFXW.c1, tuEkZFXW.c2 FROM tuEkZFXW WHERE ( tuEkZFXW.c2 > 0 OR tuEkZFXW.c2 < 0) AND (tuEkZFXW.c0 >= 100) ORDER BY tuEkZFXW.ID; |
+------+------+-----------+------------------+------+ |
| ID | VAL | c0 | c1 | c2 |
|
+------+------+-----------+------------------+------+ |
| 460 | 561 | 6537.3885 | 7569.57500000000 | 1 |
|
| 464 | 566 | 4044.8689 | 8585.58460000000 | 1 |
|
+------+------+-----------+------------------+------+ |
2 rows in set (0.00 sec) |
COMMIT; |
--- session 2
|
COMMIT; |
|
--- expected to see
|
--- I see in PG
|
...
|
--- session 2 (not block)
|
DELETE FROM tuEkZFXW WHERE ( tuEkZFXW.c2 > 0 OR tuEkZFXW.c2 < 0) AND (tuEkZFXW.c0 >= 100); |
DELETE 3 |
--- session 1
|
SELECT ID, VAL, tuEkZFXW.c0, tuEkZFXW.c1, tuEkZFXW.c2 FROM tuEkZFXW WHERE ( tuEkZFXW.c2 > 0 OR tuEkZFXW.c2 < 0) AND (tuEkZFXW.c0 >= 100) ORDER BY tuEkZFXW.ID; |
id | val | c0 | c1 | c2
|
-----+-----+-----------+----------+----
|
460 | 561 | 6537.3887 | 7569.575 | 1
|
464 | 566 | 4044.869 | 8585.585 | 1
|
(2 rows) |
...
|
Attachments
Issue Links
- relates to
-
MDEV-16232 Use fewer mini-transactions
-
- Stalled
-
-
MDEV-16402 Support Index Condition Pushdown for clustered PK scans
-
- Confirmed
-
-
MDEV-35124 Set innodb_snapshot_isolation=ON by default
-
- Closed
-
I can reproduce the claimed blocking in a recent build of the 10.11 branch. I converted the described scenario to a .test file of the mtr tool:
--source include/have_innodb.inc
disconnect con2;
Like I expect, the DELETE statement will be blocked in lock_wait(). The condition c0>=100 should match all READ UNCOMMITTED rows in the table. Both DELETE and UPDATE will typically be preceded by a call to row_search_mvcc() with prebuilt->select_lock_type=LOCK_X. I see that the DELETE is invoking lock_rec_convert_impl_to_expl() on the record c0=7105.4030 that the conflicting INSERT statement executed.
Why do you think that this locking conflict is unreasonable? For the record, when I replaced the DELETE with the following statement (to take advantage of
MDEV-13115), the locked record was skipped in the output: