mariadb/mysql-test/main/update_innodb.test
Sergei Petrunia fe41171c96 MDEV-33533: Crash at execution of DELETE when trying to use rowid filter
(Based on original patch by Oleksandr Byelkin)

Multi-table DELETE can execute via "buffered" mode: at phase #1 it collects
rowids of rows to be deleted, then at phase #2 in multi_delete::do_deletes()
it calls handler->rnd_pos() to read rows to be deleted and deletes them.

The problem occurred when phase #1 used Rowid Filter on the table that
phase #2 would be deleting from.
In InnoDB, h->rnd_init(scan=false) and h->rnd_pos() is an index scan over PK
under the hood. So, at phase #2 ha_innobase::rnd_init() would try to use the
Rowid Filter and hit an assertion inside ha_innobase::rnd_init().

Note that multi-table UPDATE works similarly but was not affected, because
patch for MDEV-7487 added code to disable rowid filter for phase #2 in
multi_update::do_updates().

This patch changes the approach:
- It makes InnoDB not use Rowid Filter in rnd_pos() scans: it is disabled in
  ha_innobase::rnd_init() and enabled back in ha_innobase::rnd_end().
- multi_update::do_updates() no longer disables Rowid Filter for phase#2 as
  it is no longer necessary.
2024-05-13 09:52:39 +02:00

211 lines
5.6 KiB
Text

--source include/have_innodb.inc
CREATE TABLE `t1` (
`c1` int(11) NOT NULL,
`c2` datetime DEFAULT NULL,
PRIMARY KEY (`c1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `t2` (
`c0` varchar(10) NOT NULL,
`c1` int(11) NOT NULL,
`c2` int(11) NOT NULL,
PRIMARY KEY (`c0`,`c1`),
KEY `c1` (`c1`),
KEY `c2` (`c2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `t3` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`c1` datetime NOT NULL,
`c2` bigint(20) NOT NULL,
`c3` int(4) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `c2` (`c2`),
KEY `c3` (`c3`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `t4` (
`c1` int(11) NOT NULL,
`c2` bigint(20) DEFAULT NULL,
`c3` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t4`.`c1` AS `c1`,`t4`.`c2` AS `c2`,`t4`.`c3` AS `c3` from `t4`;
UPDATE t1 a JOIN t2 b ON a.c1 = b.c1 JOIN v1 vw ON b.c2 = vw.c1 JOIN t3 del ON vw.c2 = del.c2 SET a.c2 = ( SELECT max(t.c1) FROM t3 t, v1 i WHERE del.c2 = t.c2 AND vw.c3 = i.c3 AND t.c3 = 4 ) WHERE a.c2 IS NULL OR a.c2 < '2011-05-01';
drop view v1;
drop table t1,t2,t3,t4;
--echo #
--echo # MDEV-14862: Server crashes in Bitmap<64u>::merge / add_key_field
--echo #
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (b INT) ENGINE=InnoDB;
DELETE FROM v1 WHERE a IN ( SELECT a FROM t2 );
DELETE FROM v1 WHERE (a,a) IN ( SELECT a,a FROM t2 );
drop view v1;
drop table t1,t2;
--echo #
--echo # MDEV-10232 Scalar result of subquery changes after adding an outer select stmt
--echo #
CREATE TABLE t1 (
a_id INT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
b_id INT(20) UNSIGNED NULL DEFAULT NULL,
c_id VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (a_id))COLLATE = 'utf8_general_ci' ENGINE = InnoDB;
CREATE TABLE t2 (
b_id INT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
c_id VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (b_id),
INDEX idx_c_id (c_id))COLLATE = 'utf8_general_ci' ENGINE = InnoDB;
INSERT INTO t1 (b_id, c_id) VALUES (NULL, NULL);
INSERT INTO t2 (c_id) VALUES (NULL);
INSERT INTO t2 (c_id) VALUES (NULL);
SELECT * FROM t1;
SELECT t2.b_id FROM t1,t2 WHERE t2.c_id = t1.c_id;
UPDATE t1 SET b_id = (SELECT t2.b_id FROM t2 t2 WHERE t2.c_id = t1.c_id);
SELECT * FROM t1;
drop table t1,t2;
--echo #
--echo # MDEV-18300: ASAN error in Field_blob::get_key_image upon UPDATE with subquery
--echo #
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set @save_use_stat_tables= @@use_stat_tables;
set use_stat_tables=preferably;
set optimizer_use_condition_selectivity=4;
CREATE TABLE t1 (a INT, b CHAR(8)) ENGINE=InnoDB;
insert into t1 values (1,'foo'),(2, 'abc');
CREATE TABLE t2 (c CHAR(8), d BLOB) ENGINE=InnoDB;
insert into t2 values ('abc', 'foo'),('edf', 'food');
--disable_result_log
ANALYZE TABLE t1,t2;
--enable_result_log
UPDATE t1 SET a = 1 WHERE b = ( SELECT c FROM t2 WHERE d = 'foo' );
SELECT * FROM t1;
DROP TABLE t1, t2;
create table t1 (a int not null, b int, c int) engine=InnoDB;
create table t2 (d int, e int) engine=InnoDB;
update t1, t2 set a=NULL, b=2, c=NULL where b=d and e=200;
drop table t1,t2;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @@use_stat_tables= @save_use_stat_tables;
--disable_view_protocol
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY) engine=innodb;
CREATE TABLE t2 (a INT NOT NULL PRIMARY KEY) engine=innodb;
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);
BEGIN;
SELECT * FROM t1 UNION
SELECT * FROM t2 FOR UPDATE;
--connect(con2,localhost,root,,)
BEGIN;
--send SELECT * FROM t2 FOR UPDATE;
--connection default
select * from t2;
update t2 set a=a+100;
commit;
--connection con2
--reap
commit;
--connection default
drop table t1,t2;
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY) engine=innodb;
CREATE TABLE t2 (a INT NOT NULL PRIMARY KEY) engine=innodb;
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);
BEGIN;
SELECT * FROM (
SELECT * FROM t1 UNION
SELECT * FROM t2 FOR UPDATE
) t;
--connection con2
BEGIN;
--send SELECT * FROM t2 FOR UPDATE;
--connection default
select * from t2;
update t2 set a=a+100;
commit;
--connection con2
--reap
commit;
--connection default
disconnect con2;
drop table t1,t2;
--enable_view_protocol
--echo # End of 10.4 tests
--echo #
--echo # MDEV-33533: multi-delete using rowid filter
--echo #
set @save_default_storage_engine=@@default_storage_engine;
set default_storage_engine=InnoDB;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
--disable_query_log
--disable_result_log
--disable_warnings
--source include/dbt3_s001.inc
--enable_warnings
--enable_result_log
--enable_query_log
create index i_n_name on nation(n_name);
analyze table
nation, lineitem, customer, orders, part, supplier, partsupp, region
persistent for all;
let $c1=
o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey = c_custkey and
c_nationkey = n_nationkey and
n_name='PERU';
explain
update orders, customer, nation set orders.o_comment = "+++" where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey = c_custkey and c_nationkey = n_nationkey and n_name='PERU';
--source include/explain-no-costs.inc
explain format=json
update orders, customer, nation set orders.o_comment = "+++" where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey = c_custkey and c_nationkey = n_nationkey and n_name='PERU';
update orders, customer, nation set orders.o_comment = "+++" where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey = c_custkey and c_nationkey = n_nationkey and n_name='PERU';
DROP DATABASE dbt3_s001;
set default_storage_engine=@save_default_storage_engine;