mirror of
				https://github.com/MariaDB/server.git
				synced 2025-10-30 18:36:12 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			784 lines
		
	
	
	
		
			23 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			784 lines
		
	
	
	
		
			23 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| call mtr.add_suppression("Sort aborted.*");
 | |
| drop table if exists t1,t2,t3,t11,t12;
 | |
| CREATE TABLE t1 (a tinyint(3), b tinyint(5));
 | |
| INSERT INTO t1 VALUES (1,1);
 | |
| INSERT LOW_PRIORITY INTO t1 VALUES (1,2);
 | |
| INSERT INTO t1 VALUES (1,3);
 | |
| DELETE from t1 where a=1 limit 1;
 | |
| DELETE LOW_PRIORITY from t1 where a=1;
 | |
| INSERT INTO t1 VALUES (1,1);
 | |
| DELETE from t1;
 | |
| LOCK TABLE t1 write;
 | |
| INSERT INTO t1 VALUES (1,2);
 | |
| DELETE from t1;
 | |
| UNLOCK TABLES;
 | |
| INSERT INTO t1 VALUES (1,2);
 | |
| SET AUTOCOMMIT=0;
 | |
| DELETE from t1;
 | |
| SET AUTOCOMMIT=1;
 | |
| drop table t1;
 | |
| create table t1 (
 | |
| a bigint not null,
 | |
| b bigint not null default 0,
 | |
| c bigint not null default 0,
 | |
| d bigint not null default 0,
 | |
| e bigint not null default 0,
 | |
| f bigint not null default 0,
 | |
| g bigint not null default 0,
 | |
| h bigint not null default 0,
 | |
| i bigint not null default 0,
 | |
| j bigint not null default 0,
 | |
| primary key (a,b,c,d,e,f,g,h,i,j));
 | |
| insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23);
 | |
| delete from t1 where a=26;
 | |
| drop table t1;
 | |
| create table t1 (
 | |
| a bigint not null,
 | |
| b bigint not null default 0,
 | |
| c bigint not null default 0,
 | |
| d bigint not null default 0,
 | |
| e bigint not null default 0,
 | |
| f bigint not null default 0,
 | |
| g bigint not null default 0,
 | |
| h bigint not null default 0,
 | |
| i bigint not null default 0,
 | |
| j bigint not null default 0,
 | |
| primary key (a,b,c,d,e,f,g,h,i,j));
 | |
| insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27);
 | |
| delete from t1 where a=27;
 | |
| drop table t1;
 | |
| CREATE TABLE `t1` (
 | |
| `i` int(10) NOT NULL default '0',
 | |
| `i2` int(10) NOT NULL default '0',
 | |
| PRIMARY KEY  (`i`)
 | |
| );
 | |
| DELETE FROM t1 USING t1 WHERE post='1';
 | |
| ERROR 42S22: Unknown column 'post' in 'WHERE'
 | |
| drop table t1;
 | |
| CREATE TABLE t1 (
 | |
| bool     char(0) default NULL,
 | |
| not_null varchar(20) binary NOT NULL default '',
 | |
| misc     integer not null,
 | |
| PRIMARY KEY  (not_null)
 | |
| ) ENGINE=MyISAM;
 | |
| INSERT INTO t1 VALUES (NULL,'a',4), (NULL,'b',5), (NULL,'c',6), (NULL,'d',7);
 | |
| select * from t1 where misc > 5 and bool is null;
 | |
| bool	not_null	misc
 | |
| NULL	c	6
 | |
| NULL	d	7
 | |
| delete   from t1 where misc > 5 and bool is null;
 | |
| select * from t1 where misc > 5 and bool is null;
 | |
| bool	not_null	misc
 | |
| select count(*) from t1;
 | |
| count(*)
 | |
| 2
 | |
| delete from t1 where 1 > 2;
 | |
| select count(*) from t1;
 | |
| count(*)
 | |
| 2
 | |
| delete from t1 where 3 > 2;
 | |
| select count(*) from t1;
 | |
| count(*)
 | |
| 0
 | |
| drop table t1;
 | |
| create table t1 (a int not null auto_increment primary key, b char(32));
 | |
| insert into t1 (b) values ('apple'), ('apple');
 | |
| select * from t1;
 | |
| a	b
 | |
| 1	apple
 | |
| 2	apple
 | |
| delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a;
 | |
| select * from t1;
 | |
| a	b
 | |
| 1	apple
 | |
| drop table t1;
 | |
| #
 | |
| # IGNORE option
 | |
| #
 | |
| create table t11 (a int NOT NULL, b int, primary key (a));
 | |
| create table t12 (a int NOT NULL, b int, primary key (a));
 | |
| create table t2 (a int NOT NULL, b int, primary key (a));
 | |
| insert into t11 values (0, 10),(1, 11),(2, 12);
 | |
| insert into t12 values (33, 10),(0, 11),(2, 12);
 | |
| insert into t2 values (1, 21),(2, 12),(3, 23);
 | |
| select * from t11;
 | |
| a	b
 | |
| 0	10
 | |
| 1	11
 | |
| 2	12
 | |
| select * from t12;
 | |
| a	b
 | |
| 33	10
 | |
| 0	11
 | |
| 2	12
 | |
| select * from t2;
 | |
| a	b
 | |
| 1	21
 | |
| 2	12
 | |
| 3	23
 | |
| delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
 | |
| ERROR 21000: Subquery returns more than 1 row
 | |
| select * from t11;
 | |
| a	b
 | |
| 0	10
 | |
| 1	11
 | |
| 2	12
 | |
| select * from t12;
 | |
| a	b
 | |
| 33	10
 | |
| 0	11
 | |
| 2	12
 | |
| explain delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	t12	ALL	PRIMARY	NULL	NULL	NULL	3	
 | |
| 1	PRIMARY	t11	eq_ref	PRIMARY	PRIMARY	4	test.t12.a	1	Using where
 | |
| 2	DEPENDENT SUBQUERY	t2	ALL	PRIMARY	NULL	NULL	NULL	3	Using where
 | |
| delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
 | |
| Warnings:
 | |
| Warning	1242	Subquery returns more than 1 row
 | |
| select * from t11;
 | |
| a	b
 | |
| 0	10
 | |
| 1	11
 | |
| select * from t12;
 | |
| a	b
 | |
| 33	10
 | |
| 0	11
 | |
| insert into t11 values (2, 12);
 | |
| delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
 | |
| ERROR 21000: Subquery returns more than 1 row
 | |
| select * from t11;
 | |
| a	b
 | |
| 0	10
 | |
| 1	11
 | |
| 2	12
 | |
| delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
 | |
| Warnings:
 | |
| Warning	1242	Subquery returns more than 1 row
 | |
| Warning	1242	Subquery returns more than 1 row
 | |
| select * from t11;
 | |
| a	b
 | |
| 0	10
 | |
| 1	11
 | |
| drop table t11, t12, t2;
 | |
| create table t1 (a int, b int, unique key (a), key (b));
 | |
| insert into t1 values (3, 3), (7, 7);
 | |
| delete t1 from t1 where a = 3;
 | |
| check table t1;
 | |
| Table	Op	Msg_type	Msg_text
 | |
| test.t1	check	status	OK
 | |
| select * from t1;
 | |
| a	b
 | |
| 7	7
 | |
| drop table t1;
 | |
| CREATE TABLE t1 ( a int PRIMARY KEY );
 | |
| DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
 | |
| INSERT INTO t1 VALUES (0),(1),(2);
 | |
| DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
 | |
| SELECT * FROM t1;
 | |
| a
 | |
| 0
 | |
| 2
 | |
| DROP TABLE t1;
 | |
| create table t1 (a int);
 | |
| delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
 | |
| delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
 | |
| drop table t1;
 | |
| create table t1(f1 int primary key);
 | |
| insert into t1 values (4),(3),(1),(2);
 | |
| delete from t1 where (@a:= f1) order by f1 limit 1;
 | |
| select @a;
 | |
| @a
 | |
| 1
 | |
| drop table t1;
 | |
| CREATE TABLE t1 (
 | |
| `date` date ,
 | |
| `time` time ,
 | |
| `seq` int(10) unsigned NOT NULL auto_increment,
 | |
| PRIMARY KEY  (`seq`),
 | |
| KEY `seq` (`seq`),
 | |
| KEY `time` (`time`),
 | |
| KEY `date` (`date`)
 | |
| );
 | |
| DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1;
 | |
| drop table t1;
 | |
| End of 4.1 tests
 | |
| CREATE TABLE t1 (a int not null,b int not null);
 | |
| CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
 | |
| CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
 | |
| insert into t1 values (1,1),(2,1),(1,3);
 | |
| insert into t2 values (1,1),(2,2),(3,3);
 | |
| insert into t3 values (1,1),(2,1),(1,3);
 | |
| select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
 | |
| a	b	a	b	a	b
 | |
| 1	1	1	1	1	1
 | |
| 2	1	2	2	2	1
 | |
| 1	3	1	1	1	3
 | |
| explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
 | |
| 1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a	1	Using index
 | |
| 1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b,test.t1.b	1	Using index
 | |
| delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
 | |
| select * from t3;
 | |
| a	b
 | |
| drop table t1,t2,t3;
 | |
| create table t1(a date not null);
 | |
| insert into t1 values (0);
 | |
| select * from t1 where a is null;
 | |
| a
 | |
| 0000-00-00
 | |
| delete from t1 where a is null;
 | |
| select count(*) from t1;
 | |
| count(*)
 | |
| 0
 | |
| drop table t1;
 | |
| CREATE TABLE t1 (a INT);
 | |
| INSERT INTO t1 VALUES (1);
 | |
| DELETE FROM t1 ORDER BY x;
 | |
| ERROR 42S22: Unknown column 'x' in 'ORDER BY'
 | |
| DELETE FROM t1 ORDER BY t2.x;
 | |
| ERROR 42S22: Unknown column 't2.x' in 'ORDER BY'
 | |
| DELETE FROM t1 ORDER BY (SELECT x);
 | |
| ERROR 42S22: Unknown column 'x' in 'SELECT'
 | |
| DROP TABLE t1;
 | |
| CREATE TABLE t1 (
 | |
| a INT
 | |
| );
 | |
| CREATE TABLE t2 (
 | |
| a INT
 | |
| );
 | |
| CREATE DATABASE db1;
 | |
| CREATE TABLE db1.t1 (
 | |
| a INT
 | |
| );
 | |
| INSERT INTO db1.t1 (a) SELECT * FROM t1;
 | |
| CREATE DATABASE db2;
 | |
| CREATE TABLE db2.t1 (
 | |
| a INT
 | |
| );
 | |
| INSERT INTO db2.t1 (a) SELECT * FROM t2;
 | |
| DELETE FROM t1 alias USING t1, t2 alias WHERE t1.a = alias.a;
 | |
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING t1, t2 alias WHERE t1.a = alias.a' at line 1
 | |
| DELETE FROM alias USING t1, t2 alias WHERE t1.a = alias.a;
 | |
| DELETE FROM t1, alias USING t1, t2 alias WHERE t1.a = alias.a;
 | |
| DELETE FROM t1, t2 USING t1, t2 alias WHERE t1.a = alias.a;
 | |
| ERROR 42S02: Unknown table 't2' in MULTI DELETE
 | |
| DELETE FROM db1.t1 alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
 | |
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a' at line 1
 | |
| DELETE FROM alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
 | |
| DELETE FROM db2.alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
 | |
| ERROR 42S02: Unknown table 'alias' in MULTI DELETE
 | |
| DELETE FROM t1 USING t1 WHERE a = 1;
 | |
| SELECT * FROM t1;
 | |
| a
 | |
| DELETE FROM t1 alias USING t1 alias WHERE a = 2;
 | |
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING t1 alias WHERE a = 2' at line 1
 | |
| SELECT * FROM t1;
 | |
| a
 | |
| DROP TABLE t1, t2;
 | |
| DROP DATABASE db1;
 | |
| DROP DATABASE db2;
 | |
| CREATE FUNCTION f1() RETURNS INT RETURN 1;
 | |
| CREATE TABLE t1 (a INT);
 | |
| INSERT INTO t1 VALUES (0);
 | |
| DELETE FROM t1 ORDER BY (f1(10)) LIMIT 1;
 | |
| ERROR 42000: Incorrect number of arguments for FUNCTION test.f1; expected 0, got 1
 | |
| DROP TABLE t1;
 | |
| DROP FUNCTION f1;
 | |
| #
 | |
| # Bug #49552 : sql_buffer_result cause crash + not found records 
 | |
| #   in multitable delete/subquery
 | |
| #
 | |
| CREATE TABLE t1(a INT);
 | |
| INSERT INTO t1 VALUES (1),(2),(3);
 | |
| SET SESSION SQL_BUFFER_RESULT=1;
 | |
| DELETE t1 FROM (SELECT SUM(a) a FROM t1) x,t1;
 | |
| SET SESSION SQL_BUFFER_RESULT=DEFAULT;
 | |
| SELECT * FROM t1;
 | |
| a
 | |
| DROP TABLE t1;
 | |
| End of 5.0 tests
 | |
| DROP DATABASE IF EXISTS db1;
 | |
| DROP DATABASE IF EXISTS db2;
 | |
| DROP DATABASE IF EXISTS db3;
 | |
| DROP DATABASE IF EXISTS db4;
 | |
| DROP TABLE IF EXISTS t1, t2;
 | |
| DROP PROCEDURE IF EXISTS count;
 | |
| USE test;
 | |
| CREATE DATABASE db1;
 | |
| CREATE DATABASE db2;
 | |
| CREATE TABLE db1.t1 (a INT, b INT);
 | |
| INSERT INTO db1.t1 VALUES (1,1),(2,2),(3,3);
 | |
| CREATE TABLE db1.t2 AS SELECT * FROM db1.t1;
 | |
| CREATE TABLE db2.t1 AS SELECT * FROM db1.t2;
 | |
| CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
 | |
| CREATE TABLE t1 AS SELECT * FROM db2.t2;
 | |
| CREATE TABLE t2 AS SELECT * FROM t1;
 | |
| CREATE PROCEDURE count_rows()
 | |
| BEGIN
 | |
| SELECT COUNT(*) AS "COUNT(db1.t1)" FROM db1.t1;
 | |
| SELECT COUNT(*) AS "COUNT(db1.t2)" FROM db1.t2;
 | |
| SELECT COUNT(*) AS "COUNT(db2.t1)" FROM db2.t1;
 | |
| SELECT COUNT(*) AS "COUNT(db2.t2)" FROM db2.t2;
 | |
| SELECT COUNT(*) AS "COUNT(test.t1)" FROM test.t1;
 | |
| SELECT COUNT(*) AS "COUNT(test.t2)" FROM test.t2;
 | |
| END|
 | |
| CREATE DATABASE db3;
 | |
| USE db3;
 | |
| DROP DATABASE db3;
 | |
| SELECT * FROM t1;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1,a2 FROM db1.t1, db2.t2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1,a2 FROM db1.t1, db2.t2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE FROM a1,a2 USING db1.t1, db2.t2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE FROM a1,a2 USING db1.t1, db2.t2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1 FROM db1.a1, db2.t2 AS a1;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE a1 FROM a1, db1.t1 AS a1;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE t1 FROM db1.t1, db2.t1 AS a1;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
 | |
| ERROR 3D000: No database selected
 | |
| DELETE t1 FROM db1.t1, db2.t1;
 | |
| ERROR 3D000: No database selected
 | |
| USE test;
 | |
| DELETE a1,a2 FROM db1.t1, db2.t2;
 | |
| ERROR 42S02: Unknown table 'a1' in MULTI DELETE
 | |
| DELETE a1,a2 FROM db1.t1, db2.t2;
 | |
| ERROR 42S02: Unknown table 'a1' in MULTI DELETE
 | |
| DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
 | |
| ERROR 42S02: Unknown table 'a2' in MULTI DELETE
 | |
| DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
 | |
| ERROR 42S02: Unknown table 'a1' in MULTI DELETE
 | |
| DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 42S02: Table 'db3.t1' doesn't exist
 | |
| DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 42S02: Table 'db3.t1' doesn't exist
 | |
| DELETE FROM a1,a2 USING db1.t1, db2.t2;
 | |
| ERROR 42S02: Unknown table 'a1' in MULTI DELETE
 | |
| DELETE FROM a1,a2 USING db1.t1, db2.t2;
 | |
| ERROR 42S02: Unknown table 'a1' in MULTI DELETE
 | |
| DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
 | |
| ERROR 42S02: Unknown table 'a2' in MULTI DELETE
 | |
| DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
 | |
| ERROR 42S02: Unknown table 'a1' in MULTI DELETE
 | |
| DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 42S02: Table 'db3.t1' doesn't exist
 | |
| DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 | |
| ERROR 42S02: Table 'db3.t1' doesn't exist
 | |
| DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
 | |
| ERROR 42000: Not unique table/alias: 'a1'
 | |
| DELETE a1 FROM db1.a1, db2.t2 AS a1;
 | |
| ERROR 42S02: Table 'db1.a1' doesn't exist
 | |
| DELETE a1 FROM a1, db1.t1 AS a1;
 | |
| ERROR 42000: Not unique table/alias: 'a1'
 | |
| DELETE t1 FROM db1.t1, db2.t1 AS a1;
 | |
| ERROR 42S02: Unknown table 't1' in MULTI DELETE
 | |
| DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
 | |
| ERROR 42S02: Unknown table 't1' in MULTI DELETE
 | |
| DELETE t1 FROM db1.t1, db2.t1;
 | |
| ERROR 42S02: Unknown table 't1' in MULTI DELETE
 | |
| DELETE t1 FROM db1.t2 AS t1, db2.t2 AS t2 WHERE t2.a = 1 AND t1.a = t2.a;
 | |
| SELECT ROW_COUNT();
 | |
| ROW_COUNT()
 | |
| 1
 | |
| CALL count_rows();
 | |
| COUNT(db1.t1)
 | |
| 3
 | |
| COUNT(db1.t2)
 | |
| 2
 | |
| COUNT(db2.t1)
 | |
| 3
 | |
| COUNT(db2.t2)
 | |
| 3
 | |
| COUNT(test.t1)
 | |
| 3
 | |
| COUNT(test.t2)
 | |
| 3
 | |
| DELETE a1, a2 FROM db2.t1 AS a1, t2 AS a2 WHERE a1.a = 2 AND a2.a = 2;
 | |
| SELECT ROW_COUNT();
 | |
| ROW_COUNT()
 | |
| 2
 | |
| CALL count_rows();
 | |
| COUNT(db1.t1)
 | |
| 3
 | |
| COUNT(db1.t2)
 | |
| 2
 | |
| COUNT(db2.t1)
 | |
| 2
 | |
| COUNT(db2.t2)
 | |
| 3
 | |
| COUNT(test.t1)
 | |
| 3
 | |
| COUNT(test.t2)
 | |
| 2
 | |
| DROP DATABASE db1;
 | |
| DROP DATABASE db2;
 | |
| DROP PROCEDURE count_rows;
 | |
| DROP TABLE t1, t2;
 | |
| #
 | |
| # Bug#46958: Assertion in Diagnostics_area::set_ok_status, trigger, 
 | |
| # merge table
 | |
| #
 | |
| CREATE TABLE t1 ( a INT );
 | |
| CREATE TABLE t2 ( a INT );
 | |
| CREATE TABLE t3 ( a INT );
 | |
| INSERT INTO t1 VALUES (1), (2);
 | |
| INSERT INTO t2 VALUES (1), (2);
 | |
| INSERT INTO t3 VALUES (1), (2);
 | |
| CREATE TRIGGER tr1 BEFORE DELETE ON t2
 | |
| FOR EACH ROW INSERT INTO no_such_table VALUES (1);
 | |
| DELETE t1, t2, t3 FROM t1, t2, t3;
 | |
| ERROR 42S02: Table 'test.no_such_table' doesn't exist
 | |
| SELECT * FROM t1;
 | |
| a
 | |
| SELECT * FROM t2;
 | |
| a
 | |
| 1
 | |
| 2
 | |
| SELECT * FROM t3;
 | |
| a
 | |
| 1
 | |
| 2
 | |
| DROP TABLE t1, t2, t3;
 | |
| CREATE TABLE t1 ( a INT );
 | |
| CREATE TABLE t2 ( a INT );
 | |
| CREATE TABLE t3 ( a INT );
 | |
| INSERT INTO t1 VALUES (1), (2);
 | |
| INSERT INTO t2 VALUES (1), (2);
 | |
| INSERT INTO t3 VALUES (1), (2);
 | |
| CREATE TRIGGER tr1 AFTER DELETE ON t2
 | |
| FOR EACH ROW INSERT INTO no_such_table VALUES (1);
 | |
| DELETE t1, t2, t3 FROM t1, t2, t3;
 | |
| ERROR 42S02: Table 'test.no_such_table' doesn't exist
 | |
| SELECT * FROM t1;
 | |
| a
 | |
| SELECT * FROM t2;
 | |
| a
 | |
| 2
 | |
| SELECT * FROM t3;
 | |
| a
 | |
| 1
 | |
| 2
 | |
| DROP TABLE t1, t2, t3;
 | |
| #
 | |
| # Bug #46425 crash in Diagnostics_area::set_ok_status, 
 | |
| #            empty statement, DELETE IGNORE
 | |
| #
 | |
| CREATE table t1 (i INTEGER);
 | |
| INSERT INTO t1 VALUES (1);
 | |
| CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW 
 | |
| BEGIN 
 | |
| INSERT INTO t1 SELECT * FROM t1 AS A;
 | |
| END |
 | |
| DELETE IGNORE FROM t1;
 | |
| ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
 | |
| DROP TABLE t1;
 | |
| #
 | |
| # Bug #53450: Crash/assertion
 | |
| #    "virtual int ha_myisam::index_first(uchar*)") at assert.c:81
 | |
| #
 | |
| CREATE TABLE t1 (a INT,    b INT,    c INT,
 | |
| INDEX(a), INDEX(b), INDEX(c));
 | |
| INSERT INTO t1 VALUES (1,2,3), (4,5,6), (7,8,9);
 | |
| DELETE FROM t1 WHERE a = 10 OR b = 20 ORDER BY c LIMIT 1;
 | |
| DROP TABLE t1;
 | |
| #
 | |
| # Bug #53034: Multiple-table DELETE statements not accepting
 | |
| #             "Access compatibility" syntax
 | |
| #
 | |
| CREATE TABLE t1 (id INT);
 | |
| CREATE TABLE t2 LIKE t1;
 | |
| CREATE TABLE t3 LIKE t1;
 | |
| DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a;
 | |
| DROP TABLE t1, t2, t3;
 | |
| End of 5.1 tests
 | |
| #
 | |
| # Bug#51099 Assertion in mysql_multi_delete_prepare()
 | |
| #
 | |
| DROP TABLE IF EXISTS t1, t2;
 | |
| DROP VIEW IF EXISTS v1, v2;
 | |
| CREATE TABLE t1(a INT);
 | |
| CREATE TABLE t2(b INT);
 | |
| CREATE VIEW v1 AS SELECT a, b FROM t1, t2;
 | |
| CREATE VIEW v2 AS SELECT a FROM v1;
 | |
| DELETE FROM v2;
 | |
| ERROR HY000: Can not delete from join view 'test.v2'
 | |
| DELETE v2 FROM v2;
 | |
| ERROR HY000: Can not delete from join view 'test.v2'
 | |
| DROP VIEW v2, v1;
 | |
| DROP TABLE t1, t2;
 | |
| End of 5.5 tests
 | |
| #
 | |
| # MDEV-30586: DELETE with WHERE containing nested subquery
 | |
| #             with set function aggregated in outer subquery
 | |
| #
 | |
| create table t1 (a int);
 | |
| insert into t1 values (3), (7), (1);
 | |
| create table t2 (b int);
 | |
| insert into t2 values (2), (1), (4), (7);
 | |
| create table t3 (a int, b int);
 | |
| insert into t3 values (2,10), (7,30), (2,30), (1,10), (7,40);
 | |
| select * from t1
 | |
| where t1.a in (select t3.a from t3 group by t3.a
 | |
| having t3.a > any (select t2.b from t2
 | |
| where t2.b*10 < sum(t3.b)));
 | |
| a
 | |
| 7
 | |
| delete from t1
 | |
| where t1.a in (select t3.a from t3 group by t3.a
 | |
| having t3.a > any (select t2.b from t2
 | |
| where t2.b*10 < sum(t3.b)));
 | |
| select * from t1
 | |
| where t1.a in (select t3.a from t3 group by t3.a
 | |
| having t3.a > any (select t2.b from t2
 | |
| where t2.b*10 < sum(t3.b)));
 | |
| a
 | |
| update t1 set t1.a=t1.a+10
 | |
| where t1.a in (select t3.a from t3 group by t3.a
 | |
| having t3.a > any (select t2.b from t2
 | |
| where t2.b*10 < sum(t3.b)));
 | |
| drop table t1,t2,t3;
 | |
| End of 10.4 tests
 | |
| #
 | |
| # MDEV-26459: Assertion `block_size <= 0xFFFFFFFFL' failed
 | |
| # in calculate_block_sizes for 10.7 only
 | |
| #
 | |
| SET @sort_buffer_size_save= @@sort_buffer_size;
 | |
| SET sort_buffer_size=1125899906842624;
 | |
| CREATE TABLE t1 (a INT,b CHAR,KEY(a,b));
 | |
| DELETE a1 FROM t1 AS a1,t1 AS a2 WHERE a1.a=a2.a;
 | |
| DROP TABLE t1;
 | |
| SET sort_buffer_size= @sort_buffer_size_save;
 | |
| # End of 10.11 tests
 | |
| #
 | |
| # MDEV-29428: DELETE with ORDER BY without LIMIT clause
 | |
| #
 | |
| create table t1 (c1 integer, c2 integer, c3 integer);
 | |
| insert into t1 values
 | |
| (1,1,1), (1,2,2), (1,3,3), (2,1,4), (2,2,5), (2,3,6), (2,4,7), (2,5,8);
 | |
| create temporary table t select * from t1;
 | |
| explain delete from t1 order by c2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	8	Deleting all rows
 | |
| delete from t1 order by c2;
 | |
| select *from t1;
 | |
| c1	c2	c3
 | |
| delete from t1;
 | |
| insert into t1 select * from t;
 | |
| explain delete from t1
 | |
| where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
 | |
| 1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	8	Using where; FirstMatch(t1)
 | |
| delete from t1
 | |
| where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
 | |
| select *from t1;
 | |
| c1	c2	c3
 | |
| 1	1	1
 | |
| 1	2	2
 | |
| 2	1	4
 | |
| 2	2	5
 | |
| delete from t1;
 | |
| insert into t1 select * from t;
 | |
| explain delete from t1
 | |
| where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3
 | |
| order by c2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
 | |
| 1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	8	Using where; FirstMatch(t1)
 | |
| delete from t1
 | |
| where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3
 | |
| order by c2;
 | |
| select *from t1;
 | |
| c1	c2	c3
 | |
| 1	1	1
 | |
| 1	2	2
 | |
| 2	1	4
 | |
| 2	2	5
 | |
| drop table t1;
 | |
| End of 11.1 tests
 | |
| #
 | |
| # MDEV-33988 DELETE to support table aliases
 | |
| #
 | |
| CREATE TABLE t1 (c1 INT);
 | |
| INSERT INTO t1 VALUES (1), (2);
 | |
| SELECT * FROM t1;
 | |
| c1
 | |
| 1
 | |
| 2
 | |
| DELETE FROM t1 AS a1 WHERE a1.c1 = 2;
 | |
| SELECT * FROM t1;
 | |
| c1
 | |
| 1
 | |
| CREATE TABLE t2 (c2 INT);
 | |
| INSERT INTO t2 VALUES (1), (2);
 | |
| SELECT * FROM t2;
 | |
| c2
 | |
| 1
 | |
| 2
 | |
| DELETE FROM t2 a2 WHERE NOT EXISTS (SELECT * FROM t1 WHERE t1.c1 = a2.c2);
 | |
| SELECT * FROM t2;
 | |
| c2
 | |
| 1
 | |
| DROP TABLE t1, t2;
 | |
| End of 11.6 tests
 | |
| #
 | |
| # MDEV-25008: Delete query gets stuck on mariadb, same query works
 | |
| #             on MySQL 8.0.21
 | |
| #
 | |
| CREATE TABLE t1 (
 | |
| id int NOT NULL PRIMARY KEY,
 | |
| item_id varchar(100),
 | |
| seller_name varchar(400),
 | |
| variant varchar(400),
 | |
| FULLTEXT KEY t1_serial_IDX (item_id,seller_name,variant)
 | |
| )engine=innodb;
 | |
| insert into t1 select seq,seq,seq,seq from seq_1_to_10000;
 | |
| explain
 | |
| DELETE FROM t1 WHERE id NOT IN
 | |
| (SELECT m FROM (SELECT max(id) m FROM t1 GROUP BY item_id, seller_name, variant) AS innertable);
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	#	Using where
 | |
| 2	MATERIALIZED	<derived3>	ALL	NULL	NULL	NULL	NULL	#	
 | |
| 3	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	#	Using temporary; Using filesort
 | |
| drop table t1;
 | |
| create table t1 (a int primary key, b int, c int, key(b));
 | |
| insert into t1 select seq, seq, seq from seq_1_to_20000;
 | |
| create table t2 as select * from t1;
 | |
| explain delete from t1  where    b <= 2 and a not in (select b from t2);
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	t1	range	b	b	5	NULL	2	Using where
 | |
| 2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	20000	Using where
 | |
| explain delete from t1  where    b <= 3 and a not in (select b from t2);
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	PRIMARY	t1	range	b	b	5	NULL	3	Using where
 | |
| 2	MATERIALIZED	t2	ALL	NULL	NULL	NULL	NULL	20000	
 | |
| drop table t1, t2;
 | |
| # End of 11.7 tests
 | |
| #
 | |
| # MDEV-30469: Add support of ORDER BY and LIMIT to multidelete query.
 | |
| #
 | |
| # Check that limits work with hints
 | |
| create table t2 (id int, index xid(id));
 | |
| insert into t2 values (1),(10),(2),(9),(3),(8);
 | |
| DELETE t2.* FROM t2 use index(xid) ORDER BY (id) LIMIT 2;
 | |
| select * from t2 ORDER BY (id);
 | |
| id
 | |
| 3
 | |
| 8
 | |
| 9
 | |
| 10
 | |
| DELETE t2.* FROM t2 use index(xid) ORDER BY (id) DESC LIMIT 3;
 | |
| select * from t2;
 | |
| id
 | |
| 3
 | |
| # Check some useless syntax
 | |
| DELETE t2.* FROM t2 FORCE INDEX FOR GROUP BY (xid) ORDER BY (id) LIMIT 1;
 | |
| drop table t2;
 | |
| # Check that hints work with limit
 | |
| create table t2 (id int primary key, index xid(id));
 | |
| insert into t2 values (1),(10),(2),(9),(3),(8);
 | |
| # default primary index
 | |
| explain
 | |
| DELETE t2.* FROM t2 ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	PRIMARY	4	NULL	2	
 | |
| # make it use other undex
 | |
| explain
 | |
| DELETE t2.* FROM t2 use index(xid) ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	xid	4	NULL	2	
 | |
| explain
 | |
| DELETE t2.* FROM t2 force index(xid) ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	xid	4	NULL	2	
 | |
| # prohibit primary index
 | |
| explain
 | |
| DELETE t2.* FROM t2 ignore index(primary) ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	xid	4	NULL	2	
 | |
| drop table t2;
 | |
| # Check that limits work with hints & PS protocol
 | |
| create table t2 (id int, index xid(id));
 | |
| insert into t2 values (1),(10),(2),(9),(3),(8);
 | |
| prepare stmt from
 | |
| "DELETE t2.* FROM t2 use index(xid) ORDER BY (id) LIMIT ?";
 | |
| set @lim= 2;
 | |
| execute stmt using @lim;
 | |
| select * from t2 ORDER BY (id);
 | |
| id
 | |
| 3
 | |
| 8
 | |
| 9
 | |
| 10
 | |
| set @lim= 1;
 | |
| execute stmt using @lim;
 | |
| select * from t2 ORDER BY (id);
 | |
| id
 | |
| 8
 | |
| 9
 | |
| 10
 | |
| set @lim= 3;
 | |
| execute stmt using @lim;
 | |
| select * from t2 ORDER BY (id);
 | |
| id
 | |
| drop table t2;
 | |
| # Check that hints work with limit in normal DELETE syntax
 | |
| create table t2 (id int primary key, index xid(id));
 | |
| insert into t2 values (1),(10),(2),(9),(3),(8);
 | |
| # default primary index
 | |
| explain
 | |
| DELETE FROM t2 ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	PRIMARY	4	NULL	2	
 | |
| # make it use other undex
 | |
| explain
 | |
| DELETE FROM t2 use index(xid) ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	xid	4	NULL	2	
 | |
| explain
 | |
| DELETE FROM t2 force index(xid) ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	xid	4	NULL	2	
 | |
| # prohibit primary index
 | |
| explain
 | |
| DELETE FROM t2 ignore index(primary) ORDER BY (id) LIMIT 2;
 | |
| id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 | |
| 1	SIMPLE	t2	index	NULL	xid	4	NULL	2	
 | |
| # should issue warnings because we can not switch it internally
 | |
| # to multiupdate due to RETURNING
 | |
| DELETE FROM t2 ignore index(primary) ORDER BY (id) LIMIT 2 RETURNING id;
 | |
| id
 | |
| 1
 | |
| 2
 | |
| Warnings:
 | |
| Warning	4207	Index hints are ignored because they are incompatible with RETURNING clause
 | |
| drop table t2;
 | |
| #
 | |
| # End of 11.4 test
 | |
| #
 | 
