mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
0235a528e3
The issue is that record_should_be_deleted() returns true in mysql_delete() even if sub-select with join gets error from storage engine when DELETE FROM ... WHERE ... IN (SELECT ...) statement is executed. The same is true for mysql_update() where select->skip_record() returns true even if sub-select with join gets error from storage engine. In the test case if sub-select is chosen as deadlock victim the whole transaction is rolled back during sub-select execution, but mysql_delete()/mysql_update() continues transaction execution and invokes table->delete_row() as record_should_be_deleted() wrongly returns true in mysql_delete() and table->update_row() as select->skip_record(thd) wrongly returns 1 for mysql_update(). record_should_be_deleted() wrogly returns true because thd->is_error() returns false SQL_SELECT::skip_record() invoked from record_should_be_deleted(). It's supposed that THD error should be set in rr_handle_error() called from rr_sequential() during sub-select JOIN::exec_inner() execution. But rr_handle_error() does not set THD error because READ_RECORD::print_error is not set in JOIN_TAB::read_record. READ_RECORD::print_error should be initialized in init_read_record()/init_read_record_idx(). But make_join_readinfo() does not invoke init_read_record()/init_read_record_idx() for JOIN_TAB::read_record. The fix is to set JOIN_TAB::read_record.print_error in make_join_readinfo(), i.e. in the same place where JOIN_TAB::read_record.table is set. Reviewed by Sergey Petrunya.
50 lines
1.3 KiB
Text
50 lines
1.3 KiB
Text
CREATE TABLE t1 (
|
|
pkey int NOT NULL PRIMARY KEY,
|
|
c int
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES(1,1);
|
|
CREATE TABLE t2 (
|
|
pkey int NOT NULL PRIMARY KEY,
|
|
c int
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
INSERT INTO t2 VALUES (2, NULL);
|
|
CREATE TABLE t3 (c int) engine = InnoDB;
|
|
INSERT INTO t3 VALUES (10), (20), (30), (40), (50);
|
|
connect con1, localhost,root,,;
|
|
connection default;
|
|
START TRANSACTION;
|
|
UPDATE t3 SET c=c+1000;
|
|
SELECT * FROM t1 FOR UPDATE;
|
|
pkey c
|
|
1 1
|
|
connection con1;
|
|
START TRANSACTION;
|
|
DELETE FROM t2 WHERE c NOT IN (SELECT ref_0.pkey FROM t1 AS ref_0 INNER JOIN t1 AS ref_1 ON ref_0.c = ref_0.pkey);
|
|
connection default;
|
|
SELECT * FROM t2 FOR UPDATE;
|
|
pkey c
|
|
2 NULL
|
|
COMMIT;
|
|
connection con1;
|
|
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
|
|
COMMIT;
|
|
connection default;
|
|
START TRANSACTION;
|
|
UPDATE t3 SET c=c+1000;
|
|
SELECT * FROM t1 FOR UPDATE;
|
|
pkey c
|
|
1 1
|
|
connection con1;
|
|
START TRANSACTION;
|
|
UPDATE t2 SET pkey=pkey+10 WHERE c NOT IN (SELECT ref_0.pkey FROM t1 AS ref_0 INNER JOIN t1 AS ref_1 ON ref_0.c = ref_0.pkey);
|
|
connection default;
|
|
SELECT * FROM t2 FOR UPDATE;
|
|
pkey c
|
|
2 NULL
|
|
COMMIT;
|
|
connection con1;
|
|
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
|
|
COMMIT;
|
|
disconnect con1;
|
|
connection default;
|
|
DROP TABLE t1,t2,t3;
|