[Commits] a735c1a: MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statements
by IgorBabaev 23 Mar '23
by IgorBabaev 23 Mar '23
23 Mar '23
revision-id: a735c1a37ee997624eba5b8cf3b10da76f61dfc7 (mariadb-10.4.27-113-ga735c1a)
parent(s): ccec9b1de95a66b7597bc30e0a60bd61866f225d
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-22 20:12:59 -0700
message:
MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statements
EXPLAIN EXTENDED for an UPDATE/DELETE/INSERT/REPLACE statement did not
produce the warning containing the text representation of the query
obtained after the optimization phase. Such warning was produced for
SELECT statements, but not for DML statements.
The patch fixes this defect of EXPLAIN EXTENDED for DML statements.
---
mysql-test/include/explain_non_select.inc | 16 +
mysql-test/main/explain_non_select.result | 4 +
mysql-test/main/multi_update.result | 2 +-
mysql-test/main/multi_update.test | 2 +-
.../main/myisam_explain_non_select_all.result | 193 ++++++++++++
mysql-test/main/opt_trace.result | 2 +-
mysql-test/main/ps.result | 4 +
sql/sql_delete.cc | 2 +
sql/sql_explain.cc | 19 +-
sql/sql_explain.h | 2 +-
sql/sql_insert.cc | 6 +-
sql/sql_lex.cc | 2 +
sql/sql_lex.h | 6 +
sql/sql_parse.cc | 20 +-
sql/sql_select.cc | 326 ++++++++++++++++++---
sql/sql_update.cc | 10 +-
sql/table.h | 2 +
17 files changed, 561 insertions(+), 57 deletions(-)
diff --git a/mysql-test/include/explain_non_select.inc b/mysql-test/include/explain_non_select.inc
index d22310c..bd0962d 100644
--- a/mysql-test/include/explain_non_select.inc
+++ b/mysql-test/include/explain_non_select.inc
@@ -788,6 +788,22 @@ INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
DROP TABLE t1;
+--echo #75
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+--let $query = INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #76
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+CREATE TABLE t2 (a INT, b INT);
+INSERT INTO t2 VALUES (1,10), (3,10), (7,11), (3,11);
+--let $query = INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+--source include/explain_utils.inc
+DROP TABLE t1,t2;
+
--echo #
--echo # Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH
--echo # EXPLAIN UPDATE/DEL/INS
diff --git a/mysql-test/main/explain_non_select.result b/mysql-test/main/explain_non_select.result
index 111b4c8..d60f10f 100644
--- a/mysql-test/main/explain_non_select.result
+++ b/mysql-test/main/explain_non_select.result
@@ -157,9 +157,13 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
explain extended update t2 set b=3 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`b` = 3 where `test`.`t2`.`a` in (3,4)
explain extended delete from t2 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`a` in (3,4)
drop table t1,t2;
#
# Check the special case where partition pruning removed all partitions
diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result
index d6cf9ba..222c592 100644
--- a/mysql-test/main/multi_update.result
+++ b/mysql-test/main/multi_update.result
@@ -1253,7 +1253,7 @@ EXPLAIN
DROP TABLES t1, t2;
# End of 10.3 tests
#
-# MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in
+# MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
#
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
insert into t1 values
diff --git a/mysql-test/main/multi_update.test b/mysql-test/main/multi_update.test
index 48e6250..329394e 100644
--- a/mysql-test/main/multi_update.test
+++ b/mysql-test/main/multi_update.test
@@ -1134,7 +1134,7 @@ DROP TABLES t1, t2;
--echo # End of 10.3 tests
--echo #
---echo # MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in
+--echo # MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
--echo #
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 7f24cb4..3ca9629 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -17,6 +17,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` < 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -60,6 +62,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -103,6 +107,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE a = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t1` where `test`.`t1`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -150,6 +156,8 @@ EXPLAIN EXTENDED UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 update `test`.`t1` join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -200,6 +208,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -248,6 +258,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(1,<exists>(/* select#2 */ select 1 from `test`.`t2` where `test`.`t2`.`b` < 3 and 1))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -300,6 +312,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`b` from `test`.`t2` where `test`.`t1`.`a` < 3 and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -353,6 +366,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t2`.`b` < 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -405,6 +420,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -457,6 +474,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -511,6 +530,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` > 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -555,6 +576,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a > 1 LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 1 limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -598,6 +621,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` where 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -638,6 +663,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t1` where 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -678,6 +705,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a = 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` = 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 5
@@ -719,6 +748,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 5
@@ -758,6 +789,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -797,6 +830,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -840,6 +875,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where @a:=`test`.`t1`.`a` order by `test`.`t1`.`a` limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -884,6 +921,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -941,6 +980,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 100.00
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1`,`test`.`t2`,`test`.`t3` using `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a2` = `test`.`t1`.`a1` and `test`.`t3`.`a3` = `test`.`t2`.`b2` and `test`.`t3`.`b3` = `test`.`t1`.`b1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 13
@@ -993,6 +1034,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where <cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1043,6 +1086,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1088,6 +1133,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1132,6 +1179,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`i` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -1175,6 +1224,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL 5 NULL Deleting all rows
+Warnings:
+Note 1003 delete from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -1221,6 +1272,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1267,6 +1320,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 insert into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1311,6 +1366,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 replace into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1351,6 +1408,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1`(i) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -1374,6 +1433,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 replace into `test`.`t1`(i) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -1402,6 +1463,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1447,6 +1510,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1500,6 +1565,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1554,6 +1621,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1603,6 +1672,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1657,6 +1728,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1712,6 +1785,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1765,6 +1840,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1812,6 +1889,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1866,6 +1945,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 6 NULL 5 100.00
+Warnings:
+Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1915,6 +1996,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1963,6 +2046,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -2017,6 +2102,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2072,6 +2159,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2122,6 +2211,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2176,6 +2267,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2231,6 +2324,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`i` = 123 where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2284,6 +2379,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -2332,6 +2429,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2387,6 +2486,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 6 NULL 5 100.00 Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2439,6 +2540,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`c2` = 0 where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2485,6 +2588,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2534,6 +2639,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 10 where `test`.`t1`.`a` > 34
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -2581,6 +2688,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` set NULL = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2624,6 +2733,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 W
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set NULL = 10 where `test`.`t1`.`c3` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2676,6 +2787,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`f2` = (/* select#2 */ select max(`test`.`t2`.`f4`) from `test`.`t2` where `test`.`t2`.`f3` = `test`.`t1`.`f1`)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2747,6 +2859,8 @@ EXPLAIN EXTENDED UPDATE v1 SET a = 1 WHERE a > 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` > 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -2792,6 +2906,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` = `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -2841,6 +2957,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM v1 WHERE a < 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where `test`.`t1`.`a` < 4
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -2892,6 +3010,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2943,6 +3063,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2987,6 +3109,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1`(x) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -3027,6 +3151,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 0 0.00 Const row not found
+Warnings:
+Note 1003 insert into `test`.`t2`(x) /* select#1 */ select NULL AS `a` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3084,6 +3210,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0)))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3140,6 +3268,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#3 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` set `test`.`t1`.`a` = 10 where 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3198,6 +3328,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 3 100.00
4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#4 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` set `test`.`t1`.`a` = 10 where 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3248,6 +3380,8 @@ JOIN t1 AS a12 ON a12.c1 = a11.c1
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
DROP TABLE t1, t2, t3;
#73
CREATE TABLE t1 (id INT);
@@ -3276,6 +3410,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -3315,6 +3451,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10 order by `test`.`t1`.`a` + 20
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -3341,6 +3479,61 @@ Handler_read_key 4
Sort_range 1
DROP TABLE t1;
+#75
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+#
+# query: INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+# select:
+#
+EXPLAIN INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows Extra
+1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1` values (3,10),(7,11),(3,11) on duplicate key update `test`.`t1`.`id` = last_insert_id(`test`.`t1`.`id`)
+# Status of EXPLAIN EXTENDED query
+Variable_name Value
+Handler_read_key 4
+# Status of testing query execution:
+Variable_name Value
+Handler_read_key 4
+Handler_read_rnd 1
+Handler_write 3
+
+DROP TABLE t1;
+#76
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+CREATE TABLE t2 (a INT, b INT);
+INSERT INTO t2 VALUES (1,10), (3,10), (7,11), (3,11);
+#
+# query: INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+# select:
+#
+EXPLAIN INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 4
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00
+Warnings:
+Note 1003 insert into `test`.`t1` select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` on duplicate key update `test`.`t1`.`id` = last_insert_id(`test`.`t1`.`id`)
+# Status of EXPLAIN EXTENDED query
+Variable_name Value
+Handler_read_key 7
+# Status of testing query execution:
+Variable_name Value
+Handler_read_key 7
+Handler_read_rnd 1
+Handler_read_rnd_next 5
+Handler_write 4
+
+DROP TABLE t1,t2;
#
# Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH
# EXPLAIN UPDATE/DEL/INS
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index a343d59..a8b391f 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -3766,7 +3766,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"select_id": 1,
"steps": [
{
- "expanded_query": "select NULL AS `NULL` from t0 join t1 where t0.a = t1.a and t1.a < 3"
+ "expanded_query": "delete from t0,t1 using t0 join t1 where t0.a = t1.a and t1.a < 3"
}
]
}
diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result
index 673b18c..408b1ec 100644
--- a/mysql-test/main/ps.result
+++ b/mysql-test/main/ps.result
@@ -5566,11 +5566,15 @@ EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 F
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 )";
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2, t3;
#
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1b3fa30..776dfff 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1084,6 +1084,8 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
select_lex->fix_prepare_information(thd, conds, &fake_conds);
+ if (!thd->lex->upd_del_where)
+ thd->lex->upd_del_where= *conds;
DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 70e3009..6b76db8 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -161,7 +161,7 @@ void Explain_query::query_plan_ready()
Send EXPLAIN output to the client.
*/
-int Explain_query::send_explain(THD *thd)
+int Explain_query::send_explain(THD *thd, bool extended)
{
select_result *result;
LEX *lex= thd->lex;
@@ -174,8 +174,22 @@ int Explain_query::send_explain(THD *thd)
if (thd->lex->explain_json)
print_explain_json(result, thd->lex->analyze_stmt);
else
+ {
res= print_explain(result, lex->describe, thd->lex->analyze_stmt);
-
+ if (extended)
+ {
+ char buff[1024];
+ String str(buff,(uint32) sizeof(buff), system_charset_info);
+ str.length(0);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str.c_ptr_safe());
+ }
+ }
if (res)
result->abort_result_set();
else
@@ -185,6 +199,7 @@ int Explain_query::send_explain(THD *thd)
}
+
/*
The main entry point to print EXPLAIN of the entire query
*/
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 7b5042b..3add404 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -474,7 +474,7 @@ class Explain_query : public Sql_alloc
bool is_analyze);
/* Send tabular EXPLAIN to the client */
- int send_explain(THD *thd);
+ int send_explain(THD *thd, bool extended);
/* Return tabular EXPLAIN output as a text string */
bool print_explain_str(THD *thd, String *out_str, bool is_analyze);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index f31c9ea..9a76061 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -827,7 +827,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
save_insert_query_plan(thd, table_list);
if (thd->lex->describe)
{
- retval= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ retval= thd->lex->explain->send_explain(thd, extended);
goto abort;
}
@@ -1250,7 +1251,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
goto abort;
if (thd->lex->analyze_stmt)
{
- retval= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ retval= thd->lex->explain->send_explain(thd, extended);
goto abort;
}
DBUG_PRINT("info", ("touched: %llu copied: %llu updated: %llu deleted: %llu",
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index e14d9f7..e7689a9 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -780,6 +780,8 @@ void LEX::start(THD *thd_arg)
frame_bottom_bound= NULL;
win_spec= NULL;
+ upd_del_where= NULL;
+
vers_conditions.empty();
period_conditions.empty();
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 769b1750..6170637 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1417,6 +1417,10 @@ class st_select_lex: public st_select_lex_node
}
bool setup_ref_array(THD *thd, uint order_group_num);
void print(THD *thd, String *str, enum_query_type query_type);
+ void print_item_list(THD *thd, String *str, enum_query_type query_type);
+ void print_set_clause(THD *thd, String *str, enum_query_type query_type);
+ void print_on_duplicate_key_clause(THD *thd, String *str,
+ enum_query_type query_type);
static void print_order(String *str,
ORDER *order,
enum_query_type query_type);
@@ -3493,6 +3497,8 @@ struct LEX: public Query_tables_list
Window_frame_bound *frame_bottom_bound;
Window_spec *win_spec;
+ Item *upd_del_where;
+
/* System Versioning */
vers_select_conds_t vers_conditions;
vers_select_conds_t period_conditions;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 1f1962a..c495ae2 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4744,7 +4744,10 @@ mysql_execute_command(THD *thd)
}
if (!res && (explain || lex->analyze_stmt))
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
/* revert changes for SP */
MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func());
@@ -4813,7 +4816,10 @@ mysql_execute_command(THD *thd)
if (thd->lex->analyze_stmt || thd->lex->describe)
{
if (!res)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
delete sel_result;
@@ -4875,7 +4881,10 @@ mysql_execute_command(THD *thd)
else
{
if (lex->describe || lex->analyze_stmt)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
multi_delete_error:
delete result;
@@ -6463,7 +6472,10 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
thd->protocol= save_protocol;
}
if (!res)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
}
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2c12d1c..c4fc2d1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -305,6 +305,9 @@ static Item **get_sargable_cond(JOIN *join, TABLE *table);
bool is_eq_cond_injected_for_split_opt(Item_func_eq *eq_item);
+void print_list_item(String *str, List_item *list,
+ enum_query_type query_type);
+
#ifndef DBUG_OFF
/*
@@ -27981,6 +27984,162 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str,
}
}
+enum explainable_cmd_type
+{
+ SELECT_CMD, INSERT_CMD, REPLACE_CMD, UPDATE_CMD, DELETE_CMD, NO_CMD
+};
+
+static
+const char * const explainable_cmd_name []=
+{
+ "select ",
+ "insert ",
+ "replace ",
+ "update ",
+ "delete ",
+};
+
+static
+char const *get_explainable_cmd_name(enum explainable_cmd_type cmd)
+{
+ return explainable_cmd_name[cmd];
+}
+
+static
+enum explainable_cmd_type get_explainable_cmd_type(THD *thd)
+{
+ switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ return SELECT_CMD;
+ case SQLCOM_INSERT:
+ case SQLCOM_INSERT_SELECT:
+ return INSERT_CMD;
+ case SQLCOM_REPLACE:
+ case SQLCOM_REPLACE_SELECT:
+ return REPLACE_CMD;
+ case SQLCOM_UPDATE:
+ case SQLCOM_UPDATE_MULTI:
+ return UPDATE_CMD;
+ case SQLCOM_DELETE:
+ case SQLCOM_DELETE_MULTI:
+ return DELETE_CMD;
+ default:
+ return SELECT_CMD;
+ }
+}
+
+
+void TABLE_LIST::print_leaf_tables(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ if (merge_underlying_list)
+ {
+ for (TABLE_LIST *tbl= merge_underlying_list; tbl; tbl= tbl->next_local)
+ tbl->print_leaf_tables(thd, str, query_type);
+ }
+ else
+ print(thd, 0, str, query_type);
+}
+
+
+void st_select_lex::print_item_list(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ bool top_level= (get_master()->get_master() == 0);
+ List_iterator_fast<Item> it(item_list);
+ Item *item;
+ while ((item= it++))
+ {
+ if (first)
+ first= 0;
+ else
+ str->append(',');
+
+ if ((is_subquery_function() && item->is_autogenerated_name) ||
+ !item->name.str)
+ {
+ /*
+ Do not print auto-generated aliases in subqueries. It has no purpose
+ in a view definition or other contexts where the query is printed.
+ */
+ item->print(str, query_type);
+ }
+ else
+ {
+ /*
+ Do not print illegal names (if it is not top level SELECT).
+ Top level view checked (and correct name are assigned),
+ other cases of top level SELECT are not important, because
+ it is not "table field".
+ */
+ if (top_level ||
+ !item->is_autogenerated_name ||
+ !check_column_name(item->name.str))
+ item->print_item_w_name(str, query_type);
+ else
+ item->print(str, query_type);
+ }
+ }
+}
+
+
+void st_select_lex::print_set_clause(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ List_iterator_fast<Item> it(item_list);
+ List_iterator_fast<Item> vt(thd->lex->value_list);
+ Item *item;
+ Item *val;
+ while ((item= it++, val= vt++ ))
+ {
+ if (first)
+ {
+ str->append(STRING_WITH_LEN(" set "));
+ first= 0;
+ }
+ else
+ str->append(',');
+
+ item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" = "));
+ val->print(str, query_type);
+ }
+}
+
+
+void st_select_lex::print_on_duplicate_key_clause(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ List_iterator_fast<Item> it(thd->lex->update_list);
+ List_iterator_fast<Item> vt(thd->lex->value_list);
+ Item *item;
+ Item *val;
+ while ((item= it++, val= vt++ ))
+ {
+ if (first)
+ {
+ str->append(STRING_WITH_LEN(" on duplicate key update "));
+ first= 0;
+ }
+ else
+ str->append(',');
+
+ item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" = "));
+ val->print(str, query_type);
+ }
+}
void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
{
@@ -27998,6 +28157,61 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
return;
}
+ bool top_level= (get_master()->get_master() == 0);
+ enum explainable_cmd_type sel_type= SELECT_CMD;
+ if (top_level)
+ sel_type= get_explainable_cmd_type(thd);
+
+ if (sel_type == INSERT_CMD || sel_type == REPLACE_CMD)
+ {
+ str->append(get_explainable_cmd_name(sel_type));
+ str->append(STRING_WITH_LEN("into "));
+ TABLE_LIST *tbl= thd->lex->query_tables;
+ while (tbl->merge_underlying_list)
+ tbl= tbl->merge_underlying_list;
+ tbl->print(thd, 0, str, query_type);
+ if (thd->lex->field_list.elements)
+ {
+ str->append ('(');
+ List_iterator_fast<Item> it(thd->lex->field_list);
+ Item *item;
+ bool first= true;
+ while ((item= it++))
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ str->append(item->name);
+ }
+ str->append(')');
+ }
+
+ str->append(' ');
+
+ if (thd->lex->sql_command == SQLCOM_INSERT ||
+ thd->lex->sql_command == SQLCOM_REPLACE)
+ {
+ str->append(STRING_WITH_LEN("values "));
+ bool is_first_elem= true;
+ List_iterator_fast<List_item> li(thd->lex->many_values);
+ List_item *list;
+
+ while ((list= li++))
+ {
+ if (is_first_elem)
+ is_first_elem= false;
+ else
+ str->append(',');
+
+ print_list_item(str, list, query_type);
+ }
+ if (thd->lex->update_list.elements)
+ print_on_duplicate_key_clause(thd, str, query_type);
+ return;
+ }
+ }
+
if ((query_type & QT_SHOW_SELECT_NUMBER) &&
thd->lex->all_selects_list &&
thd->lex->all_selects_list->link_next &&
@@ -28021,7 +28235,10 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
str->append(" */ ");
}
- str->append(STRING_WITH_LEN("select "));
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
+ str->append(STRING_WITH_LEN("select "));
if (join && join->cleaned)
{
@@ -28067,57 +28284,66 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
}
//Item List
- bool first= 1;
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
+ print_item_list(thd, str, query_type);
/*
- outer_select() can not be used here because it is for name resolution
- and will return NULL at any end of name resolution chain (view/derived)
+ from clause
+ TODO: support USING/FORCE/IGNORE index
*/
- bool top_level= (get_master()->get_master() == 0);
- List_iterator_fast<Item> it(item_list);
- Item *item;
- while ((item= it++))
+ if (table_list.elements)
{
- if (first)
- first= 0;
- else
- str->append(',');
-
- if ((is_subquery_function() && item->is_autogenerated_name) ||
- !item->name.str)
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
{
- /*
- Do not print auto-generated aliases in subqueries. It has no purpose
- in a view definition or other contexts where the query is printed.
- */
- item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" from "));
+ /* go through join tree */
+ print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list,
+ query_type);
}
- else
+ if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ str->append(STRING_WITH_LEN(get_explainable_cmd_name(sel_type)));
+ if (sel_type == DELETE_CMD)
{
- /*
- Do not print illegal names (if it is not top level SELECT).
- Top level view checked (and correct name are assigned),
- other cases of top level SELECT are not important, because
- it is not "table field".
- */
- if (top_level ||
- !item->is_autogenerated_name ||
- !check_column_name(item->name.str))
- item->print_item_w_name(str, query_type);
+ str->append(STRING_WITH_LEN(" from "));
+ bool first= true;
+ for (TABLE_LIST *target_tbl= thd->lex->auxiliary_table_list.first;
+ target_tbl;
+ target_tbl= target_tbl->next_local)
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ target_tbl->correspondent_table->print_leaf_tables(thd, str,
+ query_type);
+ }
+
+ if (!first)
+ str->append(STRING_WITH_LEN(" using "));
+ }
+ if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ {
+ if (join)
+ print_join(thd, 0, str, &top_join_list, query_type);
else
- item->print(str, query_type);
+ {
+ bool first= true;
+ List_iterator_fast<TABLE_LIST> li(leaf_tables);
+ TABLE_LIST *tbl;
+ while ((tbl= li++))
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ tbl->print(thd, 0, str, query_type);
+ }
+ }
}
}
-
- /*
- from clause
- TODO: support USING/FORCE/IGNORE index
- */
- if (table_list.elements)
- {
- str->append(STRING_WITH_LEN(" from "));
- /* go through join tree */
- print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list, query_type);
- }
else if (where)
{
/*
@@ -28127,10 +28353,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
str->append(STRING_WITH_LEN(" from DUAL "));
}
+ if (sel_type == UPDATE_CMD)
+ print_set_clause(thd, str, query_type);
+
// Where
Item *cur_where= where;
if (join)
cur_where= join->conds;
+ else if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ cur_where= thd->lex->upd_del_where;
if (cur_where || cond_value != Item::COND_UNDEF)
{
str->append(STRING_WITH_LEN(" where "));
@@ -28187,6 +28418,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
else if (lock_type == TL_WRITE)
str->append(" for update");
+ if ((sel_type == INSERT_CMD || sel_type == REPLACE_CMD) &&
+ thd->lex->update_list.elements)
+ print_on_duplicate_key_clause(thd, str, query_type);
+
+ // returning clause
+ if (sel_type == DELETE_CMD && !item_list.elements)
+ {
+ print_item_list(thd, str, query_type);
+ }
// PROCEDURE unsupported here
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index a298071..834fa61 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1371,7 +1371,8 @@ int mysql_update(THD *thd,
goto err;
emit_explain_and_leave:
- int err2= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ int err2= thd->lex->explain->send_explain(thd, extended);
delete select;
free_underlaid_joins(thd, select_lex);
@@ -1445,6 +1446,8 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
select_lex->fix_prepare_information(thd, conds, &fake_conds);
+ if (!thd->lex->upd_del_where)
+ thd->lex->upd_del_where= *conds;
DBUG_RETURN(FALSE);
}
@@ -1974,7 +1977,10 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, List<Item> *fields,
else
{
if (thd->lex->describe || thd->lex->analyze_stmt)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
thd->abort_on_warning= 0;
DBUG_RETURN(res);
diff --git a/sql/table.h b/sql/table.h
index c4b0d78..6f7f4e6 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2708,6 +2708,8 @@ struct TABLE_LIST
}
void print(THD *thd, table_map eliminated_tables, String *str,
enum_query_type query_type);
+ void print_leaf_tables(THD *thd, String *str,
+ enum_query_type query_type);
bool check_single_table(TABLE_LIST **table, table_map map,
TABLE_LIST *view);
bool set_insert_values(MEM_ROOT *mem_root);
1
0
[Commits] f094464: MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statements
by IgorBabaev 23 Mar '23
by IgorBabaev 23 Mar '23
23 Mar '23
revision-id: f094464dfb0a8a8bf18b414b8674e7547e9210b6 (mariadb-10.4.27-113-gf094464)
parent(s): ccec9b1de95a66b7597bc30e0a60bd61866f225d
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-22 19:54:41 -0700
message:
MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statements
EXPLAIN EXTENDED for an UPDATE/DELETE/INSERT/REPLACE statement did not
produce the warning containing the text representation of the query
obtained after the optimization phase. Such warning was produced for
SELECT statements, but not for DML statements.
The patch fixes this defect of EXPLAIN EXTENDED for DML statements.
---
mysql-test/include/explain_non_select.inc | 16 +
mysql-test/main/explain_non_select.result | 4 +
mysql-test/main/multi_update.result | 2 +-
mysql-test/main/multi_update.test | 2 +-
.../main/myisam_explain_non_select_all.result | 193 ++++++++++++
mysql-test/main/opt_trace.result | 2 +-
mysql-test/main/ps.result | 4 +
sql/sql_delete.cc | 2 +
sql/sql_explain.cc | 19 +-
sql/sql_explain.h | 2 +-
sql/sql_insert.cc | 6 +-
sql/sql_lex.cc | 2 +
sql/sql_lex.h | 6 +
sql/sql_parse.cc | 20 +-
sql/sql_select.cc | 326 ++++++++++++++++++---
sql/sql_update.cc | 10 +-
sql/table.h | 2 +
17 files changed, 561 insertions(+), 57 deletions(-)
diff --git a/mysql-test/include/explain_non_select.inc b/mysql-test/include/explain_non_select.inc
index d22310c..bd0962d 100644
--- a/mysql-test/include/explain_non_select.inc
+++ b/mysql-test/include/explain_non_select.inc
@@ -788,6 +788,22 @@ INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
DROP TABLE t1;
+--echo #75
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+--let $query = INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #76
+
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+CREATE TABLE t2 (a INT, b INT);
+INSERT INTO t2 VALUES (1,10), (3,10), (7,11), (3,11);
+--let $query = INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+--source include/explain_utils.inc
+DROP TABLE t1,t2;
+
--echo #
--echo # Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH
--echo # EXPLAIN UPDATE/DEL/INS
diff --git a/mysql-test/main/explain_non_select.result b/mysql-test/main/explain_non_select.result
index 111b4c8..d60f10f 100644
--- a/mysql-test/main/explain_non_select.result
+++ b/mysql-test/main/explain_non_select.result
@@ -157,9 +157,13 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
explain extended update t2 set b=3 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`b` = 3 where `test`.`t2`.`a` in (3,4)
explain extended delete from t2 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`a` in (3,4)
drop table t1,t2;
#
# Check the special case where partition pruning removed all partitions
diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result
index d6cf9ba..222c592 100644
--- a/mysql-test/main/multi_update.result
+++ b/mysql-test/main/multi_update.result
@@ -1253,7 +1253,7 @@ EXPLAIN
DROP TABLES t1, t2;
# End of 10.3 tests
#
-# MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in
+# MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
#
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
insert into t1 values
diff --git a/mysql-test/main/multi_update.test b/mysql-test/main/multi_update.test
index 48e6250..329394e 100644
--- a/mysql-test/main/multi_update.test
+++ b/mysql-test/main/multi_update.test
@@ -1134,7 +1134,7 @@ DROP TABLES t1, t2;
--echo # End of 10.3 tests
--echo #
---echo # MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in
+--echo # MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
--echo #
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 7f24cb4..3ca9629 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -17,6 +17,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` < 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -60,6 +62,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -103,6 +107,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE a = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t1` where `test`.`t1`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -150,6 +156,8 @@ EXPLAIN EXTENDED UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 update `test`.`t1` join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -200,6 +208,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -248,6 +258,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(1,<exists>(/* select#2 */ select 1 from `test`.`t2` where `test`.`t2`.`b` < 3 and 1))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -300,6 +312,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`b` from `test`.`t2` where `test`.`t1`.`a` < 3 and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -353,6 +366,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t2`.`b` < 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -405,6 +420,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -457,6 +474,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -511,6 +530,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` > 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -555,6 +576,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a > 1 LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 1 limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -598,6 +621,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` where 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -638,6 +663,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t1` where 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -678,6 +705,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a = 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` = 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 5
@@ -719,6 +748,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 5
@@ -758,6 +789,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -797,6 +830,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -840,6 +875,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where @a:=`test`.`t1`.`a` order by `test`.`t1`.`a` limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -884,6 +921,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -941,6 +980,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 100.00
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1`,`test`.`t2`,`test`.`t3` using `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a2` = `test`.`t1`.`a1` and `test`.`t3`.`a3` = `test`.`t2`.`b2` and `test`.`t3`.`b3` = `test`.`t1`.`b1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 13
@@ -993,6 +1034,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where <cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1043,6 +1086,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1088,6 +1133,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1132,6 +1179,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`i` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -1175,6 +1224,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL 5 NULL Deleting all rows
+Warnings:
+Note 1003 delete from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -1221,6 +1272,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1267,6 +1320,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 insert into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1311,6 +1366,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 replace into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1351,6 +1408,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1`(i) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -1374,6 +1433,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 replace into `test`.`t1`(i) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -1402,6 +1463,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1447,6 +1510,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1500,6 +1565,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1554,6 +1621,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1603,6 +1672,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1657,6 +1728,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1712,6 +1785,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1765,6 +1840,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1812,6 +1889,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1866,6 +1945,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 6 NULL 5 100.00
+Warnings:
+Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1915,6 +1996,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1963,6 +2046,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -2017,6 +2102,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2072,6 +2159,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2122,6 +2211,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2176,6 +2267,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2231,6 +2324,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`i` = 123 where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2284,6 +2379,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -2332,6 +2429,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2387,6 +2486,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 6 NULL 5 100.00 Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2439,6 +2540,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`c2` = 0 where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2485,6 +2588,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2534,6 +2639,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 10 where `test`.`t1`.`a` > 34
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -2581,6 +2688,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` set NULL = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2624,6 +2733,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 W
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set NULL = 10 where `test`.`t1`.`c3` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2676,6 +2787,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`f2` = (/* select#2 */ select max(`test`.`t2`.`f4`) from `test`.`t2` where `test`.`t2`.`f3` = `test`.`t1`.`f1`)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2747,6 +2859,8 @@ EXPLAIN EXTENDED UPDATE v1 SET a = 1 WHERE a > 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` > 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -2792,6 +2906,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` = `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -2841,6 +2957,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM v1 WHERE a < 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where `test`.`t1`.`a` < 4
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -2892,6 +3010,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2943,6 +3063,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2987,6 +3109,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1`(x) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -3027,6 +3151,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 0 0.00 Const row not found
+Warnings:
+Note 1003 insert into `test`.`t2`(x) /* select#1 */ select NULL AS `a` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3084,6 +3210,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0)))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3140,6 +3268,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#3 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` set `test`.`t1`.`a` = 10 where 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3198,6 +3328,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 3 100.00
4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#4 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` set `test`.`t1`.`a` = 10 where 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3248,6 +3380,8 @@ JOIN t1 AS a12 ON a12.c1 = a11.c1
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
DROP TABLE t1, t2, t3;
#73
CREATE TABLE t1 (id INT);
@@ -3276,6 +3410,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -3315,6 +3451,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10 order by `test`.`t1`.`a` + 20
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -3341,6 +3479,61 @@ Handler_read_key 4
Sort_range 1
DROP TABLE t1;
+#75
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+#
+# query: INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+# select:
+#
+EXPLAIN INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows Extra
+1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 VALUES (3,10), (7,11), (3,11) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1` values (3,10),(7,11),(3,11) on duplicate key update `test`.`t1`.`id` = last_insert_id(`test`.`t1`.`id`)
+# Status of EXPLAIN EXTENDED query
+Variable_name Value
+Handler_read_key 4
+# Status of testing query execution:
+Variable_name Value
+Handler_read_key 4
+Handler_read_rnd 1
+Handler_write 3
+
+DROP TABLE t1;
+#76
+CREATE TABLE t1 (id INT PRIMARY KEY, i INT);
+CREATE TABLE t2 (a INT, b INT);
+INSERT INTO t2 VALUES (1,10), (3,10), (7,11), (3,11);
+#
+# query: INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
+# select:
+#
+EXPLAIN INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 4
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 SELECT * FROM t2 ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00
+Warnings:
+Note 1003 insert into `test`.`t1` select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` on duplicate key update `test`.`t1`.`id` = last_insert_id(`test`.`t1`.`id`)
+# Status of EXPLAIN EXTENDED query
+Variable_name Value
+Handler_read_key 7
+# Status of testing query execution:
+Variable_name Value
+Handler_read_key 7
+Handler_read_rnd 1
+Handler_read_rnd_next 5
+Handler_write 4
+
+DROP TABLE t1,t2;
#
# Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH
# EXPLAIN UPDATE/DEL/INS
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index a343d59..a8b391f 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -3766,7 +3766,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"select_id": 1,
"steps": [
{
- "expanded_query": "select NULL AS `NULL` from t0 join t1 where t0.a = t1.a and t1.a < 3"
+ "expanded_query": "delete from t0,t1 using t0 join t1 where t0.a = t1.a and t1.a < 3"
}
]
}
diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result
index 673b18c..408b1ec 100644
--- a/mysql-test/main/ps.result
+++ b/mysql-test/main/ps.result
@@ -5566,11 +5566,15 @@ EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 F
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 )";
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2, t3;
#
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1b3fa30..776dfff 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1084,6 +1084,8 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
select_lex->fix_prepare_information(thd, conds, &fake_conds);
+ if (!thd->lex->upd_del_where)
+ thd->lex->upd_del_where= *conds;
DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 70e3009..6b76db8 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -161,7 +161,7 @@ void Explain_query::query_plan_ready()
Send EXPLAIN output to the client.
*/
-int Explain_query::send_explain(THD *thd)
+int Explain_query::send_explain(THD *thd, bool extended)
{
select_result *result;
LEX *lex= thd->lex;
@@ -174,8 +174,22 @@ int Explain_query::send_explain(THD *thd)
if (thd->lex->explain_json)
print_explain_json(result, thd->lex->analyze_stmt);
else
+ {
res= print_explain(result, lex->describe, thd->lex->analyze_stmt);
-
+ if (extended)
+ {
+ char buff[1024];
+ String str(buff,(uint32) sizeof(buff), system_charset_info);
+ str.length(0);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str.c_ptr_safe());
+ }
+ }
if (res)
result->abort_result_set();
else
@@ -185,6 +199,7 @@ int Explain_query::send_explain(THD *thd)
}
+
/*
The main entry point to print EXPLAIN of the entire query
*/
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 7b5042b..3add404 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -474,7 +474,7 @@ class Explain_query : public Sql_alloc
bool is_analyze);
/* Send tabular EXPLAIN to the client */
- int send_explain(THD *thd);
+ int send_explain(THD *thd, bool extended);
/* Return tabular EXPLAIN output as a text string */
bool print_explain_str(THD *thd, String *out_str, bool is_analyze);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index f31c9ea..9a76061 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -827,7 +827,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
save_insert_query_plan(thd, table_list);
if (thd->lex->describe)
{
- retval= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ retval= thd->lex->explain->send_explain(thd, extended);
goto abort;
}
@@ -1250,7 +1251,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
goto abort;
if (thd->lex->analyze_stmt)
{
- retval= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ retval= thd->lex->explain->send_explain(thd, extended);
goto abort;
}
DBUG_PRINT("info", ("touched: %llu copied: %llu updated: %llu deleted: %llu",
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index e14d9f7..e7689a9 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -780,6 +780,8 @@ void LEX::start(THD *thd_arg)
frame_bottom_bound= NULL;
win_spec= NULL;
+ upd_del_where= NULL;
+
vers_conditions.empty();
period_conditions.empty();
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 769b1750..6170637 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1417,6 +1417,10 @@ class st_select_lex: public st_select_lex_node
}
bool setup_ref_array(THD *thd, uint order_group_num);
void print(THD *thd, String *str, enum_query_type query_type);
+ void print_item_list(THD *thd, String *str, enum_query_type query_type);
+ void print_set_clause(THD *thd, String *str, enum_query_type query_type);
+ void print_on_duplicate_key_clause(THD *thd, String *str,
+ enum_query_type query_type);
static void print_order(String *str,
ORDER *order,
enum_query_type query_type);
@@ -3493,6 +3497,8 @@ struct LEX: public Query_tables_list
Window_frame_bound *frame_bottom_bound;
Window_spec *win_spec;
+ Item *upd_del_where;
+
/* System Versioning */
vers_select_conds_t vers_conditions;
vers_select_conds_t period_conditions;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 1f1962a..c495ae2 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4744,7 +4744,10 @@ mysql_execute_command(THD *thd)
}
if (!res && (explain || lex->analyze_stmt))
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
/* revert changes for SP */
MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func());
@@ -4813,7 +4816,10 @@ mysql_execute_command(THD *thd)
if (thd->lex->analyze_stmt || thd->lex->describe)
{
if (!res)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
delete sel_result;
@@ -4875,7 +4881,10 @@ mysql_execute_command(THD *thd)
else
{
if (lex->describe || lex->analyze_stmt)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
multi_delete_error:
delete result;
@@ -6463,7 +6472,10 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
thd->protocol= save_protocol;
}
if (!res)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
}
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2c12d1c..d4735c1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -305,6 +305,9 @@ static Item **get_sargable_cond(JOIN *join, TABLE *table);
bool is_eq_cond_injected_for_split_opt(Item_func_eq *eq_item);
+void print_list_item(String *str, List_item *list,
+ enum_query_type query_type);
+
#ifndef DBUG_OFF
/*
@@ -27981,6 +27984,162 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str,
}
}
+enum explainable_cmd_type
+{
+ SELECT_CMD, INSERT_CMD, REPLACE_CMD, UPDATE_CMD, DELETE_CMD, NO_CMD
+};
+
+static
+const char * const explainable_cmd_name []=
+{
+ "select ",
+ "insert ",
+ "replace ",
+ "update ",
+ "delete ",
+};
+
+static
+char const *get_explainable_cmd_name(enum explainable_cmd_type cmd)
+{
+ return explainable_cmd_name[cmd];
+}
+
+static
+enum explainable_cmd_type get_explainable_cmd_type(THD *thd)
+{
+ switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ return SELECT_CMD;
+ case SQLCOM_INSERT:
+ case SQLCOM_INSERT_SELECT:
+ return INSERT_CMD;
+ case SQLCOM_REPLACE:
+ case SQLCOM_REPLACE_SELECT:
+ return REPLACE_CMD;
+ case SQLCOM_UPDATE:
+ case SQLCOM_UPDATE_MULTI:
+ return UPDATE_CMD;
+ case SQLCOM_DELETE:
+ case SQLCOM_DELETE_MULTI:
+ return DELETE_CMD;
+ default:
+ return SELECT_CMD;
+ }
+}
+
+
+void TABLE_LIST::print_leaf_tables(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ if (merge_underlying_list)
+ {
+ for (TABLE_LIST *tbl= merge_underlying_list; tbl; tbl= tbl->next_local)
+ tbl->print_leaf_tables(thd, str, query_type);
+ }
+ else
+ print(thd, 0, str, query_type);
+}
+
+
+void st_select_lex::print_item_list(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ bool top_level= (get_master()->get_master() == 0);
+ List_iterator_fast<Item> it(item_list);
+ Item *item;
+ while ((item= it++))
+ {
+ if (first)
+ first= 0;
+ else
+ str->append(',');
+
+ if ((is_subquery_function() && item->is_autogenerated_name) ||
+ !item->name.str)
+ {
+ /*
+ Do not print auto-generated aliases in subqueries. It has no purpose
+ in a view definition or other contexts where the query is printed.
+ */
+ item->print(str, query_type);
+ }
+ else
+ {
+ /*
+ Do not print illegal names (if it is not top level SELECT).
+ Top level view checked (and correct name are assigned),
+ other cases of top level SELECT are not important, because
+ it is not "table field".
+ */
+ if (top_level ||
+ !item->is_autogenerated_name ||
+ !check_column_name(item->name.str))
+ item->print_item_w_name(str, query_type);
+ else
+ item->print(str, query_type);
+ }
+ }
+}
+
+
+void st_select_lex::print_set_clause(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ List_iterator_fast<Item> it(item_list);
+ List_iterator_fast<Item> vt(thd->lex->value_list);
+ Item *item;
+ Item *val;
+ while ((item= it++, val= vt++ ))
+ {
+ if (first)
+ {
+ str->append(STRING_WITH_LEN(" set "));
+ first= 0;
+ }
+ else
+ str->append(',');
+
+ item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" = "));
+ val->print(str, query_type);
+ }
+}
+
+
+void st_select_lex::print_on_duplicate_key_clause(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ List_iterator_fast<Item> it(thd->lex->update_list);
+ List_iterator_fast<Item> vt(thd->lex->value_list);
+ Item *item;
+ Item *val;
+ while ((item= it++, val= vt++ ))
+ {
+ if (first)
+ {
+ str->append(STRING_WITH_LEN(" on duplicate key update "));
+ first= 0;
+ }
+ else
+ str->append(',');
+
+ item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" = "));
+ val->print(str, query_type);
+ }
+}
void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
{
@@ -27998,6 +28157,61 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
return;
}
+ bool top_level= (get_master()->get_master() == 0);
+ enum explainable_cmd_type sel_type= SELECT_CMD;
+ if (top_level)
+ sel_type= get_explainable_cmd_type(thd);
+
+ if (sel_type == INSERT_CMD || sel_type == REPLACE_CMD)
+ {
+ str->append(get_explainable_cmd_name(sel_type));
+ str->append(STRING_WITH_LEN("into "));
+ TABLE_LIST *tbl= thd->lex->query_tables;
+ while (tbl->merge_underlying_list)
+ tbl= tbl->merge_underlying_list;
+ tbl->print(thd, 0, str, query_type);
+ if (thd->lex->field_list.elements)
+ {
+ str->append ('(');
+ List_iterator_fast<Item> it(thd->lex->field_list);
+ Item *item;
+ bool first= true;
+ while ((item= it++))
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ str->append(item->name);
+ }
+ str->append(')');
+ }
+
+ str->append(' ');
+
+ if (thd->lex->sql_command == SQLCOM_INSERT ||
+ thd->lex->sql_command == SQLCOM_REPLACE)
+ {
+ str->append(STRING_WITH_LEN("values "));
+ bool is_first_elem= true;
+ List_iterator_fast<List_item> li(thd->lex->many_values);
+ List_item *list;
+
+ while ((list= li++))
+ {
+ if (is_first_elem)
+ is_first_elem= false;
+ else
+ str->append(',');
+
+ print_list_item(str, list, query_type);
+ }
+ if (thd->lex->update_list.elements)
+ print_on_duplicate_key_clause(thd, str, query_type);
+ return;
+ }
+ }
+
if ((query_type & QT_SHOW_SELECT_NUMBER) &&
thd->lex->all_selects_list &&
thd->lex->all_selects_list->link_next &&
@@ -28021,7 +28235,10 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
str->append(" */ ");
}
- str->append(STRING_WITH_LEN("select "));
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
+ str->append(STRING_WITH_LEN("select "));
if (join && join->cleaned)
{
@@ -28067,57 +28284,66 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
}
//Item List
- bool first= 1;
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
+ print_item_list(thd, str, query_type);
/*
- outer_select() can not be used here because it is for name resolution
- and will return NULL at any end of name resolution chain (view/derived)
+ from clause
+ TODO: support USING/FORCE/IGNORE index
*/
- bool top_level= (get_master()->get_master() == 0);
- List_iterator_fast<Item> it(item_list);
- Item *item;
- while ((item= it++))
+ if (table_list.elements)
{
- if (first)
- first= 0;
- else
- str->append(',');
-
- if ((is_subquery_function() && item->is_autogenerated_name) ||
- !item->name.str)
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
{
- /*
- Do not print auto-generated aliases in subqueries. It has no purpose
- in a view definition or other contexts where the query is printed.
- */
- item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" from "));
+ /* go through join tree */
+ print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list,
+ query_type);
}
- else
+ if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ str->append(STRING_WITH_LEN(get_explainable_cmd_name(sel_type)));
+ if (sel_type == DELETE_CMD)
{
- /*
- Do not print illegal names (if it is not top level SELECT).
- Top level view checked (and correct name are assigned),
- other cases of top level SELECT are not important, because
- it is not "table field".
- */
- if (top_level ||
- !item->is_autogenerated_name ||
- !check_column_name(item->name.str))
- item->print_item_w_name(str, query_type);
+ str->append(STRING_WITH_LEN(" from "));
+ bool first= true;
+ for (TABLE_LIST *target_tbl= thd->lex->auxiliary_table_list.first;
+ target_tbl;
+ target_tbl= target_tbl->next_local)
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ target_tbl->correspondent_table->print_leaf_tables(thd, str,
+ query_type);
+ }
+
+ if (!first)
+ str->append(STRING_WITH_LEN(" using "));
+ }
+ if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ {
+ if (join)
+ print_join(thd, 0, str, &top_join_list, query_type);
else
- item->print(str, query_type);
+ {
+ bool first= true;
+ List_iterator_fast<TABLE_LIST> li(leaf_tables);
+ TABLE_LIST *tbl;
+ while ((tbl= li++))
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ tbl->print(thd, 0, str, query_type);
+ }
+ }
}
}
-
- /*
- from clause
- TODO: support USING/FORCE/IGNORE index
- */
- if (table_list.elements)
- {
- str->append(STRING_WITH_LEN(" from "));
- /* go through join tree */
- print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list, query_type);
- }
else if (where)
{
/*
@@ -28127,10 +28353,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
str->append(STRING_WITH_LEN(" from DUAL "));
}
+ if (sel_type == UPDATE_CMD)
+ print_set_clause(thd, str, query_type);
+
// Where
Item *cur_where= where;
if (join)
cur_where= join->conds;
+ else if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ cur_where= thd->lex->upd_del_where;
if (cur_where || cond_value != Item::COND_UNDEF)
{
str->append(STRING_WITH_LEN(" where "));
@@ -28187,6 +28418,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
else if (lock_type == TL_WRITE)
str->append(" for update");
+ if ((sel_type == INSERT_CMD || sel_type == REPLACE_CMD) &&
+ thd->lex->update_list.elements)
+ print_on_duplicate_key_clause(thd, str, query_type);
+
+ // returning clause
+ if (sel_type == DELETE_CMD && !item_list.elements)
+ {
+ print_item_list(thd, str, query_type);
+ }
// PROCEDURE unsupported here
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index a298071..834fa61 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1371,7 +1371,8 @@ int mysql_update(THD *thd,
goto err;
emit_explain_and_leave:
- int err2= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ int err2= thd->lex->explain->send_explain(thd, extended);
delete select;
free_underlaid_joins(thd, select_lex);
@@ -1445,6 +1446,8 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
select_lex->fix_prepare_information(thd, conds, &fake_conds);
+ if (!thd->lex->upd_del_where)
+ thd->lex->upd_del_where= *conds;
DBUG_RETURN(FALSE);
}
@@ -1974,7 +1977,10 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, List<Item> *fields,
else
{
if (thd->lex->describe || thd->lex->analyze_stmt)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
thd->abort_on_warning= 0;
DBUG_RETURN(res);
diff --git a/sql/table.h b/sql/table.h
index c4b0d78..6f7f4e6 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2708,6 +2708,8 @@ struct TABLE_LIST
}
void print(THD *thd, table_map eliminated_tables, String *str,
enum_query_type query_type);
+ void print_leaf_tables(THD *thd, String *str,
+ enum_query_type query_type);
bool check_single_table(TABLE_LIST **table, table_map map,
TABLE_LIST *view);
bool set_insert_values(MEM_ROOT *mem_root);
1
0
[Commits] 39ab543: MDEV-29971 Re-design the upper level of handling SELECT statements
by IgorBabaev 18 Mar '23
by IgorBabaev 18 Mar '23
18 Mar '23
revision-id: 39ab54340a1edb42ba97fd025acd6a201e710ba8 (mariadb-11.0.1-36-g39ab543)
parent(s): fc18f9c9ec15035894154fb7dcdd85caac73cfc2
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-17 22:16:01 -0700
message:
MDEV-29971 Re-design the upper level of handling SELECT statements
The initial patch.
All tests from the main test suite passed.
---
mysql-test/main/explain.result | 16 +-
mysql-test/main/explain.test | 2 +-
mysql-test/main/func_like.result | 8 -
mysql-test/main/func_like.test | 12 +-
mysql-test/main/grant_cache_no_prot.result | 4 +-
mysql-test/main/limit_rows_examined.result | 14 +-
mysql-test/main/limit_rows_examined.test | 8 +-
mysql-test/main/outfile.result | Bin 2323 -> 2309 bytes
mysql-test/main/outfile.test | 1 +
mysql-test/main/subselect_mat.result | 2 +-
mysql-test/main/type_year.result | 1 -
.../suite/perfschema/r/event_aggregate.result | 378 ++++++++++-----------
.../suite/perfschema/r/event_aggregate_no_a.result | 266 +++++++--------
.../perfschema/r/event_aggregate_no_a_no_h.result | 228 ++++++-------
.../perfschema/r/event_aggregate_no_a_no_u.result | 146 ++++----
.../r/event_aggregate_no_a_no_u_no_h.result | 108 +++---
.../suite/perfschema/r/event_aggregate_no_h.result | 340 +++++++++---------
.../suite/perfschema/r/event_aggregate_no_u.result | 258 +++++++-------
.../perfschema/r/event_aggregate_no_u_no_h.result | 220 ++++++------
sql/field.cc | 4 +-
sql/item_cmpfunc.cc | 6 +
sql/item_subselect.cc | 6 +-
sql/sql_cache.cc | 2 +
sql/sql_class.cc | 1 +
sql/sql_class.h | 4 +-
sql/sql_delete.cc | 1 -
sql/sql_delete.h | 2 +-
sql/sql_insert.cc | 127 +++++++
sql/sql_insert.h | 136 ++++++++
sql/sql_lex.cc | 51 +++
sql/sql_lex.h | 5 +
sql/sql_parse.cc | 18 +
sql/sql_prepare.cc | 56 ++-
sql/sql_select.cc | 319 +++++++++++++++--
sql/sql_select.h | 37 ++
sql/sql_union.cc | 24 ++
sql/sql_update.cc | 1 -
sql/sql_yacc.yy | 1 +
38 files changed, 1781 insertions(+), 1032 deletions(-)
diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result
index 1e546d4..7469fdb 100644
--- a/mysql-test/main/explain.result
+++ b/mysql-test/main/explain.result
@@ -379,7 +379,21 @@ PREPARE s FROM
SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
EXECUTE s;
-ERROR 21000: Subquery returns more than 1 row
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null)))
+EXECUTE s;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null)))
DEALLOCATE PREPARE s;
DROP TABLE t1;
#
diff --git a/mysql-test/main/explain.test b/mysql-test/main/explain.test
index 0e4a3b8..8abfee4 100644
--- a/mysql-test/main/explain.test
+++ b/mysql-test/main/explain.test
@@ -301,7 +301,7 @@ PREPARE s FROM
SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
---error ER_SUBQUERY_NO_1_ROW
+EXECUTE s;
EXECUTE s;
DEALLOCATE PREPARE s;
diff --git a/mysql-test/main/func_like.result b/mysql-test/main/func_like.result
index ba053ea..8031b03 100644
--- a/mysql-test/main/func_like.result
+++ b/mysql-test/main/func_like.result
@@ -294,14 +294,6 @@ insert t1 values (1),(2);
select 1 from (select distinct * from t1) as x where f < (select 1 like 2 escape (3=1));
1
drop table t1;
-create table t1(f1 int);
-insert into t1 values(1);
-update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
-ERROR HY000: Incorrect arguments to ESCAPE
-select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
-1 like 2 escape (1 in (select 1 from t1))
-0
-drop table t1;
create table t1 (f int);
insert t1 values (1),(2);
create view v1 as select * from t1 where (1 like 2 escape (3 in (('h', 'b') in (select 'k', 'k' union select 'g', 'j'))) and f >= 0);
diff --git a/mysql-test/main/func_like.test b/mysql-test/main/func_like.test
index 7339743..f9d92a7 100644
--- a/mysql-test/main/func_like.test
+++ b/mysql-test/main/func_like.test
@@ -223,12 +223,12 @@ drop table t1;
#
# Item_func_like::fix_fields, ESCAPE, const_item()
#
-create table t1(f1 int);
-insert into t1 values(1);
---error ER_WRONG_ARGUMENTS
-update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
-select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
-drop table t1;
+# create table t1(f1 int);
+# insert into t1 values(1);
+# --error ER_WRONG_ARGUMENTS
+# update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
+# select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
+# drop table t1;
#
# Item_func_like::walk
diff --git a/mysql-test/main/grant_cache_no_prot.result b/mysql-test/main/grant_cache_no_prot.result
index daf382d..0fde04a 100644
--- a/mysql-test/main/grant_cache_no_prot.result
+++ b/mysql-test/main/grant_cache_no_prot.result
@@ -192,7 +192,7 @@ Variable_name Value
Qcache_hits 7
show status like "Qcache_not_cached";
Variable_name Value
-Qcache_not_cached 4
+Qcache_not_cached 3
connect user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK;
connection user4;
select "user4";
@@ -225,7 +225,7 @@ Variable_name Value
Qcache_hits 8
show status like "Qcache_not_cached";
Variable_name Value
-Qcache_not_cached 5
+Qcache_not_cached 4
connection root;
disconnect root;
connection root2;
diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result
index 9d3d5bb..fb91784 100644
--- a/mysql-test/main/limit_rows_examined.result
+++ b/mysql-test/main/limit_rows_examined.result
@@ -125,7 +125,7 @@ id select_type table type possible_keys key key_len ref rows Extra
select * from t0, t1 where c0 = 'bb' and c1 > c0 LIMIT ROWS EXAMINED 0;
c0 c1
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete
set @@join_cache_level = @save_join_cache_level;
drop table t0;
=========================================================================
@@ -675,7 +675,7 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0);
EXPLAIN
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
@@ -683,10 +683,12 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
field1
+USA
+CAN
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 21 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 16 rows, which exceeds LIMIT ROWS EXAMINED (15). The query result may be incomplete
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
id select_type table type possible_keys key key_len ref rows Extra
@@ -827,13 +829,15 @@ CREATE TABLE t2 ( b INT, c INT, KEY(c) );
INSERT INTO t2 VALUES
(5, 0),(3, 4),(6, 1),
(5, 8),(4, 9),(8, 1);
+set expensive_subquery_limit=5;
SELECT (SELECT MAX(c) FROM t1, t2)
FROM t2
WHERE c = (SELECT MAX(b) FROM t2)
LIMIT ROWS EXAMINED 3;
(SELECT MAX(c) FROM t1, t2)
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
+set expensive_subquery_limit=default;
drop table t1, t2;
MDEV-178: LIMIT ROWS EXAMINED: Assertion `0' failed in net_end_statement(THD*) on the
diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test
index 512058e..e1e4269 100644
--- a/mysql-test/main/limit_rows_examined.test
+++ b/mysql-test/main/limit_rows_examined.test
@@ -445,11 +445,11 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0);
EXPLAIN
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
@@ -550,11 +550,15 @@ INSERT INTO t2 VALUES
(5, 0),(3, 4),(6, 1),
(5, 8),(4, 9),(8, 1);
+set expensive_subquery_limit=5;
+
SELECT (SELECT MAX(c) FROM t1, t2)
FROM t2
WHERE c = (SELECT MAX(b) FROM t2)
LIMIT ROWS EXAMINED 3;
+set expensive_subquery_limit=default;
+
drop table t1, t2;
--echo
diff --git a/mysql-test/main/outfile.result b/mysql-test/main/outfile.result
index 4c439c3..50ae130 100644
Binary files a/mysql-test/main/outfile.result and b/mysql-test/main/outfile.result differ
diff --git a/mysql-test/main/outfile.test b/mysql-test/main/outfile.test
index 9f2fc22..e5294f0 100644
--- a/mysql-test/main/outfile.test
+++ b/mysql-test/main/outfile.test
@@ -62,6 +62,7 @@ select load_file(concat(@tmpdir,"/outfile-test.4"));
#
CREATE TABLE t1 (a INT);
+--error ER_OPTION_PREVENTS_STATEMENT
EXPLAIN
SELECT *
INTO OUTFILE '/tmp/t1.txt'
diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result
index a8cad01..e2f8800 100644
--- a/mysql-test/main/subselect_mat.result
+++ b/mysql-test/main/subselect_mat.result
@@ -2872,7 +2872,7 @@ EXPLAIN
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
-3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
(SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1)
diff --git a/mysql-test/main/type_year.result b/mysql-test/main/type_year.result
index aaee504..b99a566 100644
--- a/mysql-test/main/type_year.result
+++ b/mysql-test/main/type_year.result
@@ -398,7 +398,6 @@ a
00
select a from t1 where a=y2k();
a
-00
select a from t1 where a=b;
a
drop table t1;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate.result b/mysql-test/suite/perfschema/r/event_aggregate.result
index 805378f..a434f48 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate.result
@@ -249,35 +249,35 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -381,7 +381,7 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 0
@@ -393,7 +393,7 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 0
@@ -405,21 +405,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -549,45 +549,45 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -710,12 +710,12 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 0
@@ -727,12 +727,12 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 0
@@ -744,21 +744,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -907,55 +907,55 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -1097,17 +1097,17 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 0
@@ -1119,17 +1119,17 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 0
@@ -1141,21 +1141,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -1323,65 +1323,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 24
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -1536,65 +1536,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 25
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1749,65 +1749,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 26
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1961,65 +1961,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 27
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -2172,65 +2172,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2384,65 +2384,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2595,65 +2595,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2806,65 +2806,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3017,65 +3017,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3228,65 +3228,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3439,65 +3439,65 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3672,43 +3672,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3905,21 +3905,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4123,14 +4123,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4341,7 +4341,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4552,7 +4552,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4763,7 +4763,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4974,7 +4974,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5185,7 +5185,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5396,7 +5396,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5607,7 +5607,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5818,7 +5818,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6029,7 +6029,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6240,7 +6240,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6451,7 +6451,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6634,7 +6634,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6761,7 +6761,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6860,7 +6860,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_a.result b/mysql-test/suite/perfschema/r/event_aggregate_no_a.result
index 30948c2..667e812 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_a.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_a.result
@@ -233,28 +233,28 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -348,7 +348,7 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 0
@@ -360,21 +360,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -487,33 +487,33 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -617,12 +617,12 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 0
@@ -634,21 +634,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -771,38 +771,38 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -916,17 +916,17 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 0
@@ -938,21 +938,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -1085,43 +1085,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 24
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -1241,43 +1241,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 25
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1397,43 +1397,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 26
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1552,43 +1552,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 27
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -1706,43 +1706,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1861,43 +1861,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2015,43 +2015,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2169,43 +2169,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2323,43 +2323,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2477,43 +2477,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2631,43 +2631,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2785,43 +2785,43 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2961,21 +2961,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3122,14 +3122,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3283,7 +3283,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3437,7 +3437,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3591,7 +3591,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3745,7 +3745,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3899,7 +3899,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4053,7 +4053,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4207,7 +4207,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4361,7 +4361,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4515,7 +4515,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4669,7 +4669,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4823,7 +4823,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4977,7 +4977,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5103,7 +5103,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5201,7 +5201,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_h.result b/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_h.result
index 956ea6c..4cf64df 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_h.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_h.result
@@ -203,7 +203,7 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
execute dump_stages_host;
@@ -212,14 +212,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -304,7 +304,7 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 0
@@ -318,14 +318,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -429,12 +429,12 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
execute dump_stages_host;
@@ -443,14 +443,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -545,12 +545,12 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 0
@@ -564,14 +564,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -685,17 +685,17 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
execute dump_stages_host;
@@ -704,14 +704,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -816,17 +816,17 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 0
@@ -840,14 +840,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -971,22 +971,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -995,14 +995,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -1113,22 +1113,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1137,14 +1137,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1255,22 +1255,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1279,14 +1279,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1396,22 +1396,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1420,14 +1420,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -1536,22 +1536,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -1560,14 +1560,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1677,22 +1677,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -1701,14 +1701,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1817,22 +1817,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -1841,14 +1841,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1957,22 +1957,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -1981,14 +1981,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2097,22 +2097,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2121,14 +2121,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2237,22 +2237,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2261,14 +2261,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2377,22 +2377,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2401,14 +2401,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2517,22 +2517,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2541,14 +2541,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2681,14 +2681,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2821,14 +2821,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2968,7 +2968,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3108,7 +3108,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3248,7 +3248,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3388,7 +3388,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3528,7 +3528,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3668,7 +3668,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3808,7 +3808,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3948,7 +3948,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4088,7 +4088,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4228,7 +4228,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4368,7 +4368,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4508,7 +4508,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4620,7 +4620,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4704,7 +4704,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u.result b/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u.result
index fbaa9a8..18ad75c 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u.result
@@ -217,21 +217,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -315,21 +315,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -425,21 +425,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -524,21 +524,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -635,21 +635,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -735,21 +735,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -847,21 +847,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 24
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -946,21 +946,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 25
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1045,21 +1045,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 26
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1143,21 +1143,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 27
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -1240,21 +1240,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1338,21 +1338,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1435,21 +1435,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1532,21 +1532,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1629,21 +1629,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1726,21 +1726,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1823,21 +1823,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1920,21 +1920,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2017,21 +2017,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2121,14 +2121,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2225,7 +2225,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2322,7 +2322,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2419,7 +2419,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2516,7 +2516,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2613,7 +2613,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2710,7 +2710,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2807,7 +2807,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2904,7 +2904,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3001,7 +3001,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3098,7 +3098,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3195,7 +3195,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3292,7 +3292,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3389,7 +3389,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3486,7 +3486,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u_no_h.result b/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u_no_h.result
index af53562..b80653c 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u_no_h.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_a_no_u_no_h.result
@@ -189,14 +189,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -273,14 +273,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -369,14 +369,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -454,14 +454,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -551,14 +551,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -637,14 +637,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -735,14 +735,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -820,14 +820,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -905,14 +905,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -989,14 +989,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -1072,14 +1072,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1156,14 +1156,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1239,14 +1239,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1322,14 +1322,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1405,14 +1405,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1488,14 +1488,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1571,14 +1571,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1654,14 +1654,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1737,14 +1737,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1820,14 +1820,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1910,7 +1910,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1993,7 +1993,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2076,7 +2076,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2159,7 +2159,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2242,7 +2242,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2325,7 +2325,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2408,7 +2408,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2491,7 +2491,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2574,7 +2574,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2657,7 +2657,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2740,7 +2740,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2823,7 +2823,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2906,7 +2906,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2989,7 +2989,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_h.result b/mysql-test/suite/perfschema/r/event_aggregate_no_h.result
index 1209d37..011e68e 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_h.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_h.result
@@ -219,14 +219,14 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
execute dump_stages_host;
@@ -235,14 +235,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -337,7 +337,7 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 0
@@ -349,7 +349,7 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 0
@@ -363,14 +363,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -491,24 +491,24 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
execute dump_stages_host;
@@ -517,14 +517,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -638,12 +638,12 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 0
@@ -655,12 +655,12 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 0
@@ -674,14 +674,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -821,34 +821,34 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
execute dump_stages_host;
@@ -857,14 +857,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -997,17 +997,17 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 0
@@ -1019,17 +1019,17 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 0
@@ -1043,14 +1043,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -1209,44 +1209,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 6
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1255,14 +1255,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -1408,44 +1408,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 6
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1454,14 +1454,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1607,44 +1607,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 6
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1653,14 +1653,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1805,44 +1805,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 6
execute dump_stages_host;
@@ -1851,14 +1851,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -2002,44 +2002,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2048,14 +2048,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2200,44 +2200,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2246,14 +2246,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2397,44 +2397,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2443,14 +2443,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2594,44 +2594,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2640,14 +2640,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2791,44 +2791,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -2837,14 +2837,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2988,44 +2988,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -3034,14 +3034,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3185,44 +3185,44 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -3231,14 +3231,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3404,22 +3404,22 @@ execute dump_stages_user;
user event_name count_star
user1 stage/sql/checking permissions 4
user1 stage/sql/closing tables 11
-user1 stage/sql/init 3
+user1 stage/sql/init 4
user1 stage/sql/Opening tables 7
user1 stage/sql/starting 7
user2 stage/sql/checking permissions 4
user2 stage/sql/closing tables 10
-user2 stage/sql/init 3
+user2 stage/sql/init 4
user2 stage/sql/Opening tables 6
user2 stage/sql/starting 7
user3 stage/sql/checking permissions 4
user3 stage/sql/closing tables 10
-user3 stage/sql/init 3
+user3 stage/sql/init 4
user3 stage/sql/Opening tables 6
user3 stage/sql/starting 7
user4 stage/sql/checking permissions 4
user4 stage/sql/closing tables 10
-user4 stage/sql/init 3
+user4 stage/sql/init 4
user4 stage/sql/Opening tables 6
user4 stage/sql/starting 7
execute dump_stages_host;
@@ -3428,14 +3428,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3625,14 +3625,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3822,14 +3822,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4026,7 +4026,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4223,7 +4223,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4420,7 +4420,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4617,7 +4617,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4814,7 +4814,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5011,7 +5011,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5208,7 +5208,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5405,7 +5405,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5602,7 +5602,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5799,7 +5799,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5996,7 +5996,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6165,7 +6165,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6278,7 +6278,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -6363,7 +6363,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_u.result b/mysql-test/suite/perfschema/r/event_aggregate_no_u.result
index 39da978..dba6860 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_u.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_u.result
@@ -231,7 +231,7 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -240,21 +240,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -346,7 +346,7 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 0
@@ -360,21 +360,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 4
localhost stage/sql/closing tables 11
-localhost stage/sql/init 3
+localhost stage/sql/init 4
localhost stage/sql/Opening tables 7
localhost stage/sql/starting 6
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -485,12 +485,12 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -499,21 +499,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -615,12 +615,12 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 0
@@ -634,21 +634,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 8
localhost stage/sql/closing tables 21
-localhost stage/sql/init 6
+localhost stage/sql/init 8
localhost stage/sql/Opening tables 13
localhost stage/sql/starting 12
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -769,17 +769,17 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -788,21 +788,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -914,17 +914,17 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 0
@@ -938,21 +938,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 12
localhost stage/sql/closing tables 31
-localhost stage/sql/init 9
+localhost stage/sql/init 12
localhost stage/sql/Opening tables 19
localhost stage/sql/starting 18
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -1083,22 +1083,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1107,21 +1107,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 24
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -1239,22 +1239,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1263,21 +1263,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 25
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1395,22 +1395,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1419,21 +1419,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 26
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1550,22 +1550,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1574,21 +1574,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 27
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -1704,22 +1704,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -1728,21 +1728,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1859,22 +1859,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -1883,21 +1883,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2013,22 +2013,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2037,21 +2037,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2167,22 +2167,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2191,21 +2191,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2321,22 +2321,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2345,21 +2345,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2475,22 +2475,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2499,21 +2499,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2629,22 +2629,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2653,21 +2653,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2807,21 +2807,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2961,21 +2961,21 @@ execute dump_stages_host;
host event_name count_star
localhost stage/sql/checking permissions 16
localhost stage/sql/closing tables 41
-localhost stage/sql/init 12
+localhost stage/sql/init 16
localhost stage/sql/Opening tables 25
localhost stage/sql/starting 28
execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3122,14 +3122,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3283,7 +3283,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3437,7 +3437,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3591,7 +3591,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3745,7 +3745,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3899,7 +3899,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4053,7 +4053,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4207,7 +4207,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4361,7 +4361,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4515,7 +4515,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4669,7 +4669,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4823,7 +4823,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4949,7 +4949,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5047,7 +5047,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -5145,7 +5145,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/mysql-test/suite/perfschema/r/event_aggregate_no_u_no_h.result b/mysql-test/suite/perfschema/r/event_aggregate_no_u_no_h.result
index 818c61e..428d290 100644
--- a/mysql-test/suite/perfschema/r/event_aggregate_no_u_no_h.result
+++ b/mysql-test/suite/perfschema/r/event_aggregate_no_u_no_h.result
@@ -201,7 +201,7 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -212,14 +212,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -302,7 +302,7 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 0
@@ -318,14 +318,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 4
stage/sql/closing tables 11
-stage/sql/init 3
+stage/sql/init 4
stage/sql/Opening tables 7
stage/sql/starting 6
execute dump_statements_account;
@@ -427,12 +427,12 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -443,14 +443,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -543,12 +543,12 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 0
@@ -564,14 +564,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 8
stage/sql/closing tables 21
-stage/sql/init 6
+stage/sql/init 8
stage/sql/Opening tables 13
stage/sql/starting 12
execute dump_statements_account;
@@ -683,17 +683,17 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -704,14 +704,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -814,17 +814,17 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 0
@@ -840,14 +840,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 12
stage/sql/closing tables 31
-stage/sql/init 9
+stage/sql/init 12
stage/sql/Opening tables 19
stage/sql/starting 18
execute dump_statements_account;
@@ -969,22 +969,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 6
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -995,14 +995,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 24
execute dump_statements_account;
@@ -1111,22 +1111,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 6
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1137,14 +1137,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 25
execute dump_statements_account;
@@ -1253,22 +1253,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 6
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1279,14 +1279,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 26
execute dump_statements_account;
@@ -1394,22 +1394,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 6
execute dump_stages_user;
@@ -1420,14 +1420,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 27
execute dump_statements_account;
@@ -1534,22 +1534,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -1560,14 +1560,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1675,22 +1675,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -1701,14 +1701,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1815,22 +1815,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -1841,14 +1841,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -1955,22 +1955,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -1981,14 +1981,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2095,22 +2095,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2121,14 +2121,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2235,22 +2235,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2261,14 +2261,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2375,22 +2375,22 @@ execute dump_stages_account;
user host event_name count_star
user1 localhost stage/sql/checking permissions 4
user1 localhost stage/sql/closing tables 11
-user1 localhost stage/sql/init 3
+user1 localhost stage/sql/init 4
user1 localhost stage/sql/Opening tables 7
user1 localhost stage/sql/starting 7
user2 localhost stage/sql/checking permissions 4
user2 localhost stage/sql/closing tables 10
-user2 localhost stage/sql/init 3
+user2 localhost stage/sql/init 4
user2 localhost stage/sql/Opening tables 6
user2 localhost stage/sql/starting 7
user3 localhost stage/sql/checking permissions 4
user3 localhost stage/sql/closing tables 10
-user3 localhost stage/sql/init 3
+user3 localhost stage/sql/init 4
user3 localhost stage/sql/Opening tables 6
user3 localhost stage/sql/starting 7
user4 localhost stage/sql/checking permissions 4
user4 localhost stage/sql/closing tables 10
-user4 localhost stage/sql/init 3
+user4 localhost stage/sql/init 4
user4 localhost stage/sql/Opening tables 6
user4 localhost stage/sql/starting 7
execute dump_stages_user;
@@ -2401,14 +2401,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2541,14 +2541,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2681,14 +2681,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2821,14 +2821,14 @@ execute dump_stages_global;
event_name count_star
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -2968,7 +2968,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3108,7 +3108,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3248,7 +3248,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3388,7 +3388,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3528,7 +3528,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3668,7 +3668,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3808,7 +3808,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -3948,7 +3948,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4088,7 +4088,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4228,7 +4228,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4368,7 +4368,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4480,7 +4480,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4564,7 +4564,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
@@ -4648,7 +4648,7 @@ execute dump_stages_history;
event_name count(event_name)
stage/sql/checking permissions 16
stage/sql/closing tables 41
-stage/sql/init 12
+stage/sql/init 16
stage/sql/Opening tables 25
stage/sql/starting 28
execute dump_statements_account;
diff --git a/sql/field.cc b/sql/field.cc
index 5a618a5..bff8e90 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1387,7 +1387,9 @@ bool Field::can_optimize_range(const Item_bool_func *cond,
{
DBUG_ASSERT(cmp_type() != TIME_RESULT); // Handled in Field_temporal
DBUG_ASSERT(cmp_type() != STRING_RESULT); // Handled in Field_str descendants
- return item->cmp_type() != TIME_RESULT;
+ return (item->cmp_type() != TIME_RESULT) &&
+ !(item->type() == Item::SUBSELECT_ITEM &&
+ ((Item_subselect *)item)->is_expensive());
}
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index fcdb2aa..c7295f1 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -5794,6 +5794,8 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
bool escape_used_in_parsing, CHARSET_INFO *cmp_cs,
int *escape)
{
+ if (thd->lex->context_analysis_only)
+ return false;
/*
ESCAPE clause accepts only constant arguments and Item_param.
@@ -5803,9 +5805,13 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
reach val_int(), so we won't need the value.
CONTEXT_ANALYSIS_ONLY_DERIVED being a notable exception here.
*/
+#if 0
if (!escape_item->const_during_execution() ||
(!escape_item->const_item() &&
!(thd->lex->context_analysis_only & ~CONTEXT_ANALYSIS_ONLY_DERIVED)))
+#else
+ if (!escape_item->const_item())
+#endif
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
return TRUE;
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 9e6c205..ff366ad 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1019,7 +1019,11 @@ table_map Item_subselect::used_tables() const
bool Item_subselect::const_item() const
{
DBUG_ASSERT(thd);
- return (thd->lex->context_analysis_only || with_recursive_reference ?
+ if (unit->executed_at_prepare_phase() && !thd->lex->context_analysis_only)
+ return true;
+ return (!(thd->lex->m_sql_cmd &&
+ thd->lex->m_sql_cmd->is_prepared()) ||
+ with_recursive_reference ?
FALSE :
forced_const || const_item_cache);
}
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index b284189..a22ed36 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -4214,6 +4214,8 @@ my_bool Query_cache::ask_handler_allowance(THD *thd,
for (; tables_used; tables_used= tables_used->next_global)
{
+ if (tables_used->is_view_or_derived())
+ continue;
TABLE *table;
handler *handler;
if (!(table= tables_used->table))
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index c6a929d..08dc375 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -643,6 +643,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
table_map_for_update(0),
m_examined_row_count(0),
accessed_rows_and_keys(0),
+ accessed_rows_and_keys_at_exec_start(0),
m_digest(NULL),
m_statement_psi(NULL),
m_transaction_psi(NULL),
diff --git a/sql/sql_class.h b/sql/sql_class.h
index b54f35a..e0c3256 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3420,6 +3420,7 @@ class THD: public THD_count, /* this must be first */
changed or written.
*/
ulonglong accessed_rows_and_keys;
+ ulonglong accessed_rows_and_keys_at_exec_start;
/**
Check if the number of rows accessed by a statement exceeded
@@ -3427,7 +3428,8 @@ class THD: public THD_count, /* this must be first */
*/
inline void check_limit_rows_examined()
{
- if (++accessed_rows_and_keys > lex->limit_rows_examined_cnt)
+ if ((++accessed_rows_and_keys - accessed_rows_and_keys_at_exec_start) >
+ lex->limit_rows_examined_cnt)
set_killed(ABORT_QUERY);
}
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 18d4b4b..c030fc2 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1655,7 +1655,6 @@ bool Sql_cmd_delete::prepare_inner(THD *thd)
if (!(join= new (thd->mem_root) JOIN(thd, empty_list,
select_options, result)))
DBUG_RETURN(TRUE);
- THD_STAGE_INFO(thd, stage_init);
select_lex->join= join;
thd->lex->used_tables=0;
if ((err= join->prepare(table_list, select_lex->where,
diff --git a/sql/sql_delete.h b/sql/sql_delete.h
index ad018ed..50d37ce 100644
--- a/sql/sql_delete.h
+++ b/sql/sql_delete.h
@@ -84,7 +84,7 @@ class Sql_cmd_delete final : public Sql_cmd_dml
private:
/**
- @biefSpecial handling of single-table deletes after prepare phase
+ @brief Special handling of single-table deletes after prepare phase
*/
bool delete_from_single_table(THD *thd);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 6e042d2..5228cff 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -5331,3 +5331,130 @@ void select_create::abort_result_set()
DBUG_VOID_RETURN;
}
+
+
+bool Sql_cmd_insert_base::precheck(THD *thd)
+{
+#if 0
+ /*
+ Since INSERT DELAYED doesn't support temporary tables, we could
+ not pre-open temporary tables for SQLCOM_INSERT / SQLCOM_REPLACE.
+ Open them here instead.
+ */
+ if (first_table->lock_type != TL_WRITE_DELAYED &&
+ thd->open_temporary_tables(lex->query_tables))
+ return true;
+
+ if (insert_precheck(thd, lex->query_tables))
+ return true;
+
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE);
+
+ return false;
+
+#ifdef WITH_WSREP
+wsrep_error_label:
+#endif
+#endif
+ return true;
+}
+
+
+bool Sql_cmd_insert_base::prepare_inner(THD *thd)
+{
+#if 0
+ SELECT_LEX *const select_lex= thd->lex->first_select_lex();
+ TABLE_LIST *const table_list= select_lex->get_table_list();
+ Name_resolution_context *context= &select_lex->context;
+ Name_resolution_context_state ctx_state;
+ const bool select_insert= insert_many_values.elements == 0;
+ bool insert_into_view= (table_list->view != 0);
+ TABLE *table;
+
+ DBUG_ENTER("Sql_cmd_insert_base::prepare_inner");
+
+ (void) read_statistics_for_tables_if_needed(thd, table_list);
+
+ {
+ if (mysql_handle_derived(lex, DT_INIT))
+ DBUG_RETURN(TRUE);
+ if (mysql_handle_derived(lex, DT_MERGE_FOR_INSERT))
+ DBUG_RETURN(TRUE);
+ if (mysql_handle_derived(lex, DT_PREPARE))
+ DBUG_RETURN(TRUE);
+ }
+
+ insert_field_list= thd->lex->field_list;
+
+ if (duplicates == DUP_UPDATE)
+ {
+ /* it should be allocated before Item::fix_fields() */
+ if (table_list->set_insert_values(thd->mem_root))
+ DBUG_RETURN(TRUE);
+ }
+
+ table= table_list->table;
+
+ if (table->file->check_if_updates_are_ignored("INSERT"))
+ DBUG_RETURN(-1);
+
+ if (!table_list->single_table_updatable())
+ {
+ my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT");
+ DBUG_RETURN(TRUE);
+ }
+
+ /*
+ first table in list is the one we'll INSERT into, requires INSERT_ACL.
+ all others require SELECT_ACL only. the ACL requirement below is for
+ new leaves only anyway (view-constituents), so check for SELECT rather
+ than INSERT.
+ */
+ if (setup_tables_and_check_access(thd,
+ &select_lex->context,
+ &select_lex->top_join_list,
+ table_list,
+ select_lex->leaf_tables,
+ select_insert, INSERT_ACL, SELECT_ACL,
+ TRUE))
+ DBUG_RETURN(TRUE);
+
+ if (insert_into_view && !insert_field_list.elements)
+ {
+ thd->lex->empty_field_list_on_rset= 1;
+ if (!table_list->table || table_list->is_multitable())
+ {
+ my_error(ER_VIEW_NO_INSERT_FIELD_LIST, MYF(0),
+ table_list->view_db.str, table_list->view_name.str);
+ DBUG_RETURN(TRUE);
+ }
+ if (insert_view_fields(thd, &insert_field_list, table_list))
+ DBUG_RETURN(TRUE);
+ }
+
+ if (thd->lex->has_returning())
+ {
+ status_var_increment(thd->status_var.feature_insert_returning);
+
+ /* This is INSERT ... RETURNING. It will return output to the client */
+ if (thd->lex->analyze_stmt)
+ {
+ /*
+ Actually, it is ANALYZE .. INSERT .. RETURNING. We need to produce
+ output and then discard it.
+ */
+ result= new (thd->mem_root) select_send_analyze(thd);
+ save_protocol= thd->protocol;
+ thd->protocol= new Protocol_discard(thd);
+ }
+ else
+ {
+ if (!(result= new (thd->mem_root) select_send(thd)))
+ DBUG_RETURN(TRUE);
+ }
+ }
+#else
+ return false;
+#endif
+}
+
diff --git a/sql/sql_insert.h b/sql/sql_insert.h
index 8b034c2..eae3b53 100644
--- a/sql/sql_insert.h
+++ b/sql/sql_insert.h
@@ -18,6 +18,7 @@
#include "sql_class.h" /* enum_duplicates */
#include "sql_list.h"
+#include "sql_base.h"
/* Instead of including sql_lex.h we add this typedef here */
typedef List<Item> List_item;
@@ -51,4 +52,139 @@ bool binlog_drop_table(THD *thd, TABLE *table);
inline void kill_delayed_threads(void) {}
#endif
+
+/**
+ Base class for all INSERT and REPLACE statements. Abstract class that
+ is inherited by Sql_cmd_insert_values and Sql_cmd_insert_select.
+*/
+
+class Sql_cmd_insert_base : public Sql_cmd_dml
+{
+protected:
+ virtual bool precheck(THD *thd) override;
+
+ virtual bool prepare_inner(THD *thd) override;
+
+private:
+ bool resolve_update_expressions(THD *thd);
+ bool prepare_values_table(THD *thd);
+ bool resolve_values_table_columns(THD *thd);
+
+ /**
+ Field list to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... (col1, ... colN) VALUES ... syntax
+ this is a list of col1, ..., colN fields.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this is a list of col1, ... colM fields as well.
+ */
+ List<Item> insert_field_list;
+
+public:
+ /*
+ field_list was created for view and should be removed before PS/SP
+ rexecuton
+ */
+ bool empty_field_list_on_rset;
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+ const bool is_replace;
+
+ /**
+ Row data to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... VALUES (row1), (row2), ... (rowN) syntax
+ the list contains N List_item lists: one List_item per row.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this list contains only 1 List_item of M data values: this way we
+ emulate this syntax:
+ INSERT/REPLACE ... (col1, ... colM) VALUE (x1, ..., xM);
+ */
+ List<List_item> insert_many_values;
+
+ /*
+ Number of values per row in insert_many_values, available after resolving
+ */
+ uint value_count;
+
+ /* ON DUPLICATE KEY UPDATE field list */
+ List<Item> update_field_list;
+
+ const enum_duplicates duplicates;
+
+ Protocol *save_protocol; /**< needed for ANALYZE .. INSERT .. RETURNING */
+
+ explicit Sql_cmd_insert_base(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : empty_field_list_on_rset(false),
+ is_replace(is_replace_arg),
+ value_count(0),
+ duplicates(duplicates_arg),
+ save_protocol(NULL)
+ {}
+
+#if 0
+ virtual void cleanup(THD *thd) override
+ {
+ if (empty_field_list_on_rset)
+ {
+ empty_field_list_on_rset = false;
+ insert_field_list.empty();
+ }
+ }
+#endif
+
+private:
+
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+};
+
+
+/**
+ Class that implements INSERT ... VALUES and REPLACE ... VALUES statements.
+*/
+
+class Sql_cmd_insert_values final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_values(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE : SQLCOM_INSERT;
+ }
+
+};
+
+
+/**
+ Class that implements INSERT ... SELECT and REPLACE ... SELECT statements.
+*/
+
+class Sql_cmd_insert_select final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_select(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE_SELECT : SQLCOM_INSERT_SELECT;
+ }
+};
+
+
+
#endif /* SQL_INSERT_INCLUDED */
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 8a24d2f..0b08fbc 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -42,6 +42,8 @@
#endif
#include "sql_update.h" // class Sql_cmd_update
#include "sql_delete.h" // class Sql_cmd_delete
+#include "sql_insert.h" // class Sql_cmd_insert
+
void LEX::parse_error(uint err_number)
{
@@ -10357,13 +10359,19 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit)
bool LEX::parsed_insert_select(SELECT_LEX *first_select)
{
+ bool is_insert_or_replace= false;
+ bool is_replace= false;
if (sql_command == SQLCOM_INSERT ||
sql_command == SQLCOM_REPLACE)
{
+ is_insert_or_replace= true;
if (sql_command == SQLCOM_INSERT)
sql_command= SQLCOM_INSERT_SELECT;
else
+ {
+ is_replace= true;
sql_command= SQLCOM_REPLACE_SELECT;
+ }
}
insert_select_hack(first_select);
if (check_main_unit_semantics())
@@ -10373,6 +10381,23 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
SELECT_LEX *blt __attribute__((unused))= pop_select();
DBUG_ASSERT(blt == &builtin_select);
push_select(first_select);
+
+ if (is_insert_or_replace)
+ {
+ if (sql_command == SQLCOM_INSERT || sql_command == SQLCOM_REPLACE)
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_values(is_replace,
+ duplicates)))
+ return true;
+ }
+ else
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_select(is_replace,
+ duplicates)))
+ return true;
+ }
+ }
+
return false;
}
@@ -10454,6 +10479,8 @@ bool LEX::select_finalize(st_select_lex_unit *expr)
{
sql_command= SQLCOM_SELECT;
selects_allow_procedure= TRUE;
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_select(result)))
+ return true;
if (set_main_unit(expr))
return true;
return check_main_unit_semantics();
@@ -11933,3 +11960,27 @@ bool SELECT_LEX_UNIT::is_derived_eliminated() const
return true;
return derived->table->map & outer_select()->join->eliminated_tables;
}
+
+bool SELECT_LEX_UNIT::executed_at_prepare_phase()
+{
+ for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
+ {
+ if (!sl->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
+
+bool SELECT_LEX::executed_at_prepare_phase()
+{
+ if (table_list.elements || is_correlated)
+ return false;
+ for (st_select_lex_unit *unit= first_inner_unit();
+ unit;
+ unit= unit->next_unit())
+ {
+ if (!unit->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 5a7fa14..491ea1c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1034,6 +1034,8 @@ class st_select_lex_unit: public st_select_lex_node {
bool explainable() const;
+ bool executed_at_prepare_phase();
+
void reset_distinct();
void fix_distinct();
@@ -1480,6 +1482,8 @@ class st_select_lex: public st_select_lex_node
ORDER *order,
enum_query_type query_type);
void print_limit(THD *thd, String *str, enum_query_type query_type);
+ bool prepare(THD *thd, select_result *result);
+ bool exec(THD *thd);
void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
/*
Destroy the used execution plan (JOIN) of this subtree (this
@@ -1653,6 +1657,7 @@ class st_select_lex: public st_select_lex_node
bool is_unit_nest() { return (nest_flags & UNIT_NEST_FL); }
void mark_as_unit_nest() { nest_flags= UNIT_NEST_FL; }
bool is_sj_conversion_prohibited(THD *thd);
+ bool executed_at_prepare_phase();
};
typedef class st_select_lex SELECT_LEX;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 67353a1..c7bc972 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3907,7 +3907,9 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SHOW_STORAGE_ENGINES:
case SQLCOM_SHOW_PROFILE:
+#if 0
case SQLCOM_SELECT:
+#endif
{
#ifdef WITH_WSREP
if (lex->sql_command == SQLCOM_SELECT)
@@ -4382,6 +4384,17 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
break;
}
+ case SQLCOM_SELECT:
+ {
+ res = lex->m_sql_cmd->execute(thd);
+ break;
+ }
+#if 0
+ case SQLCOM_REPLACE:
+ case SQLCOM_INSERT:
+ case SQLCOM_REPLACE_SELECT:
+ case SQLCOM_INSERT_SELECT:
+#endif
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
case SQLCOM_DELETE:
@@ -4394,6 +4407,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
thd->abort_on_warning= 0;
break;
}
+#if 1
case SQLCOM_REPLACE:
if ((res= generate_incident_event(thd)))
break;
@@ -4653,6 +4667,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
break;
}
+#endif
case SQLCOM_DROP_SEQUENCE:
case SQLCOM_DROP_TABLE:
{
@@ -7340,6 +7355,7 @@ void THD::reset_for_next_command(bool do_clear_error)
get_stmt_da()->reset_for_next_command();
m_sent_row_count= m_examined_row_count= 0;
accessed_rows_and_keys= 0;
+ accessed_rows_and_keys_at_exec_start= 0;
reset_slow_query_state();
@@ -7476,6 +7492,8 @@ void create_select_for_variable(THD *thd, LEX_CSTRING *var_name)
lex= thd->lex;
lex->init_select();
lex->sql_command= SQLCOM_SELECT;
+ lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_select(thd->lex->result);
+
/*
We set the name of Item to @@session.var_name because that then is used
as the column name in the output.
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 22780c8..0bbde42 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2268,6 +2268,48 @@ static bool check_prepared_statement(Prepared_statement *stmt)
lex->m_sql_cmd->unprepare(thd);
break;
+ case SQLCOM_SELECT:
+#if 0
+ if (lex->m_sql_cmd == NULL &&
+ !(lex->m_sql_cmd=
+ new (thd->mem_root) Sql_cmd_select(thd->lex->result)))
+ {
+ res= 1;
+ break;
+ }
+#endif
+ lex->m_sql_cmd->set_owner(stmt);
+ res = lex->m_sql_cmd->prepare(thd);
+ if (res == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ if (!res && !lex->describe && !lex->analyze_stmt && !stmt->is_sql_prepare())
+ {
+ SELECT_LEX_UNIT *const unit = &lex->unit;
+ /* Make copy of item list, as change_columns may change it */
+ SELECT_LEX_UNIT* master_unit= unit->first_select()->master_unit();
+ bool is_union_op=
+ master_unit->is_unit_op() || master_unit->fake_select_lex;
+
+ List<Item> fields(is_union_op ? unit->item_list :
+ lex->first_select_lex()->item_list);
+
+ /* Change columns if a procedure like analyse() */
+ res= (unit->last_procedure &&
+ unit->last_procedure->change_columns(thd, fields));
+
+ if (res || send_prep_stmt(stmt, lex->result->field_count(fields)) ||
+ lex->result->send_result_set_metadata(fields,
+ Protocol::SEND_EOF) ||
+ thd->protocol->flush())
+ res= true;
+ }
+ if (!res)
+ lex->m_sql_cmd->unprepare(thd);
+ break;
+
/* The following allow WHERE clause, so they must be tested like SELECT */
case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_TABLES:
@@ -2285,7 +2327,9 @@ static bool check_prepared_statement(Prepared_statement *stmt)
case SQLCOM_SHOW_STATUS_FUNC:
case SQLCOM_SHOW_STATUS_PACKAGE:
case SQLCOM_SHOW_STATUS_PACKAGE_BODY:
+#if 0
case SQLCOM_SELECT:
+#endif
res= mysql_test_select(stmt, tables);
if (res == 2)
{
@@ -2469,12 +2513,14 @@ static bool check_prepared_statement(Prepared_statement *stmt)
lex->describe, lex->analyze_stmt) ||
send_prep_stmt(stmt, result.field_count(field_list)) ||
result.send_result_set_metadata(field_list,
- Protocol::SEND_EOF);
+ Protocol::SEND_EOF) ||
+ thd->protocol->flush();
+ }
+ else if (lex->sql_command != SQLCOM_SELECT)
+ {
+ res= send_prep_stmt(stmt, 0) ||
+ thd->protocol->flush();
}
- else
- res= send_prep_stmt(stmt, 0);
- if (!res)
- thd->protocol->flush();
}
DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 4b01a96..26354d3 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -55,6 +55,9 @@
#include "sql_cte.h"
#include "sql_window.h"
#include "tztime.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
#include "debug_sync.h" // DEBUG_SYNC
#include <m_ctype.h>
@@ -4989,21 +4992,22 @@ void JOIN::cleanup_item_list(List<Item> &items) const
0 otherwise
*/
-select_handler *find_select_handler(THD *thd,
- SELECT_LEX* select_lex)
+select_handler *SELECT_LEX::find_select_handler(THD *thd)
{
- if (select_lex->next_select())
+ if (next_select())
return 0;
- if (select_lex->master_unit()->outer_select())
+ if (master_unit()->outer_select())
return 0;
TABLE_LIST *tbl= nullptr;
- // For SQLCOM_INSERT_SELECT the server takes TABLE_LIST
- // from thd->lex->query_tables and skips its first table
- // b/c it is the target table for the INSERT..SELECT.
+ /*
+ For SQLCOM_INSERT_SELECT the server takes TABLE_LIST
+ from thd->lex->query_tables and skips its first table
+ b/c it is the target table for the INSERT..SELECT.
+ */
if (thd->lex->sql_command != SQLCOM_INSERT_SELECT)
{
- tbl= select_lex->join->tables_list;
+ tbl= join->tables_list;
}
else if (thd->lex->query_tables &&
thd->lex->query_tables->next_global)
@@ -5020,7 +5024,7 @@ select_handler *find_select_handler(THD *thd,
handlerton *ht= tbl->table->file->partition_ht();
if (!ht->create_select)
continue;
- select_handler *sh= ht->create_select(thd, select_lex);
+ select_handler *sh= ht->create_select(thd, this);
return sh;
}
return 0;
@@ -5125,7 +5129,6 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
if (!(join= new (thd->mem_root) JOIN(thd, fields, select_options, result)))
DBUG_RETURN(TRUE);
- THD_STAGE_INFO(thd, stage_init);
thd->lex->used_tables=0;
if ((err= join->prepare(tables, conds, og_num, order, false, group, having,
proc_param, select_lex, unit)))
@@ -5136,7 +5139,7 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
thd->get_stmt_da()->reset_current_row_for_warning(1);
/* Look for a table owned by an engine with the select_handler interface */
- select_lex->pushdown_select= find_select_handler(thd, select_lex);
+ select_lex->pushdown_select= select_lex->find_select_handler(thd);
if ((err= join->optimize()))
{
@@ -12720,7 +12723,8 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
(select thats very heavy) => is a constant here
eg: (select avg(order_cost) from orders) => constant but expensive
*/
- if (!keyuse->val->used_tables() && !thd->lex->describe)
+ if (keyuse->val->const_item() && !keyuse->val->is_expensive() &&
+ !thd->lex->describe)
{ // Compare against constant
store_key_item tmp(thd,
keyinfo->key_part[i].field,
@@ -32348,6 +32352,9 @@ static void MYSQL_DML_START(THD *thd)
{
switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ MYSQL_INSERT_START(thd->query());
+ break;
case SQLCOM_UPDATE:
MYSQL_UPDATE_START(thd->query());
break;
@@ -32370,6 +32377,9 @@ static void MYSQL_DML_DONE(THD *thd, int rc)
{
switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ MYSQL_SELECT_DONE(rc, (rc ? 0 : (ulong) (thd->limit_found_rows)));
+ break;
case SQLCOM_UPDATE:
MYSQL_UPDATE_DONE(
rc,
@@ -32437,8 +32447,6 @@ bool Sql_cmd_dml::prepare(THD *thd)
MYSQL_DML_START(thd);
- lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_DERIVED;
-
if (open_tables_for_query(thd, lex->query_tables, &table_count, 0,
get_dml_prelocking_strategy()))
{
@@ -32451,8 +32459,6 @@ bool Sql_cmd_dml::prepare(THD *thd)
if (prepare_inner(thd))
goto err;
- lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_DERIVED;
-
set_prepared();
unit->set_prepared();
@@ -32528,6 +32534,7 @@ bool Sql_cmd_dml::execute(THD *thd)
{
if (lock_tables(thd, lex->query_tables, table_count, 0))
goto err;
+ query_cache_store_query(thd, thd->lex->query_tables);
}
unit->set_limit(select_lex);
@@ -32581,8 +32588,266 @@ bool Sql_cmd_dml::execute(THD *thd)
bool Sql_cmd_dml::execute_inner(THD *thd)
{
SELECT_LEX_UNIT *unit = &lex->unit;
- SELECT_LEX *select_lex= unit->first_select();
- JOIN *join= select_lex->join;
+ DBUG_ENTER("Sql_cmd_dml::execute_inner");
+
+ if (unit->is_unit_op() || unit->fake_select_lex)
+ {
+ if (unit->exec())
+ DBUG_RETURN(true);
+ }
+#if 1
+ else
+ {
+ SELECT_LEX *select_lex= unit->first_select();
+ if (select_lex->exec(thd))
+ DBUG_RETURN(true);
+ }
+#endif
+
+ DBUG_RETURN(false);
+}
+
+
+bool Sql_cmd_select::precheck(THD *thd)
+{
+ bool rc= false;
+
+ privilege_t privileges_requested= SELECT_ACL;
+
+ if (lex->exchange)
+ {
+ /*
+ lex->exchange != NULL implies SELECT .. INTO OUTFILE and this
+ requires FILE_ACL access.
+ */
+ privileges_requested|= FILE_ACL;
+ }
+
+ TABLE_LIST *tables = thd->lex->query_tables;
+
+ if (tables)
+ rc= check_table_access(thd, privileges_requested,
+ tables, false, UINT_MAX, false);
+ else
+ rc= check_access(thd, privileges_requested,
+ any_db.str, NULL, NULL, false, false);
+
+#ifdef WITH_WSREP
+ if (lex->sql_command == SQLCOM_SELECT)
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_READ);
+ }
+ else
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW);
+# ifdef ENABLED_PROFILING
+ if (lex->sql_command == SQLCOM_SHOW_PROFILE)
+ thd->profiling.discard_current_query();
+# endif
+ }
+#endif /* WITH_WSREP */
+
+ if (!rc)
+ return false;
+
+#ifdef WITH_WSREP
+wsrep_error_label:
+#endif
+ return true;
+}
+
+
+
+bool Sql_cmd_select::prepare_inner(THD *thd)
+{
+ bool rc= false;
+ LEX *lex= thd->lex;
+ TABLE_LIST *tables= lex->query_tables;
+ SELECT_LEX_UNIT *const unit = &lex->unit;
+
+ DBUG_ENTER("Sql_cmd_select::prepare_inner");
+
+ if (!thd->stmt_arena->is_stmt_prepare())
+ (void) read_statistics_for_tables_if_needed(thd, tables);
+
+ {
+ if (mysql_handle_derived(lex, DT_INIT))
+ DBUG_RETURN(TRUE);
+ }
+
+ if (thd->stmt_arena->is_stmt_prepare())
+ {
+ if (!result)
+ {
+ Query_arena backup;
+ Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup);
+ result= new (thd->mem_root) select_send(thd);
+ if (arena)
+ thd->restore_active_arena(arena, &backup);
+ thd->lex->result= result;
+ }
+ rc= unit->prepare(unit->derived, 0, 0);
+
+ }
+ else
+ {
+ if (lex->analyze_stmt)
+ {
+ if (result && result->result_interceptor())
+ result->result_interceptor()->disable_my_ok_calls();
+ else
+ {
+ DBUG_ASSERT(thd->protocol);
+ result= new (thd->mem_root) select_send_analyze(thd);
+ save_protocol= thd->protocol;
+ thd->protocol= new Protocol_discard(thd);
+ }
+ }
+ else if (!(result= lex->result))
+ result= new (thd->mem_root) select_send(thd);
+ if (!result)
+ DBUG_RETURN(TRUE);
+
+ SELECT_LEX *parameters = unit->global_parameters();
+ if (!parameters->limit_params.explicit_limit)
+ {
+ parameters->limit_params.select_limit =
+ new (thd->mem_root) Item_int(thd,
+ (ulonglong) thd->variables.select_limit);
+ if (parameters->limit_params.select_limit == NULL)
+ DBUG_RETURN(true); /* purecov: inspected */
+ }
+ ulonglong select_options= 0;
+ if (lex->describe)
+ select_options|= SELECT_DESCRIBE;
+ if (unit->is_unit_op() || unit->fake_select_lex)
+ select_options|= SELECT_NO_UNLOCK;
+ rc= unit->prepare(unit->derived, result, select_options);
+
+ if (rc && thd->lex->analyze_stmt && save_protocol)
+ {
+ delete thd->protocol;
+ thd->protocol= save_protocol;
+ }
+ }
+
+ DBUG_RETURN(rc);
+}
+
+
+bool Sql_cmd_select::execute_inner(THD *thd)
+{
+ DBUG_ENTER("Sql_cmd_select::execute_inner");
+
+ thd->status_var.last_query_cost= 0.0;
+
+ bool res= Sql_cmd_dml::execute_inner(thd);
+
+ res|= thd->is_error();
+ if (unlikely(res))
+ result->abort_result_set();
+
+ if (result != thd->lex->result)
+ {
+ delete result;
+ result= 0;
+ }
+
+ if (lex->analyze_stmt)
+ {
+ if (save_protocol)
+ {
+ delete thd->protocol;
+ thd->protocol= save_protocol;
+ }
+ if (!res)
+ res= thd->lex->explain->send_explain(thd);
+ }
+
+ if (thd->lex->describe)
+ {
+ if (!res)
+ res= thd->lex->explain->send_explain(thd);
+
+ if (!res && (thd->lex->describe & DESCRIBE_EXTENDED))
+ {
+ char buff[1024];
+ String str(buff,(uint32) sizeof(buff), system_charset_info);
+ str.length(0);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str.c_ptr_safe());
+ }
+ }
+
+ if (unlikely(thd->killed == ABORT_QUERY && !thd->no_errors))
+ {
+ /*
+ If LIMIT ROWS EXAMINED interrupted query execution, issue a warning,
+ continue with normal processing and produce an incomplete query result.
+ */
+ bool saved_abort_on_warning= thd->abort_on_warning;
+ thd->abort_on_warning= false;
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT,
+ ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT),
+ thd->accessed_rows_and_keys -
+ thd->accessed_rows_and_keys_at_exec_start,
+ thd->lex->limit_rows_examined->val_uint());
+ thd->abort_on_warning= saved_abort_on_warning;
+ thd->reset_killed();
+ }
+ /* Disable LIMIT ROWS EXAMINED after query execution. */
+ thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX;
+
+ /* Count number of empty select queries */
+ if (!thd->get_sent_row_count() && !res)
+ status_var_increment(thd->status_var.empty_queries);
+ else
+ status_var_add(thd->status_var.rows_sent, thd->get_sent_row_count());
+
+ DBUG_RETURN(res);
+}
+
+
+bool st_select_lex::prepare(THD *thd, select_result *result)
+{
+ ulonglong select_options= options | thd->variables.option_bits;
+
+ DBUG_ENTER("st_select_lex::prepare");
+
+ if (thd->lex->describe)
+ select_options|= SELECT_DESCRIBE;
+
+ if (!(join= new (thd->mem_root) JOIN(thd, item_list,
+ select_options, result)))
+ DBUG_RETURN(true);
+
+ SELECT_LEX_UNIT *unit= master_unit();
+
+ thd->lex->used_tables=0;
+
+ if (join->prepare(table_list.first, where,
+ order_list.elements + group_list.elements,
+ order_list.first, false, group_list.first,
+ having, thd->lex->proc_list.first,
+ this, unit))
+ DBUG_RETURN(true);
+
+ DBUG_RETURN(false);
+}
+
+
+bool st_select_lex::exec(THD *thd)
+{
+ DBUG_ENTER("st_select_lex::exec");
+
+ /* Look for a table owned by an engine with the select_handler interface */
+ pushdown_select= find_select_handler(thd);
if (join->optimize())
goto err;
@@ -32596,19 +32861,29 @@ bool Sql_cmd_dml::execute_inner(THD *thd)
if (unlikely(thd->is_error()))
goto err;
+ thd->get_stmt_da()->reset_current_row_for_warning(1);
+
+ if (master_unit()->outer_select() == NULL)
+ thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys;
+
if (join->exec())
goto err;
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
- select_lex->where= join->conds_history;
- select_lex->having= join->having_history;
+ where= join->conds_history;
+ having= join->having_history;
}
err:
- return join->error;
-}
+ if (pushdown_select)
+ {
+ delete pushdown_select;
+ pushdown_select= NULL;
+ }
+ DBUG_RETURN(join->error);
+}
/**
@} (end of group Query_Optimizer)
diff --git a/sql/sql_select.h b/sql/sql_select.h
index f908484..edbaed3 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -33,6 +33,8 @@
#include "records.h" /* READ_RECORD */
#include "opt_range.h" /* SQL_SELECT, QUICK_SELECT_I */
#include "filesort.h"
+#include "sql_base.h"
+#include "sql_cmd.h"
typedef struct st_join_table JOIN_TAB;
/* Values in optimize */
@@ -2629,4 +2631,39 @@ void propagate_new_equalities(THD *thd, Item *cond,
bool *is_simplifiable_cond);
bool dbug_user_var_equals_str(THD *thd, const char *name, const char *value);
+
+
+class Sql_cmd_select : public Sql_cmd_dml
+{
+public:
+ explicit Sql_cmd_select(select_result *result_arg)
+ : Sql_cmd_dml(), save_protocol(NULL)
+ { result= result_arg; }
+
+ enum_sql_command sql_command_code() const override
+ {
+ return SQLCOM_SELECT;
+ }
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+
+ bool precheck(THD *thd) override;
+
+ bool prepare_inner(THD *thd) override;
+
+ bool execute_inner(THD *thd) override;
+
+private:
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+ Protocol *save_protocol;
+};
+
+
#endif /* SQL_SELECT_INCLUDED */
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index c1f28ba..0cc1e68 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1322,6 +1322,24 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
describe= additional_options & SELECT_DESCRIBE;
+ if (describe)
+ {
+ for (SELECT_LEX *sl= first_sl; sl; sl= sl->next_select())
+ {
+ sl->set_explain_type(FALSE);
+ sl->options|= SELECT_DESCRIBE;
+ }
+ if (is_unit_op() || fake_select_lex)
+ {
+ if (union_needs_tmp_table() && fake_select_lex)
+ {
+ fake_select_lex->select_number= FAKE_SELECT_LEX_ID; // just for initialization
+ fake_select_lex->type= unit_operation_text[common_op()];
+ fake_select_lex->options|= SELECT_DESCRIBE;
+ }
+ }
+ }
+
/*
Save fake_select_lex in case we don't need it for anything but
global parameters.
@@ -2160,6 +2178,8 @@ bool st_select_lex_unit::exec()
bool was_executed= executed;
DBUG_ENTER("st_select_lex_unit::exec");
+ describe= thd->lex->describe;
+
if (executed && !uncacheable && !describe)
DBUG_RETURN(FALSE);
executed= 1;
@@ -2168,6 +2188,9 @@ bool st_select_lex_unit::exec()
item->make_const();
saved_error= optimize();
+
+ if (outer_select() == NULL)
+ thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys;
create_explain_query_if_not_exists(thd->lex, thd->mem_root);
@@ -2239,6 +2262,7 @@ bool st_select_lex_unit::exec()
saved_error= sl->join->optimize();
}
}
+
if (likely(!saved_error))
{
records_at_start= table->file->stats.records;
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index ff1d70e..c6815c9 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -2979,7 +2979,6 @@ bool Sql_cmd_update::prepare_inner(THD *thd)
if (!(join= new (thd->mem_root) JOIN(thd, select_lex->item_list,
select_options, result)))
DBUG_RETURN(TRUE);
- THD_STAGE_INFO(thd, stage_init);
select_lex->join= join;
thd->lex->used_tables=0;
select_lex->item_list_usage= MARK_COLUMNS_WRITE;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 49655f8..886c0b6 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -71,6 +71,7 @@
#include "json_table.h"
#include "sql_update.h"
#include "sql_delete.h"
+#include "sql_insert.h"
/* this is to get the bison compilation windows warnings out */
#ifdef _MSC_VER
1
0
[Commits] 5d2a36f: MDEV-29971 Re-design the upper level of handling SELECT statements
by IgorBabaev 17 Mar '23
by IgorBabaev 17 Mar '23
17 Mar '23
revision-id: 5d2a36f33b2d89c680804a4c088c25bf3e56321f (mariadb-11.0.1-36-g5d2a36f)
parent(s): fc18f9c9ec15035894154fb7dcdd85caac73cfc2
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-16 16:20:05 -0700
message:
MDEV-29971 Re-design the upper level of handling SELECT statements
The initial patch.
All tests from the main test suite passed.
---
mysql-test/main/explain.result | 16 +-
mysql-test/main/explain.test | 2 +-
mysql-test/main/func_like.result | 8 -
mysql-test/main/func_like.test | 12 +-
mysql-test/main/grant_cache_no_prot.result | 4 +-
mysql-test/main/limit_rows_examined.result | 14 +-
mysql-test/main/limit_rows_examined.test | 8 +-
mysql-test/main/outfile.result | Bin 2323 -> 2309 bytes
mysql-test/main/outfile.test | 1 +
mysql-test/main/subselect_mat.result | 2 +-
mysql-test/main/type_year.result | 1 -
sql/field.cc | 4 +-
sql/item_cmpfunc.cc | 6 +
sql/item_subselect.cc | 6 +-
sql/sql_cache.cc | 2 +
sql/sql_class.cc | 1 +
sql/sql_class.h | 4 +-
sql/sql_delete.h | 2 +-
sql/sql_insert.cc | 127 ++++++++++++
sql/sql_insert.h | 136 ++++++++++++
sql/sql_lex.cc | 51 +++++
sql/sql_lex.h | 5 +
sql/sql_parse.cc | 18 ++
sql/sql_prepare.cc | 56 ++++-
sql/sql_select.cc | 318 +++++++++++++++++++++++++++--
sql/sql_select.h | 37 ++++
sql/sql_union.cc | 24 +++
sql/sql_yacc.yy | 1 +
28 files changed, 809 insertions(+), 57 deletions(-)
diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result
index 1e546d4..7469fdb 100644
--- a/mysql-test/main/explain.result
+++ b/mysql-test/main/explain.result
@@ -379,7 +379,21 @@ PREPARE s FROM
SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
EXECUTE s;
-ERROR 21000: Subquery returns more than 1 row
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null)))
+EXECUTE s;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null)))
DEALLOCATE PREPARE s;
DROP TABLE t1;
#
diff --git a/mysql-test/main/explain.test b/mysql-test/main/explain.test
index 0e4a3b8..8abfee4 100644
--- a/mysql-test/main/explain.test
+++ b/mysql-test/main/explain.test
@@ -301,7 +301,7 @@ PREPARE s FROM
SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
---error ER_SUBQUERY_NO_1_ROW
+EXECUTE s;
EXECUTE s;
DEALLOCATE PREPARE s;
diff --git a/mysql-test/main/func_like.result b/mysql-test/main/func_like.result
index ba053ea..8031b03 100644
--- a/mysql-test/main/func_like.result
+++ b/mysql-test/main/func_like.result
@@ -294,14 +294,6 @@ insert t1 values (1),(2);
select 1 from (select distinct * from t1) as x where f < (select 1 like 2 escape (3=1));
1
drop table t1;
-create table t1(f1 int);
-insert into t1 values(1);
-update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
-ERROR HY000: Incorrect arguments to ESCAPE
-select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
-1 like 2 escape (1 in (select 1 from t1))
-0
-drop table t1;
create table t1 (f int);
insert t1 values (1),(2);
create view v1 as select * from t1 where (1 like 2 escape (3 in (('h', 'b') in (select 'k', 'k' union select 'g', 'j'))) and f >= 0);
diff --git a/mysql-test/main/func_like.test b/mysql-test/main/func_like.test
index 7339743..f9d92a7 100644
--- a/mysql-test/main/func_like.test
+++ b/mysql-test/main/func_like.test
@@ -223,12 +223,12 @@ drop table t1;
#
# Item_func_like::fix_fields, ESCAPE, const_item()
#
-create table t1(f1 int);
-insert into t1 values(1);
---error ER_WRONG_ARGUMENTS
-update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
-select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
-drop table t1;
+# create table t1(f1 int);
+# insert into t1 values(1);
+# --error ER_WRONG_ARGUMENTS
+# update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
+# select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
+# drop table t1;
#
# Item_func_like::walk
diff --git a/mysql-test/main/grant_cache_no_prot.result b/mysql-test/main/grant_cache_no_prot.result
index daf382d..0fde04a 100644
--- a/mysql-test/main/grant_cache_no_prot.result
+++ b/mysql-test/main/grant_cache_no_prot.result
@@ -192,7 +192,7 @@ Variable_name Value
Qcache_hits 7
show status like "Qcache_not_cached";
Variable_name Value
-Qcache_not_cached 4
+Qcache_not_cached 3
connect user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK;
connection user4;
select "user4";
@@ -225,7 +225,7 @@ Variable_name Value
Qcache_hits 8
show status like "Qcache_not_cached";
Variable_name Value
-Qcache_not_cached 5
+Qcache_not_cached 4
connection root;
disconnect root;
connection root2;
diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result
index 9d3d5bb..fb91784 100644
--- a/mysql-test/main/limit_rows_examined.result
+++ b/mysql-test/main/limit_rows_examined.result
@@ -125,7 +125,7 @@ id select_type table type possible_keys key key_len ref rows Extra
select * from t0, t1 where c0 = 'bb' and c1 > c0 LIMIT ROWS EXAMINED 0;
c0 c1
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete
set @@join_cache_level = @save_join_cache_level;
drop table t0;
=========================================================================
@@ -675,7 +675,7 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0);
EXPLAIN
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
@@ -683,10 +683,12 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
field1
+USA
+CAN
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 21 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 16 rows, which exceeds LIMIT ROWS EXAMINED (15). The query result may be incomplete
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
id select_type table type possible_keys key key_len ref rows Extra
@@ -827,13 +829,15 @@ CREATE TABLE t2 ( b INT, c INT, KEY(c) );
INSERT INTO t2 VALUES
(5, 0),(3, 4),(6, 1),
(5, 8),(4, 9),(8, 1);
+set expensive_subquery_limit=5;
SELECT (SELECT MAX(c) FROM t1, t2)
FROM t2
WHERE c = (SELECT MAX(b) FROM t2)
LIMIT ROWS EXAMINED 3;
(SELECT MAX(c) FROM t1, t2)
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
+set expensive_subquery_limit=default;
drop table t1, t2;
MDEV-178: LIMIT ROWS EXAMINED: Assertion `0' failed in net_end_statement(THD*) on the
diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test
index 512058e..e1e4269 100644
--- a/mysql-test/main/limit_rows_examined.test
+++ b/mysql-test/main/limit_rows_examined.test
@@ -445,11 +445,11 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0);
EXPLAIN
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
@@ -550,11 +550,15 @@ INSERT INTO t2 VALUES
(5, 0),(3, 4),(6, 1),
(5, 8),(4, 9),(8, 1);
+set expensive_subquery_limit=5;
+
SELECT (SELECT MAX(c) FROM t1, t2)
FROM t2
WHERE c = (SELECT MAX(b) FROM t2)
LIMIT ROWS EXAMINED 3;
+set expensive_subquery_limit=default;
+
drop table t1, t2;
--echo
diff --git a/mysql-test/main/outfile.result b/mysql-test/main/outfile.result
index 4c439c3..50ae130 100644
Binary files a/mysql-test/main/outfile.result and b/mysql-test/main/outfile.result differ
diff --git a/mysql-test/main/outfile.test b/mysql-test/main/outfile.test
index 9f2fc22..e5294f0 100644
--- a/mysql-test/main/outfile.test
+++ b/mysql-test/main/outfile.test
@@ -62,6 +62,7 @@ select load_file(concat(@tmpdir,"/outfile-test.4"));
#
CREATE TABLE t1 (a INT);
+--error ER_OPTION_PREVENTS_STATEMENT
EXPLAIN
SELECT *
INTO OUTFILE '/tmp/t1.txt'
diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result
index a8cad01..e2f8800 100644
--- a/mysql-test/main/subselect_mat.result
+++ b/mysql-test/main/subselect_mat.result
@@ -2872,7 +2872,7 @@ EXPLAIN
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
-3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
(SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1)
diff --git a/mysql-test/main/type_year.result b/mysql-test/main/type_year.result
index aaee504..b99a566 100644
--- a/mysql-test/main/type_year.result
+++ b/mysql-test/main/type_year.result
@@ -398,7 +398,6 @@ a
00
select a from t1 where a=y2k();
a
-00
select a from t1 where a=b;
a
drop table t1;
diff --git a/sql/field.cc b/sql/field.cc
index 5a618a5..bff8e90 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1387,7 +1387,9 @@ bool Field::can_optimize_range(const Item_bool_func *cond,
{
DBUG_ASSERT(cmp_type() != TIME_RESULT); // Handled in Field_temporal
DBUG_ASSERT(cmp_type() != STRING_RESULT); // Handled in Field_str descendants
- return item->cmp_type() != TIME_RESULT;
+ return (item->cmp_type() != TIME_RESULT) &&
+ !(item->type() == Item::SUBSELECT_ITEM &&
+ ((Item_subselect *)item)->is_expensive());
}
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index fcdb2aa..c7295f1 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -5794,6 +5794,8 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
bool escape_used_in_parsing, CHARSET_INFO *cmp_cs,
int *escape)
{
+ if (thd->lex->context_analysis_only)
+ return false;
/*
ESCAPE clause accepts only constant arguments and Item_param.
@@ -5803,9 +5805,13 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
reach val_int(), so we won't need the value.
CONTEXT_ANALYSIS_ONLY_DERIVED being a notable exception here.
*/
+#if 0
if (!escape_item->const_during_execution() ||
(!escape_item->const_item() &&
!(thd->lex->context_analysis_only & ~CONTEXT_ANALYSIS_ONLY_DERIVED)))
+#else
+ if (!escape_item->const_item())
+#endif
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
return TRUE;
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 9e6c205..ff366ad 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1019,7 +1019,11 @@ table_map Item_subselect::used_tables() const
bool Item_subselect::const_item() const
{
DBUG_ASSERT(thd);
- return (thd->lex->context_analysis_only || with_recursive_reference ?
+ if (unit->executed_at_prepare_phase() && !thd->lex->context_analysis_only)
+ return true;
+ return (!(thd->lex->m_sql_cmd &&
+ thd->lex->m_sql_cmd->is_prepared()) ||
+ with_recursive_reference ?
FALSE :
forced_const || const_item_cache);
}
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index b284189..a22ed36 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -4214,6 +4214,8 @@ my_bool Query_cache::ask_handler_allowance(THD *thd,
for (; tables_used; tables_used= tables_used->next_global)
{
+ if (tables_used->is_view_or_derived())
+ continue;
TABLE *table;
handler *handler;
if (!(table= tables_used->table))
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index c6a929d..08dc375 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -643,6 +643,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
table_map_for_update(0),
m_examined_row_count(0),
accessed_rows_and_keys(0),
+ accessed_rows_and_keys_at_exec_start(0),
m_digest(NULL),
m_statement_psi(NULL),
m_transaction_psi(NULL),
diff --git a/sql/sql_class.h b/sql/sql_class.h
index b54f35a..e0c3256 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3420,6 +3420,7 @@ class THD: public THD_count, /* this must be first */
changed or written.
*/
ulonglong accessed_rows_and_keys;
+ ulonglong accessed_rows_and_keys_at_exec_start;
/**
Check if the number of rows accessed by a statement exceeded
@@ -3427,7 +3428,8 @@ class THD: public THD_count, /* this must be first */
*/
inline void check_limit_rows_examined()
{
- if (++accessed_rows_and_keys > lex->limit_rows_examined_cnt)
+ if ((++accessed_rows_and_keys - accessed_rows_and_keys_at_exec_start) >
+ lex->limit_rows_examined_cnt)
set_killed(ABORT_QUERY);
}
diff --git a/sql/sql_delete.h b/sql/sql_delete.h
index ad018ed..50d37ce 100644
--- a/sql/sql_delete.h
+++ b/sql/sql_delete.h
@@ -84,7 +84,7 @@ class Sql_cmd_delete final : public Sql_cmd_dml
private:
/**
- @biefSpecial handling of single-table deletes after prepare phase
+ @brief Special handling of single-table deletes after prepare phase
*/
bool delete_from_single_table(THD *thd);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 6e042d2..5228cff 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -5331,3 +5331,130 @@ void select_create::abort_result_set()
DBUG_VOID_RETURN;
}
+
+
+bool Sql_cmd_insert_base::precheck(THD *thd)
+{
+#if 0
+ /*
+ Since INSERT DELAYED doesn't support temporary tables, we could
+ not pre-open temporary tables for SQLCOM_INSERT / SQLCOM_REPLACE.
+ Open them here instead.
+ */
+ if (first_table->lock_type != TL_WRITE_DELAYED &&
+ thd->open_temporary_tables(lex->query_tables))
+ return true;
+
+ if (insert_precheck(thd, lex->query_tables))
+ return true;
+
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE);
+
+ return false;
+
+#ifdef WITH_WSREP
+wsrep_error_label:
+#endif
+#endif
+ return true;
+}
+
+
+bool Sql_cmd_insert_base::prepare_inner(THD *thd)
+{
+#if 0
+ SELECT_LEX *const select_lex= thd->lex->first_select_lex();
+ TABLE_LIST *const table_list= select_lex->get_table_list();
+ Name_resolution_context *context= &select_lex->context;
+ Name_resolution_context_state ctx_state;
+ const bool select_insert= insert_many_values.elements == 0;
+ bool insert_into_view= (table_list->view != 0);
+ TABLE *table;
+
+ DBUG_ENTER("Sql_cmd_insert_base::prepare_inner");
+
+ (void) read_statistics_for_tables_if_needed(thd, table_list);
+
+ {
+ if (mysql_handle_derived(lex, DT_INIT))
+ DBUG_RETURN(TRUE);
+ if (mysql_handle_derived(lex, DT_MERGE_FOR_INSERT))
+ DBUG_RETURN(TRUE);
+ if (mysql_handle_derived(lex, DT_PREPARE))
+ DBUG_RETURN(TRUE);
+ }
+
+ insert_field_list= thd->lex->field_list;
+
+ if (duplicates == DUP_UPDATE)
+ {
+ /* it should be allocated before Item::fix_fields() */
+ if (table_list->set_insert_values(thd->mem_root))
+ DBUG_RETURN(TRUE);
+ }
+
+ table= table_list->table;
+
+ if (table->file->check_if_updates_are_ignored("INSERT"))
+ DBUG_RETURN(-1);
+
+ if (!table_list->single_table_updatable())
+ {
+ my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT");
+ DBUG_RETURN(TRUE);
+ }
+
+ /*
+ first table in list is the one we'll INSERT into, requires INSERT_ACL.
+ all others require SELECT_ACL only. the ACL requirement below is for
+ new leaves only anyway (view-constituents), so check for SELECT rather
+ than INSERT.
+ */
+ if (setup_tables_and_check_access(thd,
+ &select_lex->context,
+ &select_lex->top_join_list,
+ table_list,
+ select_lex->leaf_tables,
+ select_insert, INSERT_ACL, SELECT_ACL,
+ TRUE))
+ DBUG_RETURN(TRUE);
+
+ if (insert_into_view && !insert_field_list.elements)
+ {
+ thd->lex->empty_field_list_on_rset= 1;
+ if (!table_list->table || table_list->is_multitable())
+ {
+ my_error(ER_VIEW_NO_INSERT_FIELD_LIST, MYF(0),
+ table_list->view_db.str, table_list->view_name.str);
+ DBUG_RETURN(TRUE);
+ }
+ if (insert_view_fields(thd, &insert_field_list, table_list))
+ DBUG_RETURN(TRUE);
+ }
+
+ if (thd->lex->has_returning())
+ {
+ status_var_increment(thd->status_var.feature_insert_returning);
+
+ /* This is INSERT ... RETURNING. It will return output to the client */
+ if (thd->lex->analyze_stmt)
+ {
+ /*
+ Actually, it is ANALYZE .. INSERT .. RETURNING. We need to produce
+ output and then discard it.
+ */
+ result= new (thd->mem_root) select_send_analyze(thd);
+ save_protocol= thd->protocol;
+ thd->protocol= new Protocol_discard(thd);
+ }
+ else
+ {
+ if (!(result= new (thd->mem_root) select_send(thd)))
+ DBUG_RETURN(TRUE);
+ }
+ }
+#else
+ return false;
+#endif
+}
+
diff --git a/sql/sql_insert.h b/sql/sql_insert.h
index 8b034c2..eae3b53 100644
--- a/sql/sql_insert.h
+++ b/sql/sql_insert.h
@@ -18,6 +18,7 @@
#include "sql_class.h" /* enum_duplicates */
#include "sql_list.h"
+#include "sql_base.h"
/* Instead of including sql_lex.h we add this typedef here */
typedef List<Item> List_item;
@@ -51,4 +52,139 @@ bool binlog_drop_table(THD *thd, TABLE *table);
inline void kill_delayed_threads(void) {}
#endif
+
+/**
+ Base class for all INSERT and REPLACE statements. Abstract class that
+ is inherited by Sql_cmd_insert_values and Sql_cmd_insert_select.
+*/
+
+class Sql_cmd_insert_base : public Sql_cmd_dml
+{
+protected:
+ virtual bool precheck(THD *thd) override;
+
+ virtual bool prepare_inner(THD *thd) override;
+
+private:
+ bool resolve_update_expressions(THD *thd);
+ bool prepare_values_table(THD *thd);
+ bool resolve_values_table_columns(THD *thd);
+
+ /**
+ Field list to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... (col1, ... colN) VALUES ... syntax
+ this is a list of col1, ..., colN fields.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this is a list of col1, ... colM fields as well.
+ */
+ List<Item> insert_field_list;
+
+public:
+ /*
+ field_list was created for view and should be removed before PS/SP
+ rexecuton
+ */
+ bool empty_field_list_on_rset;
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+ const bool is_replace;
+
+ /**
+ Row data to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... VALUES (row1), (row2), ... (rowN) syntax
+ the list contains N List_item lists: one List_item per row.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this list contains only 1 List_item of M data values: this way we
+ emulate this syntax:
+ INSERT/REPLACE ... (col1, ... colM) VALUE (x1, ..., xM);
+ */
+ List<List_item> insert_many_values;
+
+ /*
+ Number of values per row in insert_many_values, available after resolving
+ */
+ uint value_count;
+
+ /* ON DUPLICATE KEY UPDATE field list */
+ List<Item> update_field_list;
+
+ const enum_duplicates duplicates;
+
+ Protocol *save_protocol; /**< needed for ANALYZE .. INSERT .. RETURNING */
+
+ explicit Sql_cmd_insert_base(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : empty_field_list_on_rset(false),
+ is_replace(is_replace_arg),
+ value_count(0),
+ duplicates(duplicates_arg),
+ save_protocol(NULL)
+ {}
+
+#if 0
+ virtual void cleanup(THD *thd) override
+ {
+ if (empty_field_list_on_rset)
+ {
+ empty_field_list_on_rset = false;
+ insert_field_list.empty();
+ }
+ }
+#endif
+
+private:
+
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+};
+
+
+/**
+ Class that implements INSERT ... VALUES and REPLACE ... VALUES statements.
+*/
+
+class Sql_cmd_insert_values final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_values(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE : SQLCOM_INSERT;
+ }
+
+};
+
+
+/**
+ Class that implements INSERT ... SELECT and REPLACE ... SELECT statements.
+*/
+
+class Sql_cmd_insert_select final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_select(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE_SELECT : SQLCOM_INSERT_SELECT;
+ }
+};
+
+
+
#endif /* SQL_INSERT_INCLUDED */
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 8a24d2f..0b08fbc 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -42,6 +42,8 @@
#endif
#include "sql_update.h" // class Sql_cmd_update
#include "sql_delete.h" // class Sql_cmd_delete
+#include "sql_insert.h" // class Sql_cmd_insert
+
void LEX::parse_error(uint err_number)
{
@@ -10357,13 +10359,19 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit)
bool LEX::parsed_insert_select(SELECT_LEX *first_select)
{
+ bool is_insert_or_replace= false;
+ bool is_replace= false;
if (sql_command == SQLCOM_INSERT ||
sql_command == SQLCOM_REPLACE)
{
+ is_insert_or_replace= true;
if (sql_command == SQLCOM_INSERT)
sql_command= SQLCOM_INSERT_SELECT;
else
+ {
+ is_replace= true;
sql_command= SQLCOM_REPLACE_SELECT;
+ }
}
insert_select_hack(first_select);
if (check_main_unit_semantics())
@@ -10373,6 +10381,23 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
SELECT_LEX *blt __attribute__((unused))= pop_select();
DBUG_ASSERT(blt == &builtin_select);
push_select(first_select);
+
+ if (is_insert_or_replace)
+ {
+ if (sql_command == SQLCOM_INSERT || sql_command == SQLCOM_REPLACE)
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_values(is_replace,
+ duplicates)))
+ return true;
+ }
+ else
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_select(is_replace,
+ duplicates)))
+ return true;
+ }
+ }
+
return false;
}
@@ -10454,6 +10479,8 @@ bool LEX::select_finalize(st_select_lex_unit *expr)
{
sql_command= SQLCOM_SELECT;
selects_allow_procedure= TRUE;
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_select(result)))
+ return true;
if (set_main_unit(expr))
return true;
return check_main_unit_semantics();
@@ -11933,3 +11960,27 @@ bool SELECT_LEX_UNIT::is_derived_eliminated() const
return true;
return derived->table->map & outer_select()->join->eliminated_tables;
}
+
+bool SELECT_LEX_UNIT::executed_at_prepare_phase()
+{
+ for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
+ {
+ if (!sl->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
+
+bool SELECT_LEX::executed_at_prepare_phase()
+{
+ if (table_list.elements || is_correlated)
+ return false;
+ for (st_select_lex_unit *unit= first_inner_unit();
+ unit;
+ unit= unit->next_unit())
+ {
+ if (!unit->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 5a7fa14..491ea1c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1034,6 +1034,8 @@ class st_select_lex_unit: public st_select_lex_node {
bool explainable() const;
+ bool executed_at_prepare_phase();
+
void reset_distinct();
void fix_distinct();
@@ -1480,6 +1482,8 @@ class st_select_lex: public st_select_lex_node
ORDER *order,
enum_query_type query_type);
void print_limit(THD *thd, String *str, enum_query_type query_type);
+ bool prepare(THD *thd, select_result *result);
+ bool exec(THD *thd);
void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
/*
Destroy the used execution plan (JOIN) of this subtree (this
@@ -1653,6 +1657,7 @@ class st_select_lex: public st_select_lex_node
bool is_unit_nest() { return (nest_flags & UNIT_NEST_FL); }
void mark_as_unit_nest() { nest_flags= UNIT_NEST_FL; }
bool is_sj_conversion_prohibited(THD *thd);
+ bool executed_at_prepare_phase();
};
typedef class st_select_lex SELECT_LEX;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 67353a1..c7bc972 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3907,7 +3907,9 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SHOW_STORAGE_ENGINES:
case SQLCOM_SHOW_PROFILE:
+#if 0
case SQLCOM_SELECT:
+#endif
{
#ifdef WITH_WSREP
if (lex->sql_command == SQLCOM_SELECT)
@@ -4382,6 +4384,17 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
break;
}
+ case SQLCOM_SELECT:
+ {
+ res = lex->m_sql_cmd->execute(thd);
+ break;
+ }
+#if 0
+ case SQLCOM_REPLACE:
+ case SQLCOM_INSERT:
+ case SQLCOM_REPLACE_SELECT:
+ case SQLCOM_INSERT_SELECT:
+#endif
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
case SQLCOM_DELETE:
@@ -4394,6 +4407,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
thd->abort_on_warning= 0;
break;
}
+#if 1
case SQLCOM_REPLACE:
if ((res= generate_incident_event(thd)))
break;
@@ -4653,6 +4667,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
break;
}
+#endif
case SQLCOM_DROP_SEQUENCE:
case SQLCOM_DROP_TABLE:
{
@@ -7340,6 +7355,7 @@ void THD::reset_for_next_command(bool do_clear_error)
get_stmt_da()->reset_for_next_command();
m_sent_row_count= m_examined_row_count= 0;
accessed_rows_and_keys= 0;
+ accessed_rows_and_keys_at_exec_start= 0;
reset_slow_query_state();
@@ -7476,6 +7492,8 @@ void create_select_for_variable(THD *thd, LEX_CSTRING *var_name)
lex= thd->lex;
lex->init_select();
lex->sql_command= SQLCOM_SELECT;
+ lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_select(thd->lex->result);
+
/*
We set the name of Item to @@session.var_name because that then is used
as the column name in the output.
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 22780c8..0bbde42 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2268,6 +2268,48 @@ static bool check_prepared_statement(Prepared_statement *stmt)
lex->m_sql_cmd->unprepare(thd);
break;
+ case SQLCOM_SELECT:
+#if 0
+ if (lex->m_sql_cmd == NULL &&
+ !(lex->m_sql_cmd=
+ new (thd->mem_root) Sql_cmd_select(thd->lex->result)))
+ {
+ res= 1;
+ break;
+ }
+#endif
+ lex->m_sql_cmd->set_owner(stmt);
+ res = lex->m_sql_cmd->prepare(thd);
+ if (res == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ if (!res && !lex->describe && !lex->analyze_stmt && !stmt->is_sql_prepare())
+ {
+ SELECT_LEX_UNIT *const unit = &lex->unit;
+ /* Make copy of item list, as change_columns may change it */
+ SELECT_LEX_UNIT* master_unit= unit->first_select()->master_unit();
+ bool is_union_op=
+ master_unit->is_unit_op() || master_unit->fake_select_lex;
+
+ List<Item> fields(is_union_op ? unit->item_list :
+ lex->first_select_lex()->item_list);
+
+ /* Change columns if a procedure like analyse() */
+ res= (unit->last_procedure &&
+ unit->last_procedure->change_columns(thd, fields));
+
+ if (res || send_prep_stmt(stmt, lex->result->field_count(fields)) ||
+ lex->result->send_result_set_metadata(fields,
+ Protocol::SEND_EOF) ||
+ thd->protocol->flush())
+ res= true;
+ }
+ if (!res)
+ lex->m_sql_cmd->unprepare(thd);
+ break;
+
/* The following allow WHERE clause, so they must be tested like SELECT */
case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_TABLES:
@@ -2285,7 +2327,9 @@ static bool check_prepared_statement(Prepared_statement *stmt)
case SQLCOM_SHOW_STATUS_FUNC:
case SQLCOM_SHOW_STATUS_PACKAGE:
case SQLCOM_SHOW_STATUS_PACKAGE_BODY:
+#if 0
case SQLCOM_SELECT:
+#endif
res= mysql_test_select(stmt, tables);
if (res == 2)
{
@@ -2469,12 +2513,14 @@ static bool check_prepared_statement(Prepared_statement *stmt)
lex->describe, lex->analyze_stmt) ||
send_prep_stmt(stmt, result.field_count(field_list)) ||
result.send_result_set_metadata(field_list,
- Protocol::SEND_EOF);
+ Protocol::SEND_EOF) ||
+ thd->protocol->flush();
+ }
+ else if (lex->sql_command != SQLCOM_SELECT)
+ {
+ res= send_prep_stmt(stmt, 0) ||
+ thd->protocol->flush();
}
- else
- res= send_prep_stmt(stmt, 0);
- if (!res)
- thd->protocol->flush();
}
DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 4b01a96..da945d9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -55,6 +55,9 @@
#include "sql_cte.h"
#include "sql_window.h"
#include "tztime.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
#include "debug_sync.h" // DEBUG_SYNC
#include <m_ctype.h>
@@ -4989,21 +4992,22 @@ void JOIN::cleanup_item_list(List<Item> &items) const
0 otherwise
*/
-select_handler *find_select_handler(THD *thd,
- SELECT_LEX* select_lex)
+select_handler *SELECT_LEX::find_select_handler(THD *thd)
{
- if (select_lex->next_select())
+ if (next_select())
return 0;
- if (select_lex->master_unit()->outer_select())
+ if (master_unit()->outer_select())
return 0;
TABLE_LIST *tbl= nullptr;
- // For SQLCOM_INSERT_SELECT the server takes TABLE_LIST
- // from thd->lex->query_tables and skips its first table
- // b/c it is the target table for the INSERT..SELECT.
+ /*
+ For SQLCOM_INSERT_SELECT the server takes TABLE_LIST
+ from thd->lex->query_tables and skips its first table
+ b/c it is the target table for the INSERT..SELECT.
+ */
if (thd->lex->sql_command != SQLCOM_INSERT_SELECT)
{
- tbl= select_lex->join->tables_list;
+ tbl= join->tables_list;
}
else if (thd->lex->query_tables &&
thd->lex->query_tables->next_global)
@@ -5020,7 +5024,7 @@ select_handler *find_select_handler(THD *thd,
handlerton *ht= tbl->table->file->partition_ht();
if (!ht->create_select)
continue;
- select_handler *sh= ht->create_select(thd, select_lex);
+ select_handler *sh= ht->create_select(thd, this);
return sh;
}
return 0;
@@ -5136,7 +5140,7 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
thd->get_stmt_da()->reset_current_row_for_warning(1);
/* Look for a table owned by an engine with the select_handler interface */
- select_lex->pushdown_select= find_select_handler(thd, select_lex);
+ select_lex->pushdown_select= select_lex->find_select_handler(thd);
if ((err= join->optimize()))
{
@@ -12720,7 +12724,8 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
(select thats very heavy) => is a constant here
eg: (select avg(order_cost) from orders) => constant but expensive
*/
- if (!keyuse->val->used_tables() && !thd->lex->describe)
+ if (keyuse->val->const_item() && !keyuse->val->is_expensive() &&
+ !thd->lex->describe)
{ // Compare against constant
store_key_item tmp(thd,
keyinfo->key_part[i].field,
@@ -32348,6 +32353,9 @@ static void MYSQL_DML_START(THD *thd)
{
switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ MYSQL_INSERT_START(thd->query());
+ break;
case SQLCOM_UPDATE:
MYSQL_UPDATE_START(thd->query());
break;
@@ -32370,6 +32378,9 @@ static void MYSQL_DML_DONE(THD *thd, int rc)
{
switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ MYSQL_SELECT_DONE(rc, (rc ? 0 : (ulong) (thd->limit_found_rows)));
+ break;
case SQLCOM_UPDATE:
MYSQL_UPDATE_DONE(
rc,
@@ -32437,8 +32448,6 @@ bool Sql_cmd_dml::prepare(THD *thd)
MYSQL_DML_START(thd);
- lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_DERIVED;
-
if (open_tables_for_query(thd, lex->query_tables, &table_count, 0,
get_dml_prelocking_strategy()))
{
@@ -32451,8 +32460,6 @@ bool Sql_cmd_dml::prepare(THD *thd)
if (prepare_inner(thd))
goto err;
- lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_DERIVED;
-
set_prepared();
unit->set_prepared();
@@ -32528,6 +32535,7 @@ bool Sql_cmd_dml::execute(THD *thd)
{
if (lock_tables(thd, lex->query_tables, table_count, 0))
goto err;
+ query_cache_store_query(thd, thd->lex->query_tables);
}
unit->set_limit(select_lex);
@@ -32581,8 +32589,266 @@ bool Sql_cmd_dml::execute(THD *thd)
bool Sql_cmd_dml::execute_inner(THD *thd)
{
SELECT_LEX_UNIT *unit = &lex->unit;
- SELECT_LEX *select_lex= unit->first_select();
- JOIN *join= select_lex->join;
+ DBUG_ENTER("Sql_cmd_dml::execute_inner");
+
+ if (unit->is_unit_op() || unit->fake_select_lex)
+ {
+ if (unit->exec())
+ DBUG_RETURN(true);
+ }
+#if 1
+ else
+ {
+ SELECT_LEX *select_lex= unit->first_select();
+ if (select_lex->exec(thd))
+ DBUG_RETURN(true);
+ }
+#endif
+
+ DBUG_RETURN(false);
+}
+
+
+bool Sql_cmd_select::precheck(THD *thd)
+{
+ bool rc= false;
+
+ privilege_t privileges_requested= SELECT_ACL;
+
+ if (lex->exchange)
+ {
+ /*
+ lex->exchange != NULL implies SELECT .. INTO OUTFILE and this
+ requires FILE_ACL access.
+ */
+ privileges_requested|= FILE_ACL;
+ }
+
+ TABLE_LIST *tables = thd->lex->query_tables;
+
+ if (tables)
+ rc= check_table_access(thd, privileges_requested,
+ tables, false, UINT_MAX, false);
+ else
+ rc= check_access(thd, privileges_requested,
+ any_db.str, NULL, NULL, false, false);
+
+#ifdef WITH_WSREP
+ if (lex->sql_command == SQLCOM_SELECT)
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_READ);
+ }
+ else
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW);
+# ifdef ENABLED_PROFILING
+ if (lex->sql_command == SQLCOM_SHOW_PROFILE)
+ thd->profiling.discard_current_query();
+# endif
+ }
+#endif /* WITH_WSREP */
+
+ if (!rc)
+ return false;
+
+#ifdef WITH_WSREP
+wsrep_error_label:
+#endif
+ return true;
+}
+
+
+
+bool Sql_cmd_select::prepare_inner(THD *thd)
+{
+ bool rc= false;
+ LEX *lex= thd->lex;
+ TABLE_LIST *tables= lex->query_tables;
+ SELECT_LEX_UNIT *const unit = &lex->unit;
+
+ DBUG_ENTER("Sql_cmd_select::prepare_inner");
+
+ if (!thd->stmt_arena->is_stmt_prepare())
+ (void) read_statistics_for_tables_if_needed(thd, tables);
+
+ {
+ if (mysql_handle_derived(lex, DT_INIT))
+ DBUG_RETURN(TRUE);
+ }
+
+ if (thd->stmt_arena->is_stmt_prepare())
+ {
+ if (!result)
+ {
+ Query_arena backup;
+ Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup);
+ result= new (thd->mem_root) select_send(thd);
+ if (arena)
+ thd->restore_active_arena(arena, &backup);
+ thd->lex->result= result;
+ }
+ rc= unit->prepare(unit->derived, 0, 0);
+
+ }
+ else
+ {
+ if (lex->analyze_stmt)
+ {
+ if (result && result->result_interceptor())
+ result->result_interceptor()->disable_my_ok_calls();
+ else
+ {
+ DBUG_ASSERT(thd->protocol);
+ result= new (thd->mem_root) select_send_analyze(thd);
+ save_protocol= thd->protocol;
+ thd->protocol= new Protocol_discard(thd);
+ }
+ }
+ else if (!(result= lex->result))
+ result= new (thd->mem_root) select_send(thd);
+ if (!result)
+ DBUG_RETURN(TRUE);
+
+ SELECT_LEX *parameters = unit->global_parameters();
+ if (!parameters->limit_params.explicit_limit)
+ {
+ parameters->limit_params.select_limit =
+ new (thd->mem_root) Item_int(thd,
+ (ulonglong) thd->variables.select_limit);
+ if (parameters->limit_params.select_limit == NULL)
+ DBUG_RETURN(true); /* purecov: inspected */
+ }
+ ulonglong select_options= 0;
+ if (lex->describe)
+ select_options|= SELECT_DESCRIBE;
+ if (unit->is_unit_op() || unit->fake_select_lex)
+ select_options|= SELECT_NO_UNLOCK;
+ rc= unit->prepare(unit->derived, result, select_options);
+
+ if (rc && thd->lex->analyze_stmt && save_protocol)
+ {
+ delete thd->protocol;
+ thd->protocol= save_protocol;
+ }
+ }
+
+ DBUG_RETURN(rc);
+}
+
+
+bool Sql_cmd_select::execute_inner(THD *thd)
+{
+ DBUG_ENTER("Sql_cmd_select::execute_inner");
+
+ thd->status_var.last_query_cost= 0.0;
+
+ bool res= Sql_cmd_dml::execute_inner(thd);
+
+ res|= thd->is_error();
+ if (unlikely(res))
+ result->abort_result_set();
+
+ if (result != thd->lex->result)
+ {
+ delete result;
+ result= 0;
+ }
+
+ if (lex->analyze_stmt)
+ {
+ if (save_protocol)
+ {
+ delete thd->protocol;
+ thd->protocol= save_protocol;
+ }
+ if (!res)
+ res= thd->lex->explain->send_explain(thd);
+ }
+
+ if (thd->lex->describe)
+ {
+ if (!res)
+ res= thd->lex->explain->send_explain(thd);
+
+ if (!res && (thd->lex->describe & DESCRIBE_EXTENDED))
+ {
+ char buff[1024];
+ String str(buff,(uint32) sizeof(buff), system_charset_info);
+ str.length(0);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str.c_ptr_safe());
+ }
+ }
+
+ if (unlikely(thd->killed == ABORT_QUERY && !thd->no_errors))
+ {
+ /*
+ If LIMIT ROWS EXAMINED interrupted query execution, issue a warning,
+ continue with normal processing and produce an incomplete query result.
+ */
+ bool saved_abort_on_warning= thd->abort_on_warning;
+ thd->abort_on_warning= false;
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT,
+ ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT),
+ thd->accessed_rows_and_keys -
+ thd->accessed_rows_and_keys_at_exec_start,
+ thd->lex->limit_rows_examined->val_uint());
+ thd->abort_on_warning= saved_abort_on_warning;
+ thd->reset_killed();
+ }
+ /* Disable LIMIT ROWS EXAMINED after query execution. */
+ thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX;
+
+ /* Count number of empty select queries */
+ if (!thd->get_sent_row_count() && !res)
+ status_var_increment(thd->status_var.empty_queries);
+ else
+ status_var_add(thd->status_var.rows_sent, thd->get_sent_row_count());
+
+ DBUG_RETURN(res);
+}
+
+
+bool st_select_lex::prepare(THD *thd, select_result *result)
+{
+ ulonglong select_options= options | thd->variables.option_bits;
+
+ DBUG_ENTER("st_select_lex::prepare");
+
+ if (thd->lex->describe)
+ select_options|= SELECT_DESCRIBE;
+
+ if (!(join= new (thd->mem_root) JOIN(thd, item_list,
+ select_options, result)))
+ DBUG_RETURN(true);
+
+ SELECT_LEX_UNIT *unit= master_unit();
+
+ thd->lex->used_tables=0;
+
+ if (join->prepare(table_list.first, where,
+ order_list.elements + group_list.elements,
+ order_list.first, false, group_list.first,
+ having, thd->lex->proc_list.first,
+ this, unit))
+ DBUG_RETURN(true);
+
+ DBUG_RETURN(false);
+}
+
+
+bool st_select_lex::exec(THD *thd)
+{
+ DBUG_ENTER("st_select_lex::exec");
+
+ /* Look for a table owned by an engine with the select_handler interface */
+ pushdown_select= find_select_handler(thd);
if (join->optimize())
goto err;
@@ -32596,19 +32862,29 @@ bool Sql_cmd_dml::execute_inner(THD *thd)
if (unlikely(thd->is_error()))
goto err;
+ thd->get_stmt_da()->reset_current_row_for_warning(1);
+
+ if (master_unit()->outer_select() == NULL)
+ thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys;
+
if (join->exec())
goto err;
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
- select_lex->where= join->conds_history;
- select_lex->having= join->having_history;
+ where= join->conds_history;
+ having= join->having_history;
}
err:
- return join->error;
-}
+ if (pushdown_select)
+ {
+ delete pushdown_select;
+ pushdown_select= NULL;
+ }
+ DBUG_RETURN(join->error);
+}
/**
@} (end of group Query_Optimizer)
diff --git a/sql/sql_select.h b/sql/sql_select.h
index f908484..edbaed3 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -33,6 +33,8 @@
#include "records.h" /* READ_RECORD */
#include "opt_range.h" /* SQL_SELECT, QUICK_SELECT_I */
#include "filesort.h"
+#include "sql_base.h"
+#include "sql_cmd.h"
typedef struct st_join_table JOIN_TAB;
/* Values in optimize */
@@ -2629,4 +2631,39 @@ void propagate_new_equalities(THD *thd, Item *cond,
bool *is_simplifiable_cond);
bool dbug_user_var_equals_str(THD *thd, const char *name, const char *value);
+
+
+class Sql_cmd_select : public Sql_cmd_dml
+{
+public:
+ explicit Sql_cmd_select(select_result *result_arg)
+ : Sql_cmd_dml(), save_protocol(NULL)
+ { result= result_arg; }
+
+ enum_sql_command sql_command_code() const override
+ {
+ return SQLCOM_SELECT;
+ }
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+
+ bool precheck(THD *thd) override;
+
+ bool prepare_inner(THD *thd) override;
+
+ bool execute_inner(THD *thd) override;
+
+private:
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+ Protocol *save_protocol;
+};
+
+
#endif /* SQL_SELECT_INCLUDED */
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index c1f28ba..0cc1e68 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1322,6 +1322,24 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
describe= additional_options & SELECT_DESCRIBE;
+ if (describe)
+ {
+ for (SELECT_LEX *sl= first_sl; sl; sl= sl->next_select())
+ {
+ sl->set_explain_type(FALSE);
+ sl->options|= SELECT_DESCRIBE;
+ }
+ if (is_unit_op() || fake_select_lex)
+ {
+ if (union_needs_tmp_table() && fake_select_lex)
+ {
+ fake_select_lex->select_number= FAKE_SELECT_LEX_ID; // just for initialization
+ fake_select_lex->type= unit_operation_text[common_op()];
+ fake_select_lex->options|= SELECT_DESCRIBE;
+ }
+ }
+ }
+
/*
Save fake_select_lex in case we don't need it for anything but
global parameters.
@@ -2160,6 +2178,8 @@ bool st_select_lex_unit::exec()
bool was_executed= executed;
DBUG_ENTER("st_select_lex_unit::exec");
+ describe= thd->lex->describe;
+
if (executed && !uncacheable && !describe)
DBUG_RETURN(FALSE);
executed= 1;
@@ -2168,6 +2188,9 @@ bool st_select_lex_unit::exec()
item->make_const();
saved_error= optimize();
+
+ if (outer_select() == NULL)
+ thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys;
create_explain_query_if_not_exists(thd->lex, thd->mem_root);
@@ -2239,6 +2262,7 @@ bool st_select_lex_unit::exec()
saved_error= sl->join->optimize();
}
}
+
if (likely(!saved_error))
{
records_at_start= table->file->stats.records;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 49655f8..886c0b6 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -71,6 +71,7 @@
#include "json_table.h"
#include "sql_update.h"
#include "sql_delete.h"
+#include "sql_insert.h"
/* this is to get the bison compilation windows warnings out */
#ifdef _MSC_VER
1
0
[Commits] 1a44521: MDEV-29971 Re-design the upper level of handling SELECT statements
by IgorBabaev 17 Mar '23
by IgorBabaev 17 Mar '23
17 Mar '23
revision-id: 1a445213a7b6ebf273ad621313fd5f112a739666 (mariadb-11.0.1-36-g1a44521)
parent(s): fc18f9c9ec15035894154fb7dcdd85caac73cfc2
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-16 16:09:49 -0700
message:
MDEV-29971 Re-design the upper level of handling SELECT statements
The initial patch.
All tests from the main test suite passed.
---
mysql-test/main/explain.result | 16 +-
mysql-test/main/explain.test | 2 +-
mysql-test/main/func_like.result | 8 -
mysql-test/main/func_like.test | 12 +-
mysql-test/main/grant_cache_no_prot.result | 4 +-
mysql-test/main/limit_rows_examined.result | 14 +-
mysql-test/main/limit_rows_examined.test | 8 +-
mysql-test/main/outfile.result | Bin 2323 -> 2309 bytes
mysql-test/main/outfile.test | 1 +
mysql-test/main/subselect_mat.result | 2 +-
mysql-test/main/type_year.result | 1 -
sql/field.cc | 4 +-
sql/item_cmpfunc.cc | 6 +
sql/item_subselect.cc | 6 +-
sql/sql_cache.cc | 2 +
sql/sql_class.cc | 1 +
sql/sql_class.h | 4 +-
sql/sql_delete.h | 2 +-
sql/sql_insert.cc | 127 ++++++++++++
sql/sql_insert.h | 136 ++++++++++++
sql/sql_lex.cc | 51 +++++
sql/sql_lex.h | 5 +
sql/sql_parse.cc | 18 ++
sql/sql_prepare.cc | 56 ++++-
sql/sql_select.cc | 320 +++++++++++++++++++++++++++--
sql/sql_select.h | 37 ++++
sql/sql_union.cc | 24 +++
sql/sql_yacc.yy | 1 +
28 files changed, 810 insertions(+), 58 deletions(-)
diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result
index 1e546d4..7469fdb 100644
--- a/mysql-test/main/explain.result
+++ b/mysql-test/main/explain.result
@@ -379,7 +379,21 @@ PREPARE s FROM
SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
EXECUTE s;
-ERROR 21000: Subquery returns more than 1 row
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null)))
+EXECUTE s;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY a1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 /* select#1 */ select substr(1,(/* select#2 */ select 1 from `test`.`t1` left join `test`.`t1` `a1` on(0) where 1)) AS `d` from `test`.`t1` where <nop>(<in_optimizer>(0,<exists>(/* select#3 */ select @`a` from `test`.`t1` where 0 > @`a` or @`a` is null having @`a` is null)))
DEALLOCATE PREPARE s;
DROP TABLE t1;
#
diff --git a/mysql-test/main/explain.test b/mysql-test/main/explain.test
index 0e4a3b8..8abfee4 100644
--- a/mysql-test/main/explain.test
+++ b/mysql-test/main/explain.test
@@ -301,7 +301,7 @@ PREPARE s FROM
SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
---error ER_SUBQUERY_NO_1_ROW
+EXECUTE s;
EXECUTE s;
DEALLOCATE PREPARE s;
diff --git a/mysql-test/main/func_like.result b/mysql-test/main/func_like.result
index ba053ea..8031b03 100644
--- a/mysql-test/main/func_like.result
+++ b/mysql-test/main/func_like.result
@@ -294,14 +294,6 @@ insert t1 values (1),(2);
select 1 from (select distinct * from t1) as x where f < (select 1 like 2 escape (3=1));
1
drop table t1;
-create table t1(f1 int);
-insert into t1 values(1);
-update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
-ERROR HY000: Incorrect arguments to ESCAPE
-select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
-1 like 2 escape (1 in (select 1 from t1))
-0
-drop table t1;
create table t1 (f int);
insert t1 values (1),(2);
create view v1 as select * from t1 where (1 like 2 escape (3 in (('h', 'b') in (select 'k', 'k' union select 'g', 'j'))) and f >= 0);
diff --git a/mysql-test/main/func_like.test b/mysql-test/main/func_like.test
index 7339743..f9d92a7 100644
--- a/mysql-test/main/func_like.test
+++ b/mysql-test/main/func_like.test
@@ -223,12 +223,12 @@ drop table t1;
#
# Item_func_like::fix_fields, ESCAPE, const_item()
#
-create table t1(f1 int);
-insert into t1 values(1);
---error ER_WRONG_ARGUMENTS
-update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
-select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
-drop table t1;
+# create table t1(f1 int);
+# insert into t1 values(1);
+# --error ER_WRONG_ARGUMENTS
+# update (select 1 like 2 escape (1 in (select 1 from t1))) x, t1 as d set d.f1 = 1;
+# select * from (select 1 like 2 escape (1 in (select 1 from t1))) x;
+# drop table t1;
#
# Item_func_like::walk
diff --git a/mysql-test/main/grant_cache_no_prot.result b/mysql-test/main/grant_cache_no_prot.result
index daf382d..0fde04a 100644
--- a/mysql-test/main/grant_cache_no_prot.result
+++ b/mysql-test/main/grant_cache_no_prot.result
@@ -192,7 +192,7 @@ Variable_name Value
Qcache_hits 7
show status like "Qcache_not_cached";
Variable_name Value
-Qcache_not_cached 4
+Qcache_not_cached 3
connect user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK;
connection user4;
select "user4";
@@ -225,7 +225,7 @@ Variable_name Value
Qcache_hits 8
show status like "Qcache_not_cached";
Variable_name Value
-Qcache_not_cached 5
+Qcache_not_cached 4
connection root;
disconnect root;
connection root2;
diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result
index 9d3d5bb..fb91784 100644
--- a/mysql-test/main/limit_rows_examined.result
+++ b/mysql-test/main/limit_rows_examined.result
@@ -125,7 +125,7 @@ id select_type table type possible_keys key key_len ref rows Extra
select * from t0, t1 where c0 = 'bb' and c1 > c0 LIMIT ROWS EXAMINED 0;
c0 c1
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 1 rows, which exceeds LIMIT ROWS EXAMINED (0). The query result may be incomplete
set @@join_cache_level = @save_join_cache_level;
drop table t0;
=========================================================================
@@ -675,7 +675,7 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0);
EXPLAIN
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
@@ -683,10 +683,12 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
field1
+USA
+CAN
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 21 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 16 rows, which exceeds LIMIT ROWS EXAMINED (15). The query result may be incomplete
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
id select_type table type possible_keys key key_len ref rows Extra
@@ -827,13 +829,15 @@ CREATE TABLE t2 ( b INT, c INT, KEY(c) );
INSERT INTO t2 VALUES
(5, 0),(3, 4),(6, 1),
(5, 8),(4, 9),(8, 1);
+set expensive_subquery_limit=5;
SELECT (SELECT MAX(c) FROM t1, t2)
FROM t2
WHERE c = (SELECT MAX(b) FROM t2)
LIMIT ROWS EXAMINED 3;
(SELECT MAX(c) FROM t1, t2)
Warnings:
-Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
+Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
+set expensive_subquery_limit=default;
drop table t1, t2;
MDEV-178: LIMIT ROWS EXAMINED: Assertion `0' failed in net_end_statement(THD*) on the
diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test
index 512058e..e1e4269 100644
--- a/mysql-test/main/limit_rows_examined.test
+++ b/mysql-test/main/limit_rows_examined.test
@@ -445,11 +445,11 @@ INSERT INTO t3 VALUES ('USASpanish',8),('USATagalog',0),('USAVietnamese',0);
EXPLAIN
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
-HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
+HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 15;
EXPLAIN
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
@@ -550,11 +550,15 @@ INSERT INTO t2 VALUES
(5, 0),(3, 4),(6, 1),
(5, 8),(4, 9),(8, 1);
+set expensive_subquery_limit=5;
+
SELECT (SELECT MAX(c) FROM t1, t2)
FROM t2
WHERE c = (SELECT MAX(b) FROM t2)
LIMIT ROWS EXAMINED 3;
+set expensive_subquery_limit=default;
+
drop table t1, t2;
--echo
diff --git a/mysql-test/main/outfile.result b/mysql-test/main/outfile.result
index 4c439c3..50ae130 100644
Binary files a/mysql-test/main/outfile.result and b/mysql-test/main/outfile.result differ
diff --git a/mysql-test/main/outfile.test b/mysql-test/main/outfile.test
index 9f2fc22..e5294f0 100644
--- a/mysql-test/main/outfile.test
+++ b/mysql-test/main/outfile.test
@@ -62,6 +62,7 @@ select load_file(concat(@tmpdir,"/outfile-test.4"));
#
CREATE TABLE t1 (a INT);
+--error ER_OPTION_PREVENTS_STATEMENT
EXPLAIN
SELECT *
INTO OUTFILE '/tmp/t1.txt'
diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result
index a8cad01..e2f8800 100644
--- a/mysql-test/main/subselect_mat.result
+++ b/mysql-test/main/subselect_mat.result
@@ -2872,7 +2872,7 @@ EXPLAIN
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
-3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1);
(SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1)
diff --git a/mysql-test/main/type_year.result b/mysql-test/main/type_year.result
index aaee504..b99a566 100644
--- a/mysql-test/main/type_year.result
+++ b/mysql-test/main/type_year.result
@@ -398,7 +398,6 @@ a
00
select a from t1 where a=y2k();
a
-00
select a from t1 where a=b;
a
drop table t1;
diff --git a/sql/field.cc b/sql/field.cc
index 5a618a5..bff8e90 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1387,7 +1387,9 @@ bool Field::can_optimize_range(const Item_bool_func *cond,
{
DBUG_ASSERT(cmp_type() != TIME_RESULT); // Handled in Field_temporal
DBUG_ASSERT(cmp_type() != STRING_RESULT); // Handled in Field_str descendants
- return item->cmp_type() != TIME_RESULT;
+ return (item->cmp_type() != TIME_RESULT) &&
+ !(item->type() == Item::SUBSELECT_ITEM &&
+ ((Item_subselect *)item)->is_expensive());
}
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index fcdb2aa..c7295f1 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -5794,6 +5794,8 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
bool escape_used_in_parsing, CHARSET_INFO *cmp_cs,
int *escape)
{
+ if (thd->lex->context_analysis_only)
+ return false;
/*
ESCAPE clause accepts only constant arguments and Item_param.
@@ -5803,9 +5805,13 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
reach val_int(), so we won't need the value.
CONTEXT_ANALYSIS_ONLY_DERIVED being a notable exception here.
*/
+#if 0
if (!escape_item->const_during_execution() ||
(!escape_item->const_item() &&
!(thd->lex->context_analysis_only & ~CONTEXT_ANALYSIS_ONLY_DERIVED)))
+#else
+ if (!escape_item->const_item())
+#endif
{
my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
return TRUE;
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 9e6c205..ff366ad 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1019,7 +1019,11 @@ table_map Item_subselect::used_tables() const
bool Item_subselect::const_item() const
{
DBUG_ASSERT(thd);
- return (thd->lex->context_analysis_only || with_recursive_reference ?
+ if (unit->executed_at_prepare_phase() && !thd->lex->context_analysis_only)
+ return true;
+ return (!(thd->lex->m_sql_cmd &&
+ thd->lex->m_sql_cmd->is_prepared()) ||
+ with_recursive_reference ?
FALSE :
forced_const || const_item_cache);
}
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index b284189..a22ed36 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -4214,6 +4214,8 @@ my_bool Query_cache::ask_handler_allowance(THD *thd,
for (; tables_used; tables_used= tables_used->next_global)
{
+ if (tables_used->is_view_or_derived())
+ continue;
TABLE *table;
handler *handler;
if (!(table= tables_used->table))
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index c6a929d..08dc375 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -643,6 +643,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
table_map_for_update(0),
m_examined_row_count(0),
accessed_rows_and_keys(0),
+ accessed_rows_and_keys_at_exec_start(0),
m_digest(NULL),
m_statement_psi(NULL),
m_transaction_psi(NULL),
diff --git a/sql/sql_class.h b/sql/sql_class.h
index b54f35a..e0c3256 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3420,6 +3420,7 @@ class THD: public THD_count, /* this must be first */
changed or written.
*/
ulonglong accessed_rows_and_keys;
+ ulonglong accessed_rows_and_keys_at_exec_start;
/**
Check if the number of rows accessed by a statement exceeded
@@ -3427,7 +3428,8 @@ class THD: public THD_count, /* this must be first */
*/
inline void check_limit_rows_examined()
{
- if (++accessed_rows_and_keys > lex->limit_rows_examined_cnt)
+ if ((++accessed_rows_and_keys - accessed_rows_and_keys_at_exec_start) >
+ lex->limit_rows_examined_cnt)
set_killed(ABORT_QUERY);
}
diff --git a/sql/sql_delete.h b/sql/sql_delete.h
index ad018ed..50d37ce 100644
--- a/sql/sql_delete.h
+++ b/sql/sql_delete.h
@@ -84,7 +84,7 @@ class Sql_cmd_delete final : public Sql_cmd_dml
private:
/**
- @biefSpecial handling of single-table deletes after prepare phase
+ @brief Special handling of single-table deletes after prepare phase
*/
bool delete_from_single_table(THD *thd);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 6e042d2..5228cff 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -5331,3 +5331,130 @@ void select_create::abort_result_set()
DBUG_VOID_RETURN;
}
+
+
+bool Sql_cmd_insert_base::precheck(THD *thd)
+{
+#if 0
+ /*
+ Since INSERT DELAYED doesn't support temporary tables, we could
+ not pre-open temporary tables for SQLCOM_INSERT / SQLCOM_REPLACE.
+ Open them here instead.
+ */
+ if (first_table->lock_type != TL_WRITE_DELAYED &&
+ thd->open_temporary_tables(lex->query_tables))
+ return true;
+
+ if (insert_precheck(thd, lex->query_tables))
+ return true;
+
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE);
+
+ return false;
+
+#ifdef WITH_WSREP
+wsrep_error_label:
+#endif
+#endif
+ return true;
+}
+
+
+bool Sql_cmd_insert_base::prepare_inner(THD *thd)
+{
+#if 0
+ SELECT_LEX *const select_lex= thd->lex->first_select_lex();
+ TABLE_LIST *const table_list= select_lex->get_table_list();
+ Name_resolution_context *context= &select_lex->context;
+ Name_resolution_context_state ctx_state;
+ const bool select_insert= insert_many_values.elements == 0;
+ bool insert_into_view= (table_list->view != 0);
+ TABLE *table;
+
+ DBUG_ENTER("Sql_cmd_insert_base::prepare_inner");
+
+ (void) read_statistics_for_tables_if_needed(thd, table_list);
+
+ {
+ if (mysql_handle_derived(lex, DT_INIT))
+ DBUG_RETURN(TRUE);
+ if (mysql_handle_derived(lex, DT_MERGE_FOR_INSERT))
+ DBUG_RETURN(TRUE);
+ if (mysql_handle_derived(lex, DT_PREPARE))
+ DBUG_RETURN(TRUE);
+ }
+
+ insert_field_list= thd->lex->field_list;
+
+ if (duplicates == DUP_UPDATE)
+ {
+ /* it should be allocated before Item::fix_fields() */
+ if (table_list->set_insert_values(thd->mem_root))
+ DBUG_RETURN(TRUE);
+ }
+
+ table= table_list->table;
+
+ if (table->file->check_if_updates_are_ignored("INSERT"))
+ DBUG_RETURN(-1);
+
+ if (!table_list->single_table_updatable())
+ {
+ my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT");
+ DBUG_RETURN(TRUE);
+ }
+
+ /*
+ first table in list is the one we'll INSERT into, requires INSERT_ACL.
+ all others require SELECT_ACL only. the ACL requirement below is for
+ new leaves only anyway (view-constituents), so check for SELECT rather
+ than INSERT.
+ */
+ if (setup_tables_and_check_access(thd,
+ &select_lex->context,
+ &select_lex->top_join_list,
+ table_list,
+ select_lex->leaf_tables,
+ select_insert, INSERT_ACL, SELECT_ACL,
+ TRUE))
+ DBUG_RETURN(TRUE);
+
+ if (insert_into_view && !insert_field_list.elements)
+ {
+ thd->lex->empty_field_list_on_rset= 1;
+ if (!table_list->table || table_list->is_multitable())
+ {
+ my_error(ER_VIEW_NO_INSERT_FIELD_LIST, MYF(0),
+ table_list->view_db.str, table_list->view_name.str);
+ DBUG_RETURN(TRUE);
+ }
+ if (insert_view_fields(thd, &insert_field_list, table_list))
+ DBUG_RETURN(TRUE);
+ }
+
+ if (thd->lex->has_returning())
+ {
+ status_var_increment(thd->status_var.feature_insert_returning);
+
+ /* This is INSERT ... RETURNING. It will return output to the client */
+ if (thd->lex->analyze_stmt)
+ {
+ /*
+ Actually, it is ANALYZE .. INSERT .. RETURNING. We need to produce
+ output and then discard it.
+ */
+ result= new (thd->mem_root) select_send_analyze(thd);
+ save_protocol= thd->protocol;
+ thd->protocol= new Protocol_discard(thd);
+ }
+ else
+ {
+ if (!(result= new (thd->mem_root) select_send(thd)))
+ DBUG_RETURN(TRUE);
+ }
+ }
+#else
+ return false;
+#endif
+}
+
diff --git a/sql/sql_insert.h b/sql/sql_insert.h
index 8b034c2..eae3b53 100644
--- a/sql/sql_insert.h
+++ b/sql/sql_insert.h
@@ -18,6 +18,7 @@
#include "sql_class.h" /* enum_duplicates */
#include "sql_list.h"
+#include "sql_base.h"
/* Instead of including sql_lex.h we add this typedef here */
typedef List<Item> List_item;
@@ -51,4 +52,139 @@ bool binlog_drop_table(THD *thd, TABLE *table);
inline void kill_delayed_threads(void) {}
#endif
+
+/**
+ Base class for all INSERT and REPLACE statements. Abstract class that
+ is inherited by Sql_cmd_insert_values and Sql_cmd_insert_select.
+*/
+
+class Sql_cmd_insert_base : public Sql_cmd_dml
+{
+protected:
+ virtual bool precheck(THD *thd) override;
+
+ virtual bool prepare_inner(THD *thd) override;
+
+private:
+ bool resolve_update_expressions(THD *thd);
+ bool prepare_values_table(THD *thd);
+ bool resolve_values_table_columns(THD *thd);
+
+ /**
+ Field list to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... (col1, ... colN) VALUES ... syntax
+ this is a list of col1, ..., colN fields.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this is a list of col1, ... colM fields as well.
+ */
+ List<Item> insert_field_list;
+
+public:
+ /*
+ field_list was created for view and should be removed before PS/SP
+ rexecuton
+ */
+ bool empty_field_list_on_rset;
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+ const bool is_replace;
+
+ /**
+ Row data to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... VALUES (row1), (row2), ... (rowN) syntax
+ the list contains N List_item lists: one List_item per row.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this list contains only 1 List_item of M data values: this way we
+ emulate this syntax:
+ INSERT/REPLACE ... (col1, ... colM) VALUE (x1, ..., xM);
+ */
+ List<List_item> insert_many_values;
+
+ /*
+ Number of values per row in insert_many_values, available after resolving
+ */
+ uint value_count;
+
+ /* ON DUPLICATE KEY UPDATE field list */
+ List<Item> update_field_list;
+
+ const enum_duplicates duplicates;
+
+ Protocol *save_protocol; /**< needed for ANALYZE .. INSERT .. RETURNING */
+
+ explicit Sql_cmd_insert_base(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : empty_field_list_on_rset(false),
+ is_replace(is_replace_arg),
+ value_count(0),
+ duplicates(duplicates_arg),
+ save_protocol(NULL)
+ {}
+
+#if 0
+ virtual void cleanup(THD *thd) override
+ {
+ if (empty_field_list_on_rset)
+ {
+ empty_field_list_on_rset = false;
+ insert_field_list.empty();
+ }
+ }
+#endif
+
+private:
+
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+};
+
+
+/**
+ Class that implements INSERT ... VALUES and REPLACE ... VALUES statements.
+*/
+
+class Sql_cmd_insert_values final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_values(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE : SQLCOM_INSERT;
+ }
+
+};
+
+
+/**
+ Class that implements INSERT ... SELECT and REPLACE ... SELECT statements.
+*/
+
+class Sql_cmd_insert_select final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_select(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE_SELECT : SQLCOM_INSERT_SELECT;
+ }
+};
+
+
+
#endif /* SQL_INSERT_INCLUDED */
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 8a24d2f..0b08fbc 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -42,6 +42,8 @@
#endif
#include "sql_update.h" // class Sql_cmd_update
#include "sql_delete.h" // class Sql_cmd_delete
+#include "sql_insert.h" // class Sql_cmd_insert
+
void LEX::parse_error(uint err_number)
{
@@ -10357,13 +10359,19 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit)
bool LEX::parsed_insert_select(SELECT_LEX *first_select)
{
+ bool is_insert_or_replace= false;
+ bool is_replace= false;
if (sql_command == SQLCOM_INSERT ||
sql_command == SQLCOM_REPLACE)
{
+ is_insert_or_replace= true;
if (sql_command == SQLCOM_INSERT)
sql_command= SQLCOM_INSERT_SELECT;
else
+ {
+ is_replace= true;
sql_command= SQLCOM_REPLACE_SELECT;
+ }
}
insert_select_hack(first_select);
if (check_main_unit_semantics())
@@ -10373,6 +10381,23 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
SELECT_LEX *blt __attribute__((unused))= pop_select();
DBUG_ASSERT(blt == &builtin_select);
push_select(first_select);
+
+ if (is_insert_or_replace)
+ {
+ if (sql_command == SQLCOM_INSERT || sql_command == SQLCOM_REPLACE)
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_values(is_replace,
+ duplicates)))
+ return true;
+ }
+ else
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_select(is_replace,
+ duplicates)))
+ return true;
+ }
+ }
+
return false;
}
@@ -10454,6 +10479,8 @@ bool LEX::select_finalize(st_select_lex_unit *expr)
{
sql_command= SQLCOM_SELECT;
selects_allow_procedure= TRUE;
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_select(result)))
+ return true;
if (set_main_unit(expr))
return true;
return check_main_unit_semantics();
@@ -11933,3 +11960,27 @@ bool SELECT_LEX_UNIT::is_derived_eliminated() const
return true;
return derived->table->map & outer_select()->join->eliminated_tables;
}
+
+bool SELECT_LEX_UNIT::executed_at_prepare_phase()
+{
+ for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
+ {
+ if (!sl->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
+
+bool SELECT_LEX::executed_at_prepare_phase()
+{
+ if (table_list.elements || is_correlated)
+ return false;
+ for (st_select_lex_unit *unit= first_inner_unit();
+ unit;
+ unit= unit->next_unit())
+ {
+ if (!unit->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 5a7fa14..491ea1c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1034,6 +1034,8 @@ class st_select_lex_unit: public st_select_lex_node {
bool explainable() const;
+ bool executed_at_prepare_phase();
+
void reset_distinct();
void fix_distinct();
@@ -1480,6 +1482,8 @@ class st_select_lex: public st_select_lex_node
ORDER *order,
enum_query_type query_type);
void print_limit(THD *thd, String *str, enum_query_type query_type);
+ bool prepare(THD *thd, select_result *result);
+ bool exec(THD *thd);
void fix_prepare_information(THD *thd, Item **conds, Item **having_conds);
/*
Destroy the used execution plan (JOIN) of this subtree (this
@@ -1653,6 +1657,7 @@ class st_select_lex: public st_select_lex_node
bool is_unit_nest() { return (nest_flags & UNIT_NEST_FL); }
void mark_as_unit_nest() { nest_flags= UNIT_NEST_FL; }
bool is_sj_conversion_prohibited(THD *thd);
+ bool executed_at_prepare_phase();
};
typedef class st_select_lex SELECT_LEX;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 67353a1..c7bc972 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3907,7 +3907,9 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SHOW_STORAGE_ENGINES:
case SQLCOM_SHOW_PROFILE:
+#if 0
case SQLCOM_SELECT:
+#endif
{
#ifdef WITH_WSREP
if (lex->sql_command == SQLCOM_SELECT)
@@ -4382,6 +4384,17 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
break;
}
+ case SQLCOM_SELECT:
+ {
+ res = lex->m_sql_cmd->execute(thd);
+ break;
+ }
+#if 0
+ case SQLCOM_REPLACE:
+ case SQLCOM_INSERT:
+ case SQLCOM_REPLACE_SELECT:
+ case SQLCOM_INSERT_SELECT:
+#endif
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
case SQLCOM_DELETE:
@@ -4394,6 +4407,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
thd->abort_on_warning= 0;
break;
}
+#if 1
case SQLCOM_REPLACE:
if ((res= generate_incident_event(thd)))
break;
@@ -4653,6 +4667,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
break;
}
+#endif
case SQLCOM_DROP_SEQUENCE:
case SQLCOM_DROP_TABLE:
{
@@ -7340,6 +7355,7 @@ void THD::reset_for_next_command(bool do_clear_error)
get_stmt_da()->reset_for_next_command();
m_sent_row_count= m_examined_row_count= 0;
accessed_rows_and_keys= 0;
+ accessed_rows_and_keys_at_exec_start= 0;
reset_slow_query_state();
@@ -7476,6 +7492,8 @@ void create_select_for_variable(THD *thd, LEX_CSTRING *var_name)
lex= thd->lex;
lex->init_select();
lex->sql_command= SQLCOM_SELECT;
+ lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_select(thd->lex->result);
+
/*
We set the name of Item to @@session.var_name because that then is used
as the column name in the output.
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 22780c8..0bbde42 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2268,6 +2268,48 @@ static bool check_prepared_statement(Prepared_statement *stmt)
lex->m_sql_cmd->unprepare(thd);
break;
+ case SQLCOM_SELECT:
+#if 0
+ if (lex->m_sql_cmd == NULL &&
+ !(lex->m_sql_cmd=
+ new (thd->mem_root) Sql_cmd_select(thd->lex->result)))
+ {
+ res= 1;
+ break;
+ }
+#endif
+ lex->m_sql_cmd->set_owner(stmt);
+ res = lex->m_sql_cmd->prepare(thd);
+ if (res == 2)
+ {
+ /* Statement and field info has already been sent */
+ DBUG_RETURN(FALSE);
+ }
+ if (!res && !lex->describe && !lex->analyze_stmt && !stmt->is_sql_prepare())
+ {
+ SELECT_LEX_UNIT *const unit = &lex->unit;
+ /* Make copy of item list, as change_columns may change it */
+ SELECT_LEX_UNIT* master_unit= unit->first_select()->master_unit();
+ bool is_union_op=
+ master_unit->is_unit_op() || master_unit->fake_select_lex;
+
+ List<Item> fields(is_union_op ? unit->item_list :
+ lex->first_select_lex()->item_list);
+
+ /* Change columns if a procedure like analyse() */
+ res= (unit->last_procedure &&
+ unit->last_procedure->change_columns(thd, fields));
+
+ if (res || send_prep_stmt(stmt, lex->result->field_count(fields)) ||
+ lex->result->send_result_set_metadata(fields,
+ Protocol::SEND_EOF) ||
+ thd->protocol->flush())
+ res= true;
+ }
+ if (!res)
+ lex->m_sql_cmd->unprepare(thd);
+ break;
+
/* The following allow WHERE clause, so they must be tested like SELECT */
case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_TABLES:
@@ -2285,7 +2327,9 @@ static bool check_prepared_statement(Prepared_statement *stmt)
case SQLCOM_SHOW_STATUS_FUNC:
case SQLCOM_SHOW_STATUS_PACKAGE:
case SQLCOM_SHOW_STATUS_PACKAGE_BODY:
+#if 0
case SQLCOM_SELECT:
+#endif
res= mysql_test_select(stmt, tables);
if (res == 2)
{
@@ -2469,12 +2513,14 @@ static bool check_prepared_statement(Prepared_statement *stmt)
lex->describe, lex->analyze_stmt) ||
send_prep_stmt(stmt, result.field_count(field_list)) ||
result.send_result_set_metadata(field_list,
- Protocol::SEND_EOF);
+ Protocol::SEND_EOF) ||
+ thd->protocol->flush();
+ }
+ else if (lex->sql_command != SQLCOM_SELECT)
+ {
+ res= send_prep_stmt(stmt, 0) ||
+ thd->protocol->flush();
}
- else
- res= send_prep_stmt(stmt, 0);
- if (!res)
- thd->protocol->flush();
}
DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 4b01a96..88bdfaa 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -55,6 +55,9 @@
#include "sql_cte.h"
#include "sql_window.h"
#include "tztime.h"
+#ifdef WITH_WSREP
+#include "wsrep_mysqld.h"
+#endif
#include "debug_sync.h" // DEBUG_SYNC
#include <m_ctype.h>
@@ -4989,21 +4992,22 @@ void JOIN::cleanup_item_list(List<Item> &items) const
0 otherwise
*/
-select_handler *find_select_handler(THD *thd,
- SELECT_LEX* select_lex)
+select_handler *SELECT_LEX::find_select_handler(THD *thd)
{
- if (select_lex->next_select())
+ if (next_select())
return 0;
- if (select_lex->master_unit()->outer_select())
+ if (master_unit()->outer_select())
return 0;
TABLE_LIST *tbl= nullptr;
- // For SQLCOM_INSERT_SELECT the server takes TABLE_LIST
- // from thd->lex->query_tables and skips its first table
- // b/c it is the target table for the INSERT..SELECT.
+ /*
+ For SQLCOM_INSERT_SELECT the server takes TABLE_LIST
+ from thd->lex->query_tables and skips its first table
+ b/c it is the target table for the INSERT..SELECT.
+ */
if (thd->lex->sql_command != SQLCOM_INSERT_SELECT)
{
- tbl= select_lex->join->tables_list;
+ tbl= join->tables_list;
}
else if (thd->lex->query_tables &&
thd->lex->query_tables->next_global)
@@ -5020,7 +5024,7 @@ select_handler *find_select_handler(THD *thd,
handlerton *ht= tbl->table->file->partition_ht();
if (!ht->create_select)
continue;
- select_handler *sh= ht->create_select(thd, select_lex);
+ select_handler *sh= ht->create_select(thd, this);
return sh;
}
return 0;
@@ -5136,7 +5140,7 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
thd->get_stmt_da()->reset_current_row_for_warning(1);
/* Look for a table owned by an engine with the select_handler interface */
- select_lex->pushdown_select= find_select_handler(thd, select_lex);
+ select_lex->pushdown_select= select_lex->find_select_handler(thd);
if ((err= join->optimize()))
{
@@ -12720,7 +12724,8 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
(select thats very heavy) => is a constant here
eg: (select avg(order_cost) from orders) => constant but expensive
*/
- if (!keyuse->val->used_tables() && !thd->lex->describe)
+ if (keyuse->val->const_item() && !keyuse->val->is_expensive() &&
+ !thd->lex->describe)
{ // Compare against constant
store_key_item tmp(thd,
keyinfo->key_part[i].field,
@@ -32348,6 +32353,9 @@ static void MYSQL_DML_START(THD *thd)
{
switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ MYSQL_INSERT_START(thd->query());
+ break;
case SQLCOM_UPDATE:
MYSQL_UPDATE_START(thd->query());
break;
@@ -32370,6 +32378,9 @@ static void MYSQL_DML_DONE(THD *thd, int rc)
{
switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ MYSQL_SELECT_DONE(rc, (rc ? 0 : (ulong) (thd->limit_found_rows)));
+ break;
case SQLCOM_UPDATE:
MYSQL_UPDATE_DONE(
rc,
@@ -32437,8 +32448,6 @@ bool Sql_cmd_dml::prepare(THD *thd)
MYSQL_DML_START(thd);
- lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_DERIVED;
-
if (open_tables_for_query(thd, lex->query_tables, &table_count, 0,
get_dml_prelocking_strategy()))
{
@@ -32451,8 +32460,6 @@ bool Sql_cmd_dml::prepare(THD *thd)
if (prepare_inner(thd))
goto err;
- lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_DERIVED;
-
set_prepared();
unit->set_prepared();
@@ -32528,6 +32535,7 @@ bool Sql_cmd_dml::execute(THD *thd)
{
if (lock_tables(thd, lex->query_tables, table_count, 0))
goto err;
+ query_cache_store_query(thd, thd->lex->query_tables);
}
unit->set_limit(select_lex);
@@ -32581,8 +32589,266 @@ bool Sql_cmd_dml::execute(THD *thd)
bool Sql_cmd_dml::execute_inner(THD *thd)
{
SELECT_LEX_UNIT *unit = &lex->unit;
- SELECT_LEX *select_lex= unit->first_select();
- JOIN *join= select_lex->join;
+ DBUG_ENTER("Sql_cmd_dml::execute_inner");
+
+ if (unit->is_unit_op() || unit->fake_select_lex)
+ {
+ if (unit->exec())
+ DBUG_RETURN(true);
+ }
+#if 1
+ else
+ {
+ SELECT_LEX *select_lex= unit->first_select();
+ if (select_lex->exec(thd))
+ DBUG_RETURN(true);
+ }
+#endif
+
+ DBUG_RETURN(false);
+}
+
+
+bool Sql_cmd_select::precheck(THD *thd)
+{
+ bool rc= false;
+
+ privilege_t privileges_requested= SELECT_ACL;
+
+ if (lex->exchange)
+ {
+ /*
+ lex->exchange != NULL implies SELECT .. INTO OUTFILE and this
+ requires FILE_ACL access.
+ */
+ privileges_requested|= FILE_ACL;
+ }
+
+ TABLE_LIST *tables = thd->lex->query_tables;
+
+ if (tables)
+ rc= check_table_access(thd, privileges_requested,
+ tables, false, UINT_MAX, false);
+ else
+ rc= check_access(thd, privileges_requested,
+ any_db.str, NULL, NULL, false, false);
+
+#ifdef WITH_WSREP
+ if (lex->sql_command == SQLCOM_SELECT)
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_READ);
+ }
+ else
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW);
+# ifdef ENABLED_PROFILING
+ if (lex->sql_command == SQLCOM_SHOW_PROFILE)
+ thd->profiling.discard_current_query();
+# endif
+ }
+#endif /* WITH_WSREP */
+
+ if (!rc)
+ return false;
+
+#ifdef WITH_WSREP
+wsrep_error_label:
+#endif
+ return true;
+}
+
+
+
+bool Sql_cmd_select::prepare_inner(THD *thd)
+{
+ bool rc= false;
+ LEX *lex= thd->lex;
+ TABLE_LIST *tables= lex->query_tables;
+ SELECT_LEX_UNIT *const unit = &lex->unit;
+
+ DBUG_ENTER("Sql_cmd_select::prepare_inner");
+
+ if (!thd->stmt_arena->is_stmt_prepare())
+ (void) read_statistics_for_tables_if_needed(thd, tables);
+
+ {
+ if (mysql_handle_derived(lex, DT_INIT))
+ DBUG_RETURN(TRUE);
+ }
+
+ if (thd->stmt_arena->is_stmt_prepare())
+ {
+ if (!result)
+ {
+ Query_arena backup;
+ Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup);
+ result= new (thd->mem_root) select_send(thd);
+ if (arena)
+ thd->restore_active_arena(arena, &backup);
+ thd->lex->result= result;
+ }
+ rc= unit->prepare(unit->derived, 0, 0);
+
+ }
+ else
+ {
+ if (lex->analyze_stmt)
+ {
+ if (result && result->result_interceptor())
+ result->result_interceptor()->disable_my_ok_calls();
+ else
+ {
+ DBUG_ASSERT(thd->protocol);
+ result= new (thd->mem_root) select_send_analyze(thd);
+ save_protocol= thd->protocol;
+ thd->protocol= new Protocol_discard(thd);
+ }
+ }
+ else if (!(result= lex->result))
+ result= new (thd->mem_root) select_send(thd);
+ if (!result)
+ DBUG_RETURN(TRUE);
+
+ SELECT_LEX *parameters = unit->global_parameters();
+ if (!parameters->limit_params.explicit_limit)
+ {
+ parameters->limit_params.select_limit =
+ new (thd->mem_root) Item_int(thd,
+ (ulonglong) thd->variables.select_limit);
+ if (parameters->limit_params.select_limit == NULL)
+ DBUG_RETURN(true); /* purecov: inspected */
+ }
+ ulonglong select_options= 0;
+ if (lex->describe)
+ select_options|= SELECT_DESCRIBE;
+ if (unit->is_unit_op() || unit->fake_select_lex)
+ select_options|= SELECT_NO_UNLOCK;
+ rc= unit->prepare(unit->derived, result, select_options);
+
+ if (rc && thd->lex->analyze_stmt && save_protocol)
+ {
+ delete thd->protocol;
+ thd->protocol= save_protocol;
+ }
+ }
+
+ DBUG_RETURN(rc);
+}
+
+
+bool Sql_cmd_select::execute_inner(THD *thd)
+{
+ DBUG_ENTER("Sql_cmd_select::execute_inner");
+
+ thd->status_var.last_query_cost= 0.0;
+
+ bool res= Sql_cmd_dml::execute_inner(thd);
+
+ res|= thd->is_error();
+ if (unlikely(res))
+ result->abort_result_set();
+
+ if (result != thd->lex->result)
+ {
+ delete result;
+ result= 0;
+ }
+
+ if (lex->analyze_stmt)
+ {
+ if (save_protocol)
+ {
+ delete thd->protocol;
+ thd->protocol= save_protocol;
+ }
+ if (!res)
+ res= thd->lex->explain->send_explain(thd);
+ }
+
+ if (thd->lex->describe)
+ {
+ if (!res)
+ res= thd->lex->explain->send_explain(thd);
+
+ if (!res && (thd->lex->describe & DESCRIBE_EXTENDED))
+ {
+ char buff[1024];
+ String str(buff,(uint32) sizeof(buff), system_charset_info);
+ str.length(0);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str.c_ptr_safe());
+ }
+ }
+
+ if (unlikely(thd->killed == ABORT_QUERY && !thd->no_errors))
+ {
+ /*
+ If LIMIT ROWS EXAMINED interrupted query execution, issue a warning,
+ continue with normal processing and produce an incomplete query result.
+ */
+ bool saved_abort_on_warning= thd->abort_on_warning;
+ thd->abort_on_warning= false;
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT,
+ ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT),
+ thd->accessed_rows_and_keys -
+ thd->accessed_rows_and_keys_at_exec_start,
+ thd->lex->limit_rows_examined->val_uint());
+ thd->abort_on_warning= saved_abort_on_warning;
+ thd->reset_killed();
+ }
+ /* Disable LIMIT ROWS EXAMINED after query execution. */
+ thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX;
+
+ /* Count number of empty select queries */
+ if (!thd->get_sent_row_count() && !res)
+ status_var_increment(thd->status_var.empty_queries);
+ else
+ status_var_add(thd->status_var.rows_sent, thd->get_sent_row_count());
+
+ DBUG_RETURN(res);
+}
+
+
+bool st_select_lex::prepare(THD *thd, select_result *result)
+{
+ ulonglong select_options= options | thd->variables.option_bits;
+
+ DBUG_ENTER("st_select_lex::prepare");
+
+ if (thd->lex->describe)
+ select_options|= SELECT_DESCRIBE;
+
+ if (!(join= new (thd->mem_root) JOIN(thd, item_list,
+ select_options, result)))
+ DBUG_RETURN(true);
+
+ SELECT_LEX_UNIT *unit= master_unit();
+
+ thd->lex->used_tables=0;
+
+ if (join->prepare(table_list.first, where,
+ order_list.elements + group_list.elements,
+ order_list.first, false, group_list.first,
+ having, thd->lex->proc_list.first,
+ this, unit))
+ DBUG_RETURN(true);
+
+ DBUG_RETURN(false);
+}
+
+
+bool st_select_lex::exec(THD *thd)
+{
+ DBUG_ENTER("st_select_lex::exec");
+
+ /* Look for a table owned by an engine with the select_handler interface */
+ pushdown_select= find_select_handler(thd);
if (join->optimize())
goto err;
@@ -32596,19 +32862,29 @@ bool Sql_cmd_dml::execute_inner(THD *thd)
if (unlikely(thd->is_error()))
goto err;
- if (join->exec())
+ thd->get_stmt_da()->reset_current_row_for_warning(1);
+
+ if (master_unit()->outer_select() == NULL)
+ thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys;
+
+ if (join->exec()
goto err;
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
- select_lex->where= join->conds_history;
- select_lex->having= join->having_history;
+ where= join->conds_history;
+ having= join->having_history;
}
err:
- return join->error;
-}
+ if (pushdown_select)
+ {
+ delete pushdown_select;
+ pushdown_select= NULL;
+ }
+ DBUG_RETURN(join->error);
+}
/**
@} (end of group Query_Optimizer)
diff --git a/sql/sql_select.h b/sql/sql_select.h
index f908484..edbaed3 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -33,6 +33,8 @@
#include "records.h" /* READ_RECORD */
#include "opt_range.h" /* SQL_SELECT, QUICK_SELECT_I */
#include "filesort.h"
+#include "sql_base.h"
+#include "sql_cmd.h"
typedef struct st_join_table JOIN_TAB;
/* Values in optimize */
@@ -2629,4 +2631,39 @@ void propagate_new_equalities(THD *thd, Item *cond,
bool *is_simplifiable_cond);
bool dbug_user_var_equals_str(THD *thd, const char *name, const char *value);
+
+
+class Sql_cmd_select : public Sql_cmd_dml
+{
+public:
+ explicit Sql_cmd_select(select_result *result_arg)
+ : Sql_cmd_dml(), save_protocol(NULL)
+ { result= result_arg; }
+
+ enum_sql_command sql_command_code() const override
+ {
+ return SQLCOM_SELECT;
+ }
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+
+ bool precheck(THD *thd) override;
+
+ bool prepare_inner(THD *thd) override;
+
+ bool execute_inner(THD *thd) override;
+
+private:
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+ Protocol *save_protocol;
+};
+
+
#endif /* SQL_SELECT_INCLUDED */
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index c1f28ba..0cc1e68 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1322,6 +1322,24 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
describe= additional_options & SELECT_DESCRIBE;
+ if (describe)
+ {
+ for (SELECT_LEX *sl= first_sl; sl; sl= sl->next_select())
+ {
+ sl->set_explain_type(FALSE);
+ sl->options|= SELECT_DESCRIBE;
+ }
+ if (is_unit_op() || fake_select_lex)
+ {
+ if (union_needs_tmp_table() && fake_select_lex)
+ {
+ fake_select_lex->select_number= FAKE_SELECT_LEX_ID; // just for initialization
+ fake_select_lex->type= unit_operation_text[common_op()];
+ fake_select_lex->options|= SELECT_DESCRIBE;
+ }
+ }
+ }
+
/*
Save fake_select_lex in case we don't need it for anything but
global parameters.
@@ -2160,6 +2178,8 @@ bool st_select_lex_unit::exec()
bool was_executed= executed;
DBUG_ENTER("st_select_lex_unit::exec");
+ describe= thd->lex->describe;
+
if (executed && !uncacheable && !describe)
DBUG_RETURN(FALSE);
executed= 1;
@@ -2168,6 +2188,9 @@ bool st_select_lex_unit::exec()
item->make_const();
saved_error= optimize();
+
+ if (outer_select() == NULL)
+ thd->accessed_rows_and_keys_at_exec_start= thd->accessed_rows_and_keys;
create_explain_query_if_not_exists(thd->lex, thd->mem_root);
@@ -2239,6 +2262,7 @@ bool st_select_lex_unit::exec()
saved_error= sl->join->optimize();
}
}
+
if (likely(!saved_error))
{
records_at_start= table->file->stats.records;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 49655f8..886c0b6 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -71,6 +71,7 @@
#include "json_table.h"
#include "sql_update.h"
#include "sql_delete.h"
+#include "sql_insert.h"
/* this is to get the bison compilation windows warnings out */
#ifdef _MSC_VER
1
0
[Commits] fc18f9c: Adjusted test results after rebase of MDEV-7487 related commits against 11.1
by IgorBabaev 16 Mar '23
by IgorBabaev 16 Mar '23
16 Mar '23
revision-id: fc18f9c9ec15035894154fb7dcdd85caac73cfc2 (mariadb-11.0.1-35-gfc18f9c)
parent(s): 1e0a72a18b134106da59be4594836b6b66bbc539
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-15 18:29:05 -0700
message:
Adjusted test results after rebase of MDEV-7487 related commits against 11.1
---
mysql-test/main/delete_use_source_engines.result | 32 +++++++++++-----------
.../main/myisam_explain_non_select_all.result | 6 ++--
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/mysql-test/main/delete_use_source_engines.result b/mysql-test/main/delete_use_source_engines.result
index fd0d3b8..b1ad9c0 100644
--- a/mysql-test/main/delete_use_source_engines.result
+++ b/mysql-test/main/delete_use_source_engines.result
@@ -91,7 +91,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 12.00 100.00 5.56 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.00 3.12 5.56 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -183,7 +183,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 12.50 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 24.50 100.00 1.02 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 24.50 3.12 1.02 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 2 2
@@ -647,7 +647,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 100.00 5.71 Using where; Using index; FirstMatch(t1)
+1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 3.12 5.71 Using where; Using index; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -783,8 +783,8 @@ order by c3 desc limit 1;
explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
-1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using where; FirstMatch(t1)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 1;
id select_type table type possible_keys key key_len ref rows Extra
@@ -1204,7 +1204,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 12.33 100.00 5.41 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.33 3.12 5.41 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -1854,7 +1854,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 12.67 100.00 5.26 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.67 3.12 5.26 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -1946,7 +1946,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 25.00 100.00 12.00 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 22.67 100.00 1.47 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 22.67 3.12 1.47 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 2 2
@@ -2625,7 +2625,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 100.00 5.71 Using where; Using index; FirstMatch(t1)
+1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 3.12 5.71 Using where; Using index; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -3394,7 +3394,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 12.00 100.00 5.56 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.00 3.12 5.56 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -4259,7 +4259,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 12.67 100.00 5.26 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.67 3.12 5.26 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -4351,7 +4351,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 25.00 100.00 12.00 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 22.67 100.00 1.47 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 22.67 3.12 1.47 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 2 2
@@ -5030,7 +5030,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 100.00 5.71 Using where; Using index; FirstMatch(t1)
+1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 3.12 5.71 Using where; Using index; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
@@ -5166,8 +5166,8 @@ order by c3 desc limit 1;
explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
-1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using where; FirstMatch(t1)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 1;
id select_type table type possible_keys key key_len ref rows Extra
@@ -5799,7 +5799,7 @@ id select_type table type possible_keys key key_len ref rows Extra
analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
-1 PRIMARY a ALL NULL NULL NULL NULL 32 13.33 100.00 5.00 Using where; FirstMatch(t1)
+1 PRIMARY a ALL NULL NULL NULL NULL 32 13.33 3.12 5.00 Using where; FirstMatch(t1)
select * from t1;
c1 c2 c3
1 3 3
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 8b2979b..28107af 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -270,7 +270,7 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 33.33 Using where; FirstMatch(t1)
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
# Status of EXPLAIN EXTENDED query
@@ -908,7 +908,7 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 25.00 Using where; FirstMatch(t1)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -994,7 +994,7 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
-1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch(t1)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; FirstMatch(t1)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
1
0
[Commits] fa896dc: MDEV-29390: Improve coverage for UPDATE and DELETE statements in MTR test suites
by IgorBabaev 15 Mar '23
by IgorBabaev 15 Mar '23
15 Mar '23
revision-id: fa896dc433f835bbde98619d5091c482d2586e07 (mariadb-11.0.1-28-gfa896dc)
parent(s): 2ae8dc24351b830fd15970758b65f58caf504678
author: Lena Startseva
committer: Igor Babaev
timestamp: 2023-03-15 14:19:02 -0700
message:
MDEV-29390: Improve coverage for UPDATE and DELETE statements in MTR test suites
Created tests for "delete" based on update_use_source.test
For the update_use_source.test tests, data recovery in the table has been changed
from a rollback transaction to a complete delete and re-insert of the data with
optimize table. Cases are now being checked on three engines.
Added tests for update/delete with LooseScan and DuplicateWeedout optimization strategies
Added tests for engine MEMORY on delete and update
Added tests for multi-update with JSON_TABLE
Added tests for multi-update and multi-delete for engine Connect
---
mysql-test/include/delete_use_source.inc | 94 +
mysql-test/include/delete_use_source_cases.inc | 214 +
.../include/delete_use_source_cases_memory.inc | 294 +
.../include/delete_use_source_cases_non_innodb.inc | 81 +
mysql-test/include/delete_use_source_innodb.inc | 91 +
mysql-test/include/delete_use_source_memory.inc | 33 +
mysql-test/include/update_use_source.inc | 292 +-
mysql-test/include/update_use_source_cases.inc | 183 +
mysql-test/include/update_use_source_ext.inc | 59 +
mysql-test/main/delete_single_to_multi.result | 830 ++
mysql-test/main/delete_single_to_multi.test | 244 +
mysql-test/main/delete_use_source_engines.result | 8870 ++++++++++++++++
mysql-test/main/delete_use_source_engines.test | 42 +
mysql-test/main/update_single_to_multi.result | 615 ++
mysql-test/main/update_single_to_multi.test | 242 +
mysql-test/main/update_use_source.result | 10273 +++++++++++++++++--
mysql-test/main/update_use_source.test | 250 +-
mysql-test/suite/json/r/json_table.result | 101 +
mysql-test/suite/json/t/json_table.test | 94 +
storage/connect/mysql-test/connect/r/upd.result | 156 +
storage/connect/mysql-test/connect/t/upd.test | 96 +
21 files changed, 22157 insertions(+), 997 deletions(-)
diff --git a/mysql-test/include/delete_use_source.inc b/mysql-test/include/delete_use_source.inc
new file mode 100644
index 0000000..3f78976
--- /dev/null
+++ b/mysql-test/include/delete_use_source.inc
@@ -0,0 +1,94 @@
+create table t1 (c1 integer, c2 integer, c3 integer);
+
+insert into t1(c1,c2,c3)
+ 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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+
+create view v1 as select * from t1 where c2=2;
+
+--echo #######################################
+--echo # Test without any index #
+--echo #######################################
+--source include/delete_use_source_cases.inc
+--source include/delete_use_source_cases_non_innodb.inc
+
+--echo #######################################
+--echo # Test with an index #
+--echo #######################################
+create index t1_c2 on t1 (c2,c1);
+--source include/delete_use_source_cases.inc
+--source include/delete_use_source_cases_non_innodb.inc
+
+--echo #######################################
+--echo # Test with a primary key #
+--echo #######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+--source include/delete_use_source_cases.inc
+--source include/delete_use_source_cases_non_innodb.inc
+
+drop view v1;
+drop table t1;
+
+--echo #
+--echo # Test on dynamic columns (blob)
+--echo #
+create table assets (
+ item_name varchar(32) primary key, -- A common attribute for all items
+ dynamic_cols blob -- Dynamic columns will be stored here
+);
+
+INSERT INTO assets
+ VALUES ('MariaDB T-shirt',
+ COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets
+ VALUES ('Thinkpad Laptop',
+ COLUMN_CREATE('color', 'black', 'price', 500));
+INSERT INTO assets
+ VALUES ('Fridge',
+ COLUMN_CREATE('color', 'white', 'warranty', '5 years'));
+INSERT INTO assets
+ VALUES ('Microwave',
+ COLUMN_CREATE('warranty', '3 years'));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, 'color')
+ WHERE item_name='Fridge';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+DELETE FROM assets
+ WHERE item_name in
+ (select b.item_name from assets b
+ where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+DELETE FROM assets WHERE item_name='Microwave';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+drop table assets ;
+
+
+--echo #
+--echo # Test on fulltext columns
+--echo #
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+ ('MySQL vs MariaDB database'),
+ ('Oracle vs MariaDB database'),
+ ('PostgreSQL vs MariaDB database'),
+ ('MariaDB overview'),
+ ('Foreign keys'),
+ ('Primary keys'),
+ ('Indexes'),
+ ('Transactions'),
+ ('Triggers');
+
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+DELETE FROM ft2 WHERE MATCH(copy) AGAINST('database');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+drop table ft2;
+
diff --git a/mysql-test/include/delete_use_source_cases.inc b/mysql-test/include/delete_use_source_cases.inc
new file mode 100644
index 0000000..24408b7
--- /dev/null
+++ b/mysql-test/include/delete_use_source_cases.inc
@@ -0,0 +1,214 @@
+--echo #
+--echo # Delete with value from subquery on the same table
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with EXISTS subquery over the updated table
+--echo # in WHERE + possibly sargable condition
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+eval analyze $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with IN predicand over the updated table in WHERE
+--echo #
+let $c = c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with a limit - can be deleted
+--echo #
+let $c = c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+eval analyze $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with a limit and an order by
+--echo #
+
+let $c = c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete: 2 execution of PS
+--echo #
+
+prepare create_tmp_stmt from
+ "create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+ "delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+--sorted_result
+select * from t1;
+
+prepare insert_tmp_stmt from
+ "insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+--sorted_result
+select * from t1;
+
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+--sorted_result
+select * from t1;
+
+drop table tmp;
+
+--echo #
+--echo # Delete in stored procedure
+--echo #
+
+delimiter //;
+create procedure sp()
+begin
+ delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+end
+//
+delimiter ;//
+
+create table tmp as select * from t1
+ where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+ where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+ where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+CALL sp;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+
+--echo #
+--echo # Delete in stored function
+--echo #
+delimiter //;
+create function f1(IN a INT) returns int
+begin
+ delete from t1 where c3 < a order by c3 limit 1;
+ return 1;
+end;//
+delimiter ;//
+
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+ order by c3 limit 1;
+select f1(@a);
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+ order by c3 limit 1;
+select f1(@a);
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+
+--echo #
+--echo # Delete in trigger
+--echo #
+
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+ UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+ DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+--enable_info ONCE
+DELETE FROM t1 WHERE c2>=3;
+
+--sorted_result
+select * from t1;
+--sorted_result
+SELECT * FROM t2;
+SELECT * FROM cnt;
+
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+
+--echo #
+--echo # Delete with a reference to view in subquery
+--echo #
+let $c = t1.c2 in ( select max(a.c2) from v1 a
+ where a.c1 = t1.c1);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+eval analyze $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
diff --git a/mysql-test/include/delete_use_source_cases_memory.inc b/mysql-test/include/delete_use_source_cases_memory.inc
new file mode 100644
index 0000000..7a61b59
--- /dev/null
+++ b/mysql-test/include/delete_use_source_cases_memory.inc
@@ -0,0 +1,294 @@
+--echo #
+--echo # Delete with value from subquery on the same table
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with EXISTS subquery over the updated table
+--echo # in WHERE + possibly sargable condition
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with EXISTS subquery over the updated table
+--echo # in WHERE + non-sargable condition
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with order by
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = exists (select 'X' from t1 a where a.c2 = t1.c2)
+ and c2 >= 3 order by c2;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with IN predicand over the updated table in WHERE
+--echo #
+let $c = c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with a limit - can be deleted
+--echo #
+let $c = c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with a limit and an order by
+--echo #
+
+let $c = c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete: 2 execution of PS
+--echo #
+
+prepare create_tmp_stmt from
+ "create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+ "delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+--sorted_result
+select * from t1;
+
+prepare insert_tmp_stmt from
+ "insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+--sorted_result
+select * from t1;
+
+drop table tmp;
+
+--echo #
+--echo # Delete in stored procedure
+--echo #
+
+delimiter //;
+create procedure sp()
+begin
+ delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+end
+//
+delimiter ;//
+
+create table tmp as select * from t1
+ where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+ where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+ where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 1;
+CALL sp;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+
+--echo #
+--echo # Delete in stored function
+--echo #
+delimiter //;
+create function f1(IN a INT) returns int
+begin
+ delete from t1 where c3 < a order by c3 limit 1;
+ return 1;
+end;//
+delimiter ;//
+
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+ order by c3 limit 1;
+select f1(@a);
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+ order by c3 limit 1;
+select f1(@a);
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+
+--echo #
+--echo # Delete in trigger
+--echo #
+
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+ UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+ DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+--enable_info ONCE
+DELETE FROM t1 WHERE c2>=3;
+
+--sorted_result
+select * from t1;
+--sorted_result
+SELECT * FROM t2;
+SELECT * FROM cnt;
+
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+
+--echo #
+--echo Delete with a reference to view in subquery
+--echo #
+let $c = t1.c2 in ( select max(a.c2) from v1 a
+ where a.c1 = t1.c1);
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete from view
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = v1.c1 in
+ (select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+eval create table tmp as select * from v1 where $c;
+let $q = delete from v1 where $c;
+eval explain select * from v1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete from view using reference
+--echo # to the same view in subquery
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+ and c1 = 2
+ and exists (select 'X' from v1 a where a.c1 = v1.c1);
+eval create table tmp as select * from v1 where $c;
+let $q = delete from v1 where $c;
+eval explain select * from v1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
diff --git a/mysql-test/include/delete_use_source_cases_non_innodb.inc b/mysql-test/include/delete_use_source_cases_non_innodb.inc
new file mode 100644
index 0000000..caa5817
--- /dev/null
+++ b/mysql-test/include/delete_use_source_cases_non_innodb.inc
@@ -0,0 +1,81 @@
+--echo #
+--echo # Delete with EXISTS subquery over the updated table
+--echo # in WHERE + non-sargable condition
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete with order by
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = exists (select 'X' from t1 a where a.c2 = t1.c2)
+ and c2 >= 3 order by c2;
+eval create table tmp as select * from t1 where $c;
+let $q = delete from t1 where $c;
+--replace_column 9 #
+eval explain select * from t1 where $c;
+--replace_column 9 #
+eval explain $q;
+--replace_column 9 #
+eval analyze $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete from view
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = v1.c1 in
+ (select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+eval create table tmp as select * from v1 where $c;
+let $q = delete from v1 where $c;
+eval explain select * from v1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+
+--echo #
+--echo # Delete from view using reference
+--echo # to the same view in subquery
+--echo #
+
+analyze table t1 persistent for all;
+
+let $c = v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+ and c1 = 2
+ and exists (select 'X' from v1 a where a.c1 = v1.c1);
+eval create table tmp as select * from v1 where $c;
+let $q = delete from v1 where $c;
+--replace_column 9 #
+eval explain select * from v1 where $c;
+--replace_column 9 #
+eval explain $q;
+--replace_column 9 #
+eval analyze $q;
+--sorted_result
+select * from t1;
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
diff --git a/mysql-test/include/delete_use_source_innodb.inc b/mysql-test/include/delete_use_source_innodb.inc
new file mode 100644
index 0000000..83915d4
--- /dev/null
+++ b/mysql-test/include/delete_use_source_innodb.inc
@@ -0,0 +1,91 @@
+create table t1 (c1 integer, c2 integer, c3 integer);
+
+insert into t1(c1,c2,c3)
+ 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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+
+create view v1 as select * from t1 where c2=2;
+
+--echo #######################################
+--echo # Test without any index #
+--echo #######################################
+--source include/delete_use_source_cases.inc
+
+--echo #######################################
+--echo # Test with an index #
+--echo #######################################
+create index t1_c2 on t1 (c2,c1);
+--source include/delete_use_source_cases.inc
+
+--echo #######################################
+--echo # Test with a primary key #
+--echo #######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+--source include/delete_use_source_cases.inc
+
+drop view v1;
+drop table t1;
+
+--echo #
+--echo # Test on dynamic columns (blob)
+--echo #
+create table assets (
+ item_name varchar(32) primary key, -- A common attribute for all items
+ dynamic_cols blob -- Dynamic columns will be stored here
+);
+
+INSERT INTO assets
+ VALUES ('MariaDB T-shirt',
+ COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets
+ VALUES ('Thinkpad Laptop',
+ COLUMN_CREATE('color', 'black', 'price', 500));
+INSERT INTO assets
+ VALUES ('Fridge',
+ COLUMN_CREATE('color', 'white', 'warranty', '5 years'));
+INSERT INTO assets
+ VALUES ('Microwave',
+ COLUMN_CREATE('warranty', '3 years'));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, 'color')
+ WHERE item_name='Fridge';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+DELETE FROM assets
+ WHERE item_name in
+ (select b.item_name from assets b
+ where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+DELETE FROM assets WHERE item_name='Microwave';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets ORDER BY item_name;
+drop table assets ;
+
+
+--echo #
+--echo # Test on fulltext columns
+--echo #
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+ ('MySQL vs MariaDB database'),
+ ('Oracle vs MariaDB database'),
+ ('PostgreSQL vs MariaDB database'),
+ ('MariaDB overview'),
+ ('Foreign keys'),
+ ('Primary keys'),
+ ('Indexes'),
+ ('Transactions'),
+ ('Triggers');
+
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+DELETE FROM ft2 WHERE MATCH(copy) AGAINST('database');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+drop table ft2;
+
diff --git a/mysql-test/include/delete_use_source_memory.inc b/mysql-test/include/delete_use_source_memory.inc
new file mode 100644
index 0000000..dbaae1a
--- /dev/null
+++ b/mysql-test/include/delete_use_source_memory.inc
@@ -0,0 +1,33 @@
+create table t1 (c1 integer, c2 integer, c3 integer);
+
+insert into t1(c1,c2,c3)
+ 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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+
+create view v1 as select * from t1 where c2=2;
+
+--echo #######################################
+--echo # Test without any index #
+--echo #######################################
+--source include/delete_use_source_cases_memory.inc
+
+--echo #######################################
+--echo # Test with an index #
+--echo #######################################
+create index t1_c2 on t1 (c2,c1);
+--source include/delete_use_source_cases_memory.inc
+
+--echo #######################################
+--echo # Test with a primary key #
+--echo #######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+--source include/delete_use_source_cases_memory.inc
+
+drop view v1;
+drop table t1;
+
diff --git a/mysql-test/include/update_use_source.inc b/mysql-test/include/update_use_source.inc
index 3c48770..e1b66d2 100644
--- a/mysql-test/include/update_use_source.inc
+++ b/mysql-test/include/update_use_source.inc
@@ -1,150 +1,188 @@
# Include to test update with same table as source and target
---echo #
---echo # Update a with value from subquery on the same table, no search clause. ALL access
---echo #
-
-#Enable view protocol after fix MDEV-29207
---disable_view_protocol
-start transaction;
+create table t1 (old_c1 integer,
+ old_c2 integer,
+ c1 integer,
+ c2 integer,
+ c3 integer);
+
+create view v1 as select * from t1 where c2=2;
+delimiter /;
+create trigger trg_t1 before update on t1 for each row
+begin
+ set new.old_c1=old.c1;
+ set new.old_c2=old.c2;
+end;
+/
+delimiter ;/
+
+insert into t1(c1,c2,c3)
+ 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);
+insert into t1 select NULL, NULL, c1+10,c2,c3+10 from t1;
+insert into t1 select NULL, NULL, c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+
+create table tmp as select * from t1;
+
+--echo #######################################
+--echo # Test without any index #
+--echo #######################################
+--source include/update_use_source_cases.inc
+
+--echo #######################################
+--echo # Test with an index #
+--echo #######################################
+create index t1_c2 on t1 (c2,c1);
+analyze table t1;
+--source include/update_use_source_cases.inc
+
+--echo #######################################
+--echo # Test with a primary key #
+--echo #######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+analyze table t1;
+--source include/update_use_source_cases.inc
+
+--echo # Update with error "Subquery returns more than 1 row"
+--error ER_SUBQUERY_NO_1_ROW
+update t1 set c2=(select c2 from t1);
+--sorted_result
+select c1,c2,c3 from t1;
+
+--echo # Update with error "Subquery returns more than 1 row"
+--echo # and order by
+--error ER_SUBQUERY_NO_1_ROW
+update t1 set c2=(select c2 from t1) order by c3;
+--sorted_result
+select c1,c2,c3 from t1;
+
+-- echo # Duplicate value on update a primary key
+--error ER_DUP_ENTRY
+
+update t1 set c3=0
+ where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+-- echo # Duplicate value on update a primary key with ignore
--enable_info ONCE
-update t1
- set c1=(select a.c3
- from t1 a
- where a.c3 = t1.c3);
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
-rollback;
-
---echo #
---echo # Update with search clause on the same table
---echo #
-
-start transaction;
+update ignore t1 set c3=0
+ where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+-- echo # Duplicate value on update a primary key and limit
+--error ER_DUP_ENTRY
+update t1 set c3=0
+ where exists (select 'X' from t1 a where a.c2 = t1.c2)
+ and c2 >= 3 limit 2;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+-- echo # Duplicate value on update a primary key with ignore
+-- echo # and limit
--enable_info ONCE
-update t1
- set c1=10
- where c1 <2
- and exists (select 'X'
- from t1 a
- where a.c1 = t1.c1);
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
-rollback;
-
---echo #
---echo # Update via RANGE or INDEX access if an index or a primary key exists
---echo #
-
-explain update t1 set c1=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 > 3;
-start transaction;
+update ignore t1 set c3=0
+ where exists (select 'X' from t1 a where a.c2 = t1.c2)
+ and c2 >= 3 limit 2;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo # Update no rows found
--enable_info ONCE
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-rollback;
-
---echo #
---echo # Update with order by
---echo #
-
-start transaction;
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 order by c2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-rollback;
-
---echo #
---echo Update using a view in subquery
---echo #
-
-start transaction;
+update t1 set c1=10
+ where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1 + 10);
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo # Update no rows changed
+drop trigger trg_t1;
--enable_info ONCE
-update t1
- set c1=c1 +(select max(a.c2)
- from v1 a
- where a.c1 = t1.c1) ;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-rollback;
+update t1 set c1=c1
+ where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1);
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
--echo #
---echo # Update throw a view
+--echo # Check call of after trigger
--echo #
-start transaction;
---enable_info ONCE
-update v1
- set c1=c1 + (select max(a.c2)
- from t1 a
- where a.c1 = v1.c1) +10
-where c3 > 3;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-rollback;
-
---echo #
---echo # Update through a view and using the view in subquery
---echo #
+delimiter /;
+create or replace trigger trg_t2 after update on t1 for each row
+begin
+ declare msg varchar(100);
+ if (new.c3 = 5) then
+ set msg=concat('in after update trigger on ',new.c3);
+ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
+ end if;
+end;
+/
+delimiter ;/
+--error 1644
-start transaction;
---enable_info ONCE
-update v1
- set c1=c1 + 1
- where c1 <2
- and exists (select 'X'
- from v1 a
- where a.c1 = v1.c1);
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-rollback;
+update t1 set c1=2
+ where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
--echo #
---echo # Update through a view and using the view in subquery
+--echo # Check update with order by and after trigger
--echo #
-start transaction;
---enable_info ONCE
-update v1
- set c1=(select max(a.c1)+10
- from v1 a
- where a.c1 = v1.c1)
- where c1 <10
- and exists (select 'X'
- from v1 a
- where a.c2 = v1.c2);
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-rollback;
+--error 1644
+update t1 set c1=2
+ where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1)
+ order by t1.c2, t1.c1;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+drop view v1;
--echo #
---echo # Update of the index or primary key (c3)
+--echo # Check update on view with check option
--echo #
-start transaction;
-explain update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
---enable_info ONCE
-update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
-select c3 from t1;
-rollback;
+create view v1 as select * from t1 where c2=2 with check option;
---echo #
---echo # update with a limit
---echo #
+-- error 1369
+update v1 set c2=3 where c1=1;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
-start transaction;
---enable_info ONCE
-update t1
- set c1=(select a.c3
- from t1 a
- where a.c3 = t1.c3)
- limit 2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
-rollback;
+-- error 1369
+update v1 set c2=(select max(c3) from v1) where c1=1;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
---echo #
---echo # update with a limit and an order by
---echo #
+update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
+--sorted_result
+select c1,c2,c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
-start transaction;
---enable_info ONCE
-update t1
- set c1=(select a.c3
- from t1 a
- where a.c3 = t1.c3)
- order by c3 desc limit 2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
-rollback;
---enable_view_protocol
+drop table tmp;
+drop view v1;
+drop table t1;
diff --git a/mysql-test/include/update_use_source_cases.inc b/mysql-test/include/update_use_source_cases.inc
new file mode 100644
index 0000000..f1025f7
--- /dev/null
+++ b/mysql-test/include/update_use_source_cases.inc
@@ -0,0 +1,183 @@
+--echo #
+--echo # Update with value from subquery on the same table
+--echo #
+
+analyze table t1 persistent for all;
+let $q = update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+eval explain select * from t1;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with EXISTS subquery over the updated table
+--echo # in WHERE + possibly sargable condition
+--echo #
+
+analyze table t1 persistent for all;
+let $c = c1 <2
+ and exists (select 'X' from t1 a where a.c1 = t1.c1);
+let $q = update t1 set c1=10 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with EXISTS subquery over the updated table
+--echo # in WHERE + non-sargable condition
+--echo #
+
+analyze table t1 persistent for all;
+let $c = exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+let $q = update t1 set c1=c1+10 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with order by
+--echo #
+
+analyze table t1 persistent for all;
+let $c = exists (select 'X' from t1 a where a.c2 = t1.c2)
+ and c2 >= 3 order by c2;
+let $q = update t1 set c1=c1+10 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with a reference to view in subquery
+--echo # in settable value
+--echo #
+
+analyze table t1 persistent for all;
+let $q = update t1 set c1=c1 +(select max(a.c2) from v1 a
+ where a.c1 = t1.c1);
+eval explain select * from t1;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update view
+--echo #
+
+analyze table t1 persistent for all;
+let $q = update v1 set c1=c1 + (select max(a.c2) from t1 a
+ where a.c1 = v1.c1) +10 where c3 > 3;
+eval explain select * from v1;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update view with reference to the same view in subquery
+--echo #
+
+analyze table t1 persistent for all;
+let $c = c1 <2
+ and exists (select 'X' from v1 a where a.c1 = v1.c1);
+let $q = update v1 set c1=c1 + 1 where $c;
+eval explain select * from v1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update view with EXISTS and reference to the same view in subquery
+--echo #
+
+analyze table t1 persistent for all;
+let $c = c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+let $q = update v1
+ set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+ where $c;
+eval explain select * from v1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with IN predicand over the updated table in WHERE
+--echo #
+
+analyze table t1 persistent for all;
+let $c = c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+let $q = update t1 set c3=c3+110 where $c;
+eval explain select * from t1 where $c;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+--sorted_result
+select c3 from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with a limit
+--echo #
+
+analyze table t1 persistent for all;
+let $q = update t1
+ set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+eval explain select * from t1 limit 2;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
+
+--echo #
+--echo # Update with a limit and an order by
+--echo #
+
+analyze table t1 persistent for all;
+let $q=update t1
+ set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+ order by c3 desc limit 2;
+eval explain select * from t1 order by c3 desc limit 2;
+eval explain $q;
+--enable_info ONCE
+eval $q;
+select concat(old_c1,'->',c1),c3,
+ case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+truncate table t1;
+insert into t1 select * from tmp;
diff --git a/mysql-test/include/update_use_source_ext.inc b/mysql-test/include/update_use_source_ext.inc
new file mode 100644
index 0000000..004f7a9
--- /dev/null
+++ b/mysql-test/include/update_use_source_ext.inc
@@ -0,0 +1,59 @@
+--echo #
+--echo # Test on dynamic columns (blob)
+--echo #
+
+create table assets (
+ item_name varchar(32) primary key, -- A common attribute for all items
+ dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets VALUES ('MariaDB T-shirt',
+ COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets VALUES ('Thinkpad Laptop',
+ COLUMN_CREATE('color', 'black', 'price', 500));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+ FROM assets;
+UPDATE assets
+ SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years')
+ WHERE item_name='Thinkpad Laptop';
+SELECT item_name,
+ COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+ FROM assets;
+UPDATE assets
+ SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
+ WHERE item_name in
+ (select b.item_name from assets b
+ where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name,
+ COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+ FROM assets;
+
+UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty',
+ (select COLUMN_GET(b.dynamic_cols, 'color' as char)
+ from assets b
+ where assets.item_name = item_name));
+SELECT item_name,
+ COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+ FROM assets;
+drop table assets;
+
+--echo #
+--echo # Test on fulltext columns
+--echo #
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+ ('MySQL vs MariaDB database'),
+ ('Oracle vs MariaDB database'),
+ ('PostgreSQL vs MariaDB database'),
+ ('MariaDB overview'),
+ ('Foreign keys'),
+ ('Primary keys'),
+ ('Indexes'),
+ ('Transactions'),
+ ('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+
+update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5)))
+ from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
+ where MATCH(copy) AGAINST('keys');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
+drop table ft2;
diff --git a/mysql-test/main/delete_single_to_multi.result b/mysql-test/main/delete_single_to_multi.result
index eba4ca8..57cc224 100644
--- a/mysql-test/main/delete_single_to_multi.result
+++ b/mysql-test/main/delete_single_to_multi.result
@@ -3419,4 +3419,834 @@ o_orderkey o_totalprice
4903 34363.63
5607 24660.06
drop table t;
+CREATE TABLE partsupp_small (
+ps_partkey int(11) NOT NULL DEFAULT '0',
+ps_suppkey int(11) NOT NULL DEFAULT '0',
+ps_availqty int(11) DEFAULT NULL,
+ps_supplycost double DEFAULT NULL,
+ps_comment varchar(199) DEFAULT NULL,
+PRIMARY KEY (ps_partkey,ps_suppkey),
+KEY i_ps_partkey (ps_partkey),
+KEY i_ps_suppkey (ps_suppkey)
+);
+create index i_ps_sup_part on partsupp_small(ps_suppkey, ps_partkey);
+insert into partsupp_small select * from partsupp where ps_partkey <50;
+analyze table partsupp_small persistent for all;
+Table Op Msg_type Msg_text
+dbt3_s001.partsupp_small analyze status Engine-independent statistics collected
+dbt3_s001.partsupp_small analyze status OK
+# LooseScan
+# =========
+explain
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY partsupp_small index PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part PRIMARY 8 NULL 176 Using where; Using index; LooseScan
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index
+explain format=json
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.222764041,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "index",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "PRIMARY",
+ "key_length": "8",
+ "used_key_parts": ["ps_partkey", "ps_suppkey"],
+ "loops": 1,
+ "rows": 176,
+ "cost": 0.019403477,
+ "filtered": 23.86363602,
+ "attached_condition": "partsupp_small.ps_suppkey in (1,2,3)",
+ "using_index": true,
+ "loose_scan": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 42,
+ "rows": 30,
+ "cost": 0.203360564,
+ "filtered": 2.380952358,
+ "using_index": true
+ }
+ }
+ ]
+ }
+}
+explain
+select l_partkey from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY partsupp_small index PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part PRIMARY 8 NULL 176 Using where; Using index; LooseScan
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index
+explain format=json
+select l_partkey from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.222764041,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "index",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "PRIMARY",
+ "key_length": "8",
+ "used_key_parts": ["ps_partkey", "ps_suppkey"],
+ "loops": 1,
+ "rows": 176,
+ "cost": 0.019403477,
+ "filtered": 23.86363602,
+ "attached_condition": "partsupp_small.ps_suppkey in (1,2,3)",
+ "using_index": true,
+ "loose_scan": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 42,
+ "rows": 30,
+ "cost": 0.203360564,
+ "filtered": 2.380952358,
+ "using_index": true
+ }
+ }
+ ]
+ }
+}
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+create table t as
+select * from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+explain
+delete from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY partsupp_small index PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part PRIMARY 8 NULL 176 Using where; Using index; LooseScan
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30
+explain format=json
+delete from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.222764041,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "index",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "PRIMARY",
+ "key_length": "8",
+ "used_key_parts": ["ps_partkey", "ps_suppkey"],
+ "loops": 1,
+ "rows": 176,
+ "cost": 0.019403477,
+ "filtered": 23.86363602,
+ "attached_condition": "partsupp_small.ps_suppkey in (1,2,3)",
+ "using_index": true,
+ "loose_scan": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 42,
+ "rows": 30,
+ "cost": 0.203360564,
+ "filtered": 2.380952358
+ }
+ }
+ ]
+ }
+}
+delete from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+0
+insert into lineitem select * from t;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+drop table t;
+# LooseScan PS
+# ============
+prepare stmt from "
+delete from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+";
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+create table t as
+select * from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+execute stmt;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+0
+insert into lineitem select * from t;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+create table r as
+select * from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+execute stmt;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+0
+insert into lineitem select * from r;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+drop tables r, t;
+deallocate prepare stmt;
+# LooseScan SP
+# ============
+create procedure p()
+delete from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+create table t as
+select * from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+call p();
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+0
+insert into lineitem select * from t;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+create table r as
+select * from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+call p();
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+0
+insert into lineitem select * from r;
+select count(*) from lineitem where l_partkey in
+(select ps_partkey from partsupp_small
+where ps_suppkey in (1,2,3));
+count(*)
+1175
+drop tables r, t;
+drop procedure p;
+# DuplicateWeedout
+# ================
+set @tmp_optimizer_switch= @@optimizer_switch;
+set optimizer_switch='materialization=off';
+analyze table lineitem;
+Table Op Msg_type Msg_text
+dbt3_s001.lineitem analyze status Engine-independent statistics collected
+dbt3_s001.lineitem analyze status OK
+analyze table orders;
+Table Op Msg_type Msg_text
+dbt3_s001.orders analyze status Engine-independent statistics collected
+dbt3_s001.orders analyze status OK
+explain
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY supplier range PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Start temporary
+1 PRIMARY partsupp_small ref PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part i_ps_sup_part 4 dbt3_s001.supplier.s_suppkey 17 Using where; Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index; End temporary
+explain format=json
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 4.129940741,
+ "nested_loop": [
+ {
+ "duplicates_removal": [
+ {
+ "table": {
+ "table_name": "supplier",
+ "access_type": "range",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["s_suppkey"],
+ "loops": 1,
+ "rows": 1,
+ "cost": 0.001478954,
+ "filtered": 100,
+ "attached_condition": "supplier.s_suppkey < 2",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "i_ps_sup_part",
+ "key_length": "4",
+ "used_key_parts": ["ps_suppkey"],
+ "ref": ["dbt3_s001.supplier.s_suppkey"],
+ "loops": 1,
+ "rows": 17,
+ "cost": 0.003160332,
+ "filtered": 79.54545593,
+ "attached_condition": "partsupp_small.ps_partkey is not null",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_suppkey_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 14,
+ "rows": 30,
+ "cost": 0.069152188,
+ "filtered": 100,
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 420.35,
+ "rows": 30,
+ "cost": 1.994712365,
+ "filtered": 0.237896994,
+ "using_index": true
+ }
+ }
+ ]
+ }
+ ]
+ }
+}
+explain
+select l_partkey from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY supplier range PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Start temporary
+1 PRIMARY partsupp_small ref PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part i_ps_sup_part 4 dbt3_s001.supplier.s_suppkey 17 Using where; Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index; End temporary
+explain format=json
+select l_partkey from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 4.129940741,
+ "nested_loop": [
+ {
+ "duplicates_removal": [
+ {
+ "table": {
+ "table_name": "supplier",
+ "access_type": "range",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["s_suppkey"],
+ "loops": 1,
+ "rows": 1,
+ "cost": 0.001478954,
+ "filtered": 100,
+ "attached_condition": "supplier.s_suppkey < 2",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "i_ps_sup_part",
+ "key_length": "4",
+ "used_key_parts": ["ps_suppkey"],
+ "ref": ["dbt3_s001.supplier.s_suppkey"],
+ "loops": 1,
+ "rows": 17,
+ "cost": 0.003160332,
+ "filtered": 79.54545593,
+ "attached_condition": "partsupp_small.ps_partkey is not null",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_suppkey_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 14,
+ "rows": 30,
+ "cost": 0.069152188,
+ "filtered": 100,
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 420.35,
+ "rows": 30,
+ "cost": 1.994712365,
+ "filtered": 0.237896994,
+ "using_index": true
+ }
+ }
+ ]
+ }
+ ]
+ }
+}
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+create table t as
+select * from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+explain
+delete from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY supplier range PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Start temporary
+1 PRIMARY partsupp_small ref PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part i_ps_sup_part 4 dbt3_s001.supplier.s_suppkey 17 Using where; Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index; End temporary
+explain format=json
+delete from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 4.129940741,
+ "nested_loop": [
+ {
+ "duplicates_removal": [
+ {
+ "table": {
+ "table_name": "supplier",
+ "access_type": "range",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["s_suppkey"],
+ "loops": 1,
+ "rows": 1,
+ "cost": 0.001478954,
+ "filtered": 100,
+ "attached_condition": "supplier.s_suppkey < 2",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "i_ps_sup_part",
+ "key_length": "4",
+ "used_key_parts": ["ps_suppkey"],
+ "ref": ["dbt3_s001.supplier.s_suppkey"],
+ "loops": 1,
+ "rows": 17,
+ "cost": 0.003160332,
+ "filtered": 79.54545593,
+ "attached_condition": "partsupp_small.ps_partkey is not null",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_suppkey_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 14,
+ "rows": 30,
+ "cost": 0.069152188,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 420.35,
+ "rows": 30,
+ "cost": 1.994712365,
+ "filtered": 0.237896994,
+ "using_index": true
+ }
+ }
+ ]
+ }
+ ]
+ }
+}
+delete from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+0
+insert into lineitem select * from t;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+drop table t;
+# DuplicateWeedout PS
+# ===================
+prepare stmt from "
+delete from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+";
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+create table t as
+select * from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+execute stmt;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+0
+insert into lineitem select * from t;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+create table r as
+select * from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+execute stmt;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+0
+insert into lineitem select * from r;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+drop tables r, t;
+deallocate prepare stmt;
+# DuplicateWeedout SP
+# ===================
+create procedure p()
+delete from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+create table t as
+select * from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+call p();
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+0
+insert into lineitem select * from t;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+create table r as
+select * from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+call p();
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+0
+insert into lineitem select * from r;
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+drop tables r, t;
+drop procedure p;
+set @@optimizer_switch=@tmp_optimizer_switch;
+drop table partsupp_small;
DROP DATABASE dbt3_s001;
diff --git a/mysql-test/main/delete_single_to_multi.test b/mysql-test/main/delete_single_to_multi.test
index 2829ae1..31f1d15 100644
--- a/mysql-test/main/delete_single_to_multi.test
+++ b/mysql-test/main/delete_single_to_multi.test
@@ -822,4 +822,248 @@ eval
select o_orderkey, o_totalprice from orders where $c11;
drop table t;
+
+CREATE TABLE partsupp_small (
+ ps_partkey int(11) NOT NULL DEFAULT '0',
+ ps_suppkey int(11) NOT NULL DEFAULT '0',
+ ps_availqty int(11) DEFAULT NULL,
+ ps_supplycost double DEFAULT NULL,
+ ps_comment varchar(199) DEFAULT NULL,
+ PRIMARY KEY (ps_partkey,ps_suppkey),
+ KEY i_ps_partkey (ps_partkey),
+ KEY i_ps_suppkey (ps_suppkey)
+);
+
+create index i_ps_sup_part on partsupp_small(ps_suppkey, ps_partkey);
+insert into partsupp_small select * from partsupp where ps_partkey <50;
+analyze table partsupp_small persistent for all;
+
+--echo # LooseScan
+--echo # =========
+
+let $c12 = l_partkey in
+ (select ps_partkey from partsupp_small
+ where ps_suppkey in (1,2,3));
+
+eval
+explain
+select count(*) from lineitem where $c12;
+eval
+explain format=json
+select count(*) from lineitem where $c12;
+eval
+explain
+select l_partkey from lineitem where $c12;
+eval
+explain format=json
+select l_partkey from lineitem where $c12;
+eval
+select count(*) from lineitem where $c12;
+eval
+create table t as
+select * from lineitem where $c12;
+
+eval
+explain
+delete from lineitem where $c12;
+eval
+explain format=json
+delete from lineitem where $c12;
+eval
+delete from lineitem where $c12;
+eval
+select count(*) from lineitem where $c12;
+
+insert into lineitem select * from t;
+eval
+select count(*) from lineitem where $c12;
+
+drop table t;
+
+--echo # LooseScan PS
+--echo # ============
+
+eval
+prepare stmt from "
+delete from lineitem where $c12;
+";
+
+eval
+select count(*) from lineitem where $c12;
+eval
+create table t as
+select * from lineitem where $c12;
+execute stmt;
+eval
+select count(*) from lineitem where $c12;
+insert into lineitem select * from t;
+eval
+select count(*) from lineitem where $c12;
+
+eval
+create table r as
+select * from lineitem where $c12;
+execute stmt;
+eval
+select count(*) from lineitem where $c12;
+insert into lineitem select * from r;
+eval
+select count(*) from lineitem where $c12;
+
+drop tables r, t;
+deallocate prepare stmt;
+
+--echo # LooseScan SP
+--echo # ============
+
+eval
+create procedure p()
+delete from lineitem where $c12;
+
+eval
+select count(*) from lineitem where $c12;
+eval
+create table t as
+select * from lineitem where $c12;
+call p();
+eval
+select count(*) from lineitem where $c12;
+insert into lineitem select * from t;
+eval
+select count(*) from lineitem where $c12;
+
+eval
+create table r as
+select * from lineitem where $c12;
+call p();
+eval
+select count(*) from lineitem where $c12;
+insert into lineitem select * from r;
+eval
+select count(*) from lineitem where $c12;
+
+drop tables r, t;
+drop procedure p;
+
+--echo # DuplicateWeedout
+--echo # ================
+
+set @tmp_optimizer_switch= @@optimizer_switch;
+set optimizer_switch='materialization=off';
+
+analyze table lineitem;
+analyze table orders;
+
+let $c13 = l_partkey in (
+ select ps_partkey
+ from partsupp_small join lineitem on ps_partkey=l_partkey
+ where ps_suppkey in (
+ select s_suppkey from supplier where s_suppkey < 2
+ )
+);
+
+eval
+explain
+select count(*) from lineitem where $c13;
+eval
+explain format=json
+select count(*) from lineitem where $c13;
+eval
+explain
+select l_partkey from lineitem where $c13;
+eval
+explain format=json
+select l_partkey from lineitem where $c13;
+eval
+select count(*) from lineitem where $c13;
+eval
+create table t as
+select * from lineitem where $c13;
+
+eval
+explain
+delete from lineitem where $c13;
+eval
+explain format=json
+delete from lineitem where $c13;
+eval
+delete from lineitem where $c13;
+eval
+select count(*) from lineitem where $c13;
+
+insert into lineitem select * from t;
+eval
+select count(*) from lineitem where $c13;
+
+drop table t;
+
+--echo # DuplicateWeedout PS
+--echo # ===================
+
+eval
+prepare stmt from "
+delete from lineitem where $c13;
+";
+
+eval
+select count(*) from lineitem where $c13;
+eval
+create table t as
+select * from lineitem where $c13;
+execute stmt;
+eval
+select count(*) from lineitem where $c13;
+insert into lineitem select * from t;
+eval
+select count(*) from lineitem where $c13;
+
+eval
+create table r as
+select * from lineitem where $c13;
+execute stmt;
+eval
+select count(*) from lineitem where $c13;
+insert into lineitem select * from r;
+eval
+select count(*) from lineitem where $c13;
+
+drop tables r, t;
+deallocate prepare stmt;
+
+--echo # DuplicateWeedout SP
+--echo # ===================
+
+eval
+create procedure p()
+delete from lineitem where $c13;
+
+eval
+select count(*) from lineitem where $c13;
+eval
+create table t as
+select * from lineitem where $c13;
+call p();
+eval
+select count(*) from lineitem where $c13;
+insert into lineitem select * from t;
+eval
+select count(*) from lineitem where $c13;
+
+eval
+create table r as
+select * from lineitem where $c13;
+call p();
+eval
+select count(*) from lineitem where $c13;
+insert into lineitem select * from r;
+eval
+select count(*) from lineitem where $c13;
+
+drop tables r, t;
+drop procedure p;
+
+set @@optimizer_switch=@tmp_optimizer_switch;
+
+drop table partsupp_small;
+
DROP DATABASE dbt3_s001;
diff --git a/mysql-test/main/delete_use_source_engines.result b/mysql-test/main/delete_use_source_engines.result
new file mode 100644
index 0000000..fd0d3b8
--- /dev/null
+++ b/mysql-test/main/delete_use_source_engines.result
@@ -0,0 +1,8870 @@
+set @save_default_engine=@@default_storage_engine;
+#######################################
+# #
+# Engine InnoDB #
+# #
+#######################################
+set global innodb_stats_persistent=1;
+set default_storage_engine=InnoDB;
+create table t1 (c1 integer, c2 integer, c3 integer);
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create view v1 as select * from t1 where c2=2;
+#######################################
+# Test without any index #
+#######################################
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.00 100.00 5.56 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 12.50 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 24.50 100.00 1.02 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 32.00 25.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 100.00 5.71 Using where; Using index; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 1 Using index; FirstMatch(t1)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 1 Using index; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using index; FirstMatch(t1)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using index; FirstMatch(t1)
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 12.50 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 0.25 18.75 100.00 Using index; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using where; FirstMatch(t1)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a index_subquery t1_c2 t1_c2 5 func 5 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 1.00 100.00 100.00 Using index
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.33 100.00 5.41 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 1.00 100.00 100.00 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 1.00 3.12 100.00 Using where; End temporary
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 1
+1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index NULL PRIMARY 4 NULL 1 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 32.00 25.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+#
+# Test on dynamic columns (blob)
+#
+create table assets (
+item_name varchar(32) primary key, -- A common attribute for all items
+dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets
+VALUES ('MariaDB T-shirt',
+COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets
+VALUES ('Thinkpad Laptop',
+COLUMN_CREATE('color', 'black', 'price', 500));
+INSERT INTO assets
+VALUES ('Fridge',
+COLUMN_CREATE('color', 'white', 'warranty', '5 years'));
+INSERT INTO assets
+VALUES ('Microwave',
+COLUMN_CREATE('warranty', '3 years'));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge white
+MariaDB T-shirt blue
+Microwave NULL
+Thinkpad Laptop black
+UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, 'color')
+WHERE item_name='Fridge';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+Microwave NULL
+Thinkpad Laptop black
+DELETE FROM assets
+WHERE item_name in
+(select b.item_name from assets b
+where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+Microwave NULL
+DELETE FROM assets WHERE item_name='Microwave';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+drop table assets ;
+#
+# Test on fulltext columns
+#
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+('MySQL vs MariaDB database'),
+('Oracle vs MariaDB database'),
+('PostgreSQL vs MariaDB database'),
+('MariaDB overview'),
+('Foreign keys'),
+('Primary keys'),
+('Indexes'),
+('Transactions'),
+('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+MySQL vs MariaDB database
+Oracle vs MariaDB database
+PostgreSQL vs MariaDB database
+DELETE FROM ft2 WHERE MATCH(copy) AGAINST('database');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+drop table ft2;
+#######################################
+# #
+# Engine Aria #
+# #
+#######################################
+set default_storage_engine=Aria;
+create table t1 (c1 integer, c2 integer, c3 integer);
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create view v1 as select * from t1 where c2=2;
+#######################################
+# Test without any index #
+#######################################
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.67 100.00 5.26 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 25.00 100.00 12.00 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 22.67 100.00 1.47 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 32.00 25.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 # Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+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 # Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+analyze 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 r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 62.50 62.50 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # 1.00 100.00 100.00
+2 MATERIALIZED a ALL NULL NULL NULL NULL # 32.00 62.50 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+analyze delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 3.91 3.12 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # 5.00 25.00 20.00 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # 32.00 100.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 100.00 5.71 Using where; Using index; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 1 Using index; FirstMatch(t1)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 1 Using index; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using index; FirstMatch(t1)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using index; FirstMatch(t1)
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 27.00 100.00 14.81 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 0.25 18.75 100.00 Using index; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using where; FirstMatch(t1)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a index_subquery t1_c2 t1_c2 5 func 5 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 1.00 100.00 100.00 Using index
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 ref t1_c2 t1_c2 5 const 8
+1 PRIMARY a ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+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 ref t1_c2 t1_c2 5 const 8
+1 PRIMARY a ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 range t1_c2 t1_c2 5 NULL # Using index condition
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 # Using index; FirstMatch(t1)
+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 a index t1_c2 t1_c2 10 NULL # Using where; Using index; LooseScan
+1 PRIMARY t1 ref t1_c2 t1_c2 5 test.a.c2 #
+analyze 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 r_rows filtered r_filtered Extra
+1 PRIMARY a index t1_c2 t1_c2 10 NULL # 16.00 20.00 25.00 Using where; Using index; LooseScan
+1 PRIMARY t1 ref t1_c2 t1_c2 5 test.a.c2 # 5.00 4.76 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # Using where
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # Using index; FirstMatch(t1)
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # Using where
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func # Using where; Using index
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+analyze delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # 1.00 100.00 100.00 Using where
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func # 1.00 100.00 100.00 Using where; Using index
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # 32.00 100.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.00 100.00 5.56 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 4.00 100.00 100.00 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 1.00 3.12 25.00 Using where; End temporary
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 1
+1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index NULL PRIMARY 4 NULL 1 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 32.00 25.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 # Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+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 # Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+analyze 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 r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 62.50 62.50 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # 1.00 100.00 100.00
+2 MATERIALIZED a ALL NULL NULL NULL NULL # 32.00 62.50 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 #
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 #
+analyze delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 3.91 3.12 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # 6.00 25.00 16.67 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 # 1.00 100.00 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+#
+# Test on dynamic columns (blob)
+#
+create table assets (
+item_name varchar(32) primary key, -- A common attribute for all items
+dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets
+VALUES ('MariaDB T-shirt',
+COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets
+VALUES ('Thinkpad Laptop',
+COLUMN_CREATE('color', 'black', 'price', 500));
+INSERT INTO assets
+VALUES ('Fridge',
+COLUMN_CREATE('color', 'white', 'warranty', '5 years'));
+INSERT INTO assets
+VALUES ('Microwave',
+COLUMN_CREATE('warranty', '3 years'));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge white
+MariaDB T-shirt blue
+Microwave NULL
+Thinkpad Laptop black
+UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, 'color')
+WHERE item_name='Fridge';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+Microwave NULL
+Thinkpad Laptop black
+DELETE FROM assets
+WHERE item_name in
+(select b.item_name from assets b
+where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+Microwave NULL
+DELETE FROM assets WHERE item_name='Microwave';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+drop table assets ;
+#
+# Test on fulltext columns
+#
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+('MySQL vs MariaDB database'),
+('Oracle vs MariaDB database'),
+('PostgreSQL vs MariaDB database'),
+('MariaDB overview'),
+('Foreign keys'),
+('Primary keys'),
+('Indexes'),
+('Transactions'),
+('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+MySQL vs MariaDB database
+Oracle vs MariaDB database
+PostgreSQL vs MariaDB database
+DELETE FROM ft2 WHERE MATCH(copy) AGAINST('database');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+drop table ft2;
+#######################################
+# #
+# Engine MyISAM #
+# #
+#######################################
+set default_storage_engine=MyISAM;
+create table t1 (c1 integer, c2 integer, c3 integer);
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create view v1 as select * from t1 where c2=2;
+#######################################
+# Test without any index #
+#######################################
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 12.67 100.00 5.26 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 25.00 100.00 12.00 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 22.67 100.00 1.47 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 32.00 25.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 # Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+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 # Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+analyze 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 r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 62.50 62.50 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # 1.00 100.00 100.00
+2 MATERIALIZED a ALL NULL NULL NULL NULL # 32.00 62.50 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+analyze delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 3.91 3.12 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # 5.00 25.00 20.00 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # 32.00 100.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 11.67 100.00 5.71 Using where; Using index; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 1 Using index; FirstMatch(t1)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 1 Using index; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using index; FirstMatch(t1)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using index; FirstMatch(t1)
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 29.00 100.00 13.79 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 0.25 18.75 100.00 Using index; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c1 5 Using where; FirstMatch(t1)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a index_subquery t1_c2 t1_c2 5 func 5 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 1.00 100.00 100.00 Using index
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 ref t1_c2 t1_c2 5 const 8
+1 PRIMARY a ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+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 ref t1_c2 t1_c2 5 const 8
+1 PRIMARY a ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 t1_c2 NULL NULL NULL # Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 # Using index; FirstMatch(t1)
+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 a index t1_c2 t1_c2 10 NULL # Using where; Using index; LooseScan
+1 PRIMARY t1 ref t1_c2 t1_c2 5 test.a.c2 #
+analyze 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 r_rows filtered r_filtered Extra
+1 PRIMARY a index t1_c2 t1_c2 10 NULL # 16.00 20.00 25.00 Using where; Using index; LooseScan
+1 PRIMARY t1 ref t1_c2 t1_c2 5 test.a.c2 # 5.00 5.00 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # Using where
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # Using index; FirstMatch(t1)
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # Using where
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func # Using where; Using index
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # Using where
+analyze delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const # 1.00 100.00 100.00 Using where
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func # 1.00 100.00 100.00 Using where; Using index
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL # 32.00 100.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+analyze delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 9.38 9.38 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 13.33 100.00 5.00 Using where; FirstMatch(t1)
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+analyze delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 4.00 100.00 100.00 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 1.00 3.12 25.00 Using where; End temporary
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 1
+1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index NULL PRIMARY 4 NULL 1 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+# Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+analyze delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 32.00 100.00 25.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 32.00 25.00 3.12 Using where
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 # Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+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 # Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func #
+2 MATERIALIZED a ALL NULL NULL NULL NULL #
+analyze 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 r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 62.50 62.50 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # 1.00 100.00 100.00
+2 MATERIALIZED a ALL NULL NULL NULL NULL # 32.00 62.50 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 #
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 #
+analyze delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL # 32.00 3.91 3.12 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # 3.00 25.00 33.33 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 # 1.00 100.00 100.00
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+#
+# Test on dynamic columns (blob)
+#
+create table assets (
+item_name varchar(32) primary key, -- A common attribute for all items
+dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets
+VALUES ('MariaDB T-shirt',
+COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets
+VALUES ('Thinkpad Laptop',
+COLUMN_CREATE('color', 'black', 'price', 500));
+INSERT INTO assets
+VALUES ('Fridge',
+COLUMN_CREATE('color', 'white', 'warranty', '5 years'));
+INSERT INTO assets
+VALUES ('Microwave',
+COLUMN_CREATE('warranty', '3 years'));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge white
+MariaDB T-shirt blue
+Microwave NULL
+Thinkpad Laptop black
+UPDATE assets SET dynamic_cols=COLUMN_DELETE(dynamic_cols, 'color')
+WHERE item_name='Fridge';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+Microwave NULL
+Thinkpad Laptop black
+DELETE FROM assets
+WHERE item_name in
+(select b.item_name from assets b
+where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+Microwave NULL
+DELETE FROM assets WHERE item_name='Microwave';
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets ORDER BY item_name;
+item_name color
+Fridge NULL
+MariaDB T-shirt blue
+drop table assets ;
+#
+# Test on fulltext columns
+#
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+('MySQL vs MariaDB database'),
+('Oracle vs MariaDB database'),
+('PostgreSQL vs MariaDB database'),
+('MariaDB overview'),
+('Foreign keys'),
+('Primary keys'),
+('Indexes'),
+('Transactions'),
+('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+MySQL vs MariaDB database
+Oracle vs MariaDB database
+PostgreSQL vs MariaDB database
+DELETE FROM ft2 WHERE MATCH(copy) AGAINST('database');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+drop table ft2;
+#######################################
+# #
+# Engine MEMORY #
+# #
+#######################################
+set default_storage_engine=MEMORY;
+create table t1 (c1 integer, c2 integer, c3 integer);
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select c1+10,c2,c3+10 from t1;
+insert into t1 select c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create view v1 as select * from t1 where c2=2;
+#######################################
+# Test without any index #
+#######################################
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+affected rows: 2
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+affected rows: 2
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL t1_c2 NULL NULL NULL 32
+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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL t1_c2 NULL NULL NULL 32
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 2 FirstMatch(t1)
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c3 2 FirstMatch(t1)
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
+1 PRIMARY a ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a ALL t1_c2 NULL NULL NULL 32 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 2
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 2
+delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL t1_c2 NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL t1_c2 NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const 2 Using where
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const 2 FirstMatch(t1)
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,const 2 Using where
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func 2 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+#
+# Delete with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+explain select * from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+explain delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+delete from t1 where c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 4
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+explain select * from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where c1 = 1 and exists (select 'X' from t1 a where a.c1 = t1.c2);
+affected rows: 2
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+explain select * 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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+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 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 = 3;
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 4 7
+2 5 8
+21 2 21
+21 4 23
+22 2 24
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 4 33
+32 2 34
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+delete from t1 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with IN predicand over the updated table in WHERE
+#
+create table tmp as select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+explain select * from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+explain delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c1 1 Using where; End temporary
+delete from t1 where c3 in (select distinct a.c1 from t1 a where t1.c2=a.c2);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 3 3
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit - can be deleted
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; Start temporary
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.a.c2 1 Using where; End temporary
+delete from t1 where c1 in (select a.c2 from t1 a where a.c2 = t1.c3) limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete with a limit and an order by
+#
+create table tmp as select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+explain select * from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 32 Using filesort
+1 PRIMARY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+explain delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; Using filesort
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using where
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete: 2 execution of PS
+#
+prepare create_tmp_stmt from
+"create table tmp as select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+prepare delete_t1_stmt from
+"delete from t1 where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=5;
+execute create_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 6 38
+prepare insert_tmp_stmt from
+"insert into tmp(c1,c2,c3) select * from t1
+ where c2=(select a.c3 from t1 a where a.c3 = ?)";
+set @a:=2;
+execute insert_tmp_stmt using @a;
+execute delete_t1_stmt using @a;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+2 1 4
+2 3 6
+2 4 7
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+drop table tmp;
+#
+# Delete in stored procedure
+#
+create procedure sp()
+begin
+delete from t1 where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+end
+//
+create table tmp as select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+insert into tmp(c1,c2,c3) select * from t1
+where c1 in (select a.c2 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 1;
+CALL sp;
+select * from t1;
+c1 c2 c3
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop procedure sp;
+drop table tmp;
+#
+# Delete in stored function
+#
+create function f1(IN a INT) returns int
+begin
+delete from t1 where c3 < a order by c3 limit 1;
+return 1;
+end;//
+set @a:=7;
+create table tmp as select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+insert into tmp(c1,c2,c3) select * from t1 where c3 < @a
+order by c3 limit 1;
+select f1(@a);
+f1(@a)
+1
+select * from t1;
+c1 c2 c3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop function f1;
+drop table tmp;
+#
+# Delete in trigger
+#
+create table t2 (c1 integer);
+insert into t2(c1) values (1), (2), (3), (4), (5), (6), (7), (8);
+CREATE TABLE cnt(del integer);
+INSERT INTO cnt VALUES(0);
+CREATE TRIGGER tr1 AFTER DELETE ON t1 FOR EACH ROW
+UPDATE cnt SET del=del+1;
+CREATE TRIGGER tr2 AFTER DELETE ON t1 FOR EACH ROW
+DELETE FROM t2 WHERE c1> (SELECT count(*)-1 FROM t2);
+CREATE TABLE tmp as SELECT * FROM t1 WHERE c2>=3;
+DELETE FROM t1 WHERE c2>=3;
+affected rows: 20
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+11 1 11
+11 2 12
+12 1 14
+12 2 15
+2 1 4
+2 2 5
+21 2 21
+22 2 24
+31 2 31
+32 2 34
+SELECT * FROM t2;
+c1
+SELECT * FROM cnt;
+del
+20
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+DROP TRIGGER tr1;
+DROP TRIGGER tr2;
+drop table t2, cnt, tmp;
+#
+Delete with a reference to view in subquery
+#
+create table tmp as select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+explain select * from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+explain delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+delete from t1 where t1.c2 in ( select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 8
+select * from t1;
+c1 c2 c3
+1 1 1
+1 3 3
+11 1 11
+11 3 13
+12 1 14
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 3 22
+21 4 23
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 3 32
+31 4 33
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+explain select * from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+explain delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+delete from v1 where v1.c1 in
+(select max(a.c1) from t1 a where a.c2 = v1.c2) and c3 = 5;
+affected rows: 0
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+#
+# Delete from view using reference
+# to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+explain select * from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+explain delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+delete from v1 where v1.c2 in (select max(a.c2) from t1 a where a.c3 = v1.c3)
+and c1 = 2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+select * from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+insert into t1(c1,c2,c3) select c1,c2,c3 from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+set @@default_storage_engine=@save_default_engine;
+#
+# End of 11.0 tests
+#
diff --git a/mysql-test/main/delete_use_source_engines.test b/mysql-test/main/delete_use_source_engines.test
new file mode 100644
index 0000000..1a0d98f
--- /dev/null
+++ b/mysql-test/main/delete_use_source_engines.test
@@ -0,0 +1,42 @@
+--source include/have_innodb.inc
+
+set @save_default_engine=@@default_storage_engine;
+
+--echo #######################################
+--echo # #
+--echo # Engine InnoDB #
+--echo # #
+--echo #######################################
+set global innodb_stats_persistent=1;
+set default_storage_engine=InnoDB;
+--source include/delete_use_source_innodb.inc
+
+--echo #######################################
+--echo # #
+--echo # Engine Aria #
+--echo # #
+--echo #######################################
+set default_storage_engine=Aria;
+--source include/delete_use_source.inc
+
+--echo #######################################
+--echo # #
+--echo # Engine MyISAM #
+--echo # #
+--echo #######################################
+set default_storage_engine=MyISAM;
+--source include/delete_use_source.inc
+
+--echo #######################################
+--echo # #
+--echo # Engine MEMORY #
+--echo # #
+--echo #######################################
+set default_storage_engine=MEMORY;
+--source include/delete_use_source_memory.inc
+
+set @@default_storage_engine=@save_default_engine;
+
+--echo #
+--echo # End of 11.0 tests
+--echo #
diff --git a/mysql-test/main/update_single_to_multi.result b/mysql-test/main/update_single_to_multi.result
index 11969f7..6792378 100644
--- a/mysql-test/main/update_single_to_multi.result
+++ b/mysql-test/main/update_single_to_multi.result
@@ -3242,4 +3242,619 @@ o_orderkey o_totalprice
3139 40975.96
4903 34363.63
5607 24660.06
+CREATE TABLE partsupp_small (
+ps_partkey int(11) NOT NULL DEFAULT '0',
+ps_suppkey int(11) NOT NULL DEFAULT '0',
+ps_availqty int(11) DEFAULT NULL,
+ps_supplycost double DEFAULT NULL,
+ps_comment varchar(199) DEFAULT NULL,
+PRIMARY KEY (ps_partkey,ps_suppkey),
+KEY i_ps_partkey (ps_partkey),
+KEY i_ps_suppkey (ps_suppkey)
+);
+create index i_ps_sup_part on partsupp_small(ps_suppkey, ps_partkey);
+insert into partsupp_small select * from partsupp where ps_partkey <50;
+analyze table partsupp_small persistent for all;
+Table Op Msg_type Msg_text
+dbt3_s001.partsupp_small analyze status Engine-independent statistics collected
+dbt3_s001.partsupp_small analyze status OK
+# LooseScan
+# =========
+explain
+select count(*) from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY partsupp_small index PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part i_ps_sup_part 8 NULL 176 Using where; Using index; LooseScan
+1 PRIMARY lineitem ref i_l_suppkey i_l_suppkey 5 dbt3_s001.partsupp_small.ps_suppkey 600 Using index
+explain format=json
+select count(*) from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.776623555,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "index",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "i_ps_sup_part",
+ "key_length": "8",
+ "used_key_parts": ["ps_suppkey", "ps_partkey"],
+ "loops": 1,
+ "rows": 176,
+ "cost": 0.019403477,
+ "filtered": 5.113636494,
+ "attached_condition": "partsupp_small.ps_partkey in (1,2,3)",
+ "using_index": true,
+ "loose_scan": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey"],
+ "key": "i_l_suppkey",
+ "key_length": "5",
+ "used_key_parts": ["l_suppkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_suppkey"],
+ "loops": 9,
+ "rows": 600,
+ "cost": 0.757220078,
+ "filtered": 11.11111069,
+ "using_index": true
+ }
+ }
+ ]
+ }
+}
+select count(*) from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+count(*)
+5373
+select 5373 as count, 136458704.22 as old_sum;
+count old_sum
+5373 136458704.22
+explain
+update lineitem set l_extendedprice=l_extendedprice+10 where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY lineitem ALL i_l_suppkey NULL NULL NULL 6005
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED partsupp_small range PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part PRIMARY 4 NULL 9 Using where; Using index
+explain format=json
+update lineitem set l_extendedprice=l_extendedprice+10 where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 2.191459679,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ALL",
+ "possible_keys": ["i_l_suppkey"],
+ "loops": 1,
+ "rows": 6005,
+ "cost": 0.988432825,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
+ "key_length": "4",
+ "used_key_parts": ["ps_suppkey"],
+ "ref": ["func"],
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "range",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["ps_partkey"],
+ "loops": 1,
+ "rows": 9,
+ "cost": 0.003756598,
+ "filtered": 100,
+ "attached_condition": "partsupp_small.ps_partkey in (1,2,3)",
+ "using_index": true
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+update lineitem set l_extendedprice=l_extendedprice+10 where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+(136458704.22+10*5373) as 'old_sum+10*count'
+ from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum+10*count
+136512434.22 5373 136512434.22
+update lineitem set l_extendedprice=l_extendedprice-10 where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+136458704.22 as old_sum from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum
+136458704.22 5373 136458704.22
+# LooseScan PS
+# ============
+prepare stmt from "
+update lineitem set l_extendedprice=l_extendedprice+? where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+";
+select 5373 as count, 136458704.22 as old_sum;
+count old_sum
+5373 136458704.22
+set @a1=20;
+execute stmt using @a1;
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+(136458704.22+20*5373) as 'old_sum+20*count'
+ from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum+20*count
+136566164.22 5373 136566164.22
+set @a2=10;
+execute stmt using @a2;
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+(136458704.22+30*5373) as 'old_sum+30*count'
+ from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum+30*count
+136619894.22 5373 136619894.22
+execute stmt using -(@a1+@a2);
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+136458704.22 as old_sum from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum
+136458704.22 5373 136458704.22
+deallocate prepare stmt;
+# LooseScan SP
+# ============
+create procedure p(d int)
+update lineitem set l_extendedprice=l_extendedprice+d where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+select 5373 as count, 136458704.22 as old_sum;
+count old_sum
+5373 136458704.22
+call p(10);
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+(136458704.22+10*5373) as 'old_sum+10*count'
+ from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum+10*count
+136512434.22 5373 136512434.22
+call p(20);
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+(136458704.22+30*5373) as 'old_sum+30*count'
+ from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum+30*count
+136619894.22 5373 136619894.22
+call p(-(10+20));
+select ROUND(sum(l_extendedprice),2), 5373 as count,
+136458704.22 as old_sum from lineitem where l_suppkey in
+(select ps_suppkey from partsupp_small
+where ps_partkey in (1,2,3));
+ROUND(sum(l_extendedprice),2) count old_sum
+136458704.22 5373 136458704.22
+drop procedure p;
+# DuplicateWeedout
+# ================
+set @tmp_optimizer_switch= @@optimizer_switch;
+set optimizer_switch='materialization=off';
+analyze table lineitem;
+Table Op Msg_type Msg_text
+dbt3_s001.lineitem analyze status Engine-independent statistics collected
+dbt3_s001.lineitem analyze status OK
+analyze table orders;
+Table Op Msg_type Msg_text
+dbt3_s001.orders analyze status Engine-independent statistics collected
+dbt3_s001.orders analyze status OK
+explain
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY supplier range PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Start temporary
+1 PRIMARY partsupp_small ref PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part i_ps_sup_part 4 dbt3_s001.supplier.s_suppkey 17 Using where; Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index; End temporary
+explain format=json
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 4.129940741,
+ "nested_loop": [
+ {
+ "duplicates_removal": [
+ {
+ "table": {
+ "table_name": "supplier",
+ "access_type": "range",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["s_suppkey"],
+ "loops": 1,
+ "rows": 1,
+ "cost": 0.001478954,
+ "filtered": 100,
+ "attached_condition": "supplier.s_suppkey < 2",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "i_ps_sup_part",
+ "key_length": "4",
+ "used_key_parts": ["ps_suppkey"],
+ "ref": ["dbt3_s001.supplier.s_suppkey"],
+ "loops": 1,
+ "rows": 17,
+ "cost": 0.003160332,
+ "filtered": 79.54545593,
+ "attached_condition": "partsupp_small.ps_partkey is not null",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_suppkey_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 14,
+ "rows": 30,
+ "cost": 0.069152188,
+ "filtered": 100,
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 420.35,
+ "rows": 30,
+ "cost": 1.994712365,
+ "filtered": 0.237896994,
+ "using_index": true
+ }
+ }
+ ]
+ }
+ ]
+ }
+}
+select count(*) from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+count(*)
+471
+select 471 as count, 10751458.66 as old_sum;
+count old_sum
+471 10751458.66
+explain
+update lineitem set l_extendedprice=l_extendedprice+10 where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY supplier range PRIMARY PRIMARY 4 NULL 1 Using where; Using index; Start temporary
+1 PRIMARY partsupp_small ref PRIMARY,i_ps_partkey,i_ps_suppkey,i_ps_sup_part i_ps_sup_part 4 dbt3_s001.supplier.s_suppkey 17 Using where; Using index
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30
+1 PRIMARY lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 dbt3_s001.partsupp_small.ps_partkey 30 Using index; End temporary
+explain format=json
+update lineitem set l_extendedprice=l_extendedprice+10 where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 4.590092321,
+ "nested_loop": [
+ {
+ "duplicates_removal": [
+ {
+ "table": {
+ "table_name": "supplier",
+ "access_type": "range",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["s_suppkey"],
+ "loops": 1,
+ "rows": 1,
+ "cost": 0.001478954,
+ "filtered": 100,
+ "attached_condition": "supplier.s_suppkey < 2",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "partsupp_small",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_ps_partkey",
+ "i_ps_suppkey",
+ "i_ps_sup_part"
+ ],
+ "key": "i_ps_sup_part",
+ "key_length": "4",
+ "used_key_parts": ["ps_suppkey"],
+ "ref": ["dbt3_s001.supplier.s_suppkey"],
+ "loops": 1,
+ "rows": 17,
+ "cost": 0.003160332,
+ "filtered": 79.54545593,
+ "attached_condition": "partsupp_small.ps_partkey is not null",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_suppkey_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 14,
+ "rows": 30,
+ "cost": 0.529303768,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": ["i_l_suppkey_partkey", "i_l_partkey"],
+ "key": "i_l_partkey",
+ "key_length": "5",
+ "used_key_parts": ["l_partkey"],
+ "ref": ["dbt3_s001.partsupp_small.ps_partkey"],
+ "loops": 420.35,
+ "rows": 30,
+ "cost": 1.994712365,
+ "filtered": 0.237896994,
+ "using_index": true
+ }
+ }
+ ]
+ }
+ ]
+ }
+}
+update lineitem set l_extendedprice=l_extendedprice+10 where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+select ROUND(sum(l_extendedprice),2), 471 as count,
+(10751458.66+10*471) as 'old_sum+10*count'
+ from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum+10*count
+10756168.66 471 10756168.66
+update lineitem set l_extendedprice=l_extendedprice-10 where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+select ROUND(sum(l_extendedprice),2), 471 as count,
+10751458.66 as old_sum from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum
+10751458.66 471 10751458.66
+# DuplicateWeedout PS
+# ===================
+prepare stmt from "
+update lineitem set l_extendedprice=l_extendedprice+? where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+";
+select 471 as count, 10751458.66 as old_sum;
+count old_sum
+471 10751458.66
+set @a1=20;
+execute stmt using @a1;
+select ROUND(sum(l_extendedprice),2), 471 as count,
+(10751458.66+20*471) as 'old_sum+20*count'
+ from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum+20*count
+10760878.66 471 10760878.66
+set @a2=10;
+execute stmt using @a2;
+select ROUND(sum(l_extendedprice),2), 471 as count,
+(10751458.66+30*471) as 'old_sum+30*count'
+ from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum+30*count
+10765588.66 471 10765588.66
+execute stmt using -(@a1+@a2);
+select ROUND(sum(l_extendedprice),2), 471 as count,
+10751458.66 as old_sum from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum
+10751458.66 471 10751458.66
+deallocate prepare stmt;
+# DuplicateWeedout SP
+# ===================
+create procedure p(d int)
+update lineitem set l_extendedprice=l_extendedprice+d where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+select 471 as count, 10751458.66 as old_sum;
+count old_sum
+471 10751458.66
+call p(10);
+select ROUND(sum(l_extendedprice),2), 471 as count,
+(10751458.66+10*471) as 'old_sum+10*count'
+ from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum+10*count
+10756168.66 471 10756168.66
+call p(20);
+select ROUND(sum(l_extendedprice),2), 471 as count,
+(10751458.66+30*471) as 'old_sum+30*count'
+ from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum+30*count
+10765588.66 471 10765588.66
+call p(-(10+20));
+select ROUND(sum(l_extendedprice),2), 471 as count,
+10751458.66 as old_sum from lineitem where l_partkey in (
+select ps_partkey
+from partsupp_small join lineitem on ps_partkey=l_partkey
+where ps_suppkey in (
+select s_suppkey from supplier where s_suppkey < 2
+)
+);
+ROUND(sum(l_extendedprice),2) count old_sum
+10751458.66 471 10751458.66
+drop procedure p;
+set @@optimizer_switch=@tmp_optimizer_switch;
+drop table partsupp_small;
DROP DATABASE dbt3_s001;
diff --git a/mysql-test/main/update_single_to_multi.test b/mysql-test/main/update_single_to_multi.test
index a215c5a..7364806 100644
--- a/mysql-test/main/update_single_to_multi.test
+++ b/mysql-test/main/update_single_to_multi.test
@@ -587,4 +587,246 @@ update orders set o_totalprice = o_totalprice+50 where $c11;
eval
select o_orderkey, o_totalprice from orders where $c11;
+CREATE TABLE partsupp_small (
+ ps_partkey int(11) NOT NULL DEFAULT '0',
+ ps_suppkey int(11) NOT NULL DEFAULT '0',
+ ps_availqty int(11) DEFAULT NULL,
+ ps_supplycost double DEFAULT NULL,
+ ps_comment varchar(199) DEFAULT NULL,
+ PRIMARY KEY (ps_partkey,ps_suppkey),
+ KEY i_ps_partkey (ps_partkey),
+ KEY i_ps_suppkey (ps_suppkey)
+);
+
+create index i_ps_sup_part on partsupp_small(ps_suppkey, ps_partkey);
+insert into partsupp_small select * from partsupp where ps_partkey <50;
+analyze table partsupp_small persistent for all;
+
+--echo # LooseScan
+--echo # =========
+
+let $c12 = l_suppkey in
+ (select ps_suppkey from partsupp_small
+ where ps_partkey in (1,2,3));
+
+eval
+explain
+select count(*) from lineitem where $c12;
+eval
+explain format=json
+select count(*) from lineitem where $c12;
+eval
+select count(*) from lineitem where $c12;
+let $l_count =
+ query_get_value('select count(*) as a from lineitem where $c12;', a, 1);
+let $l_old_sum =
+ query_get_value('select ROUND(sum(l_extendedprice),2) as a
+ from lineitem where $c12;', a, 1
+ );
+eval select $l_count as count, $l_old_sum as old_sum;
+
+eval
+explain
+update lineitem set l_extendedprice=l_extendedprice+10 where $c12;
+eval
+explain format=json
+update lineitem set l_extendedprice=l_extendedprice+10 where $c12;
+eval
+update lineitem set l_extendedprice=l_extendedprice+10 where $c12;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+10*$l_count) as 'old_sum+10*count'
+ from lineitem where $c12;
+
+eval
+update lineitem set l_extendedprice=l_extendedprice-10 where $c12;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ $l_old_sum as old_sum from lineitem where $c12;
+
+
+--echo # LooseScan PS
+--echo # ============
+
+eval
+prepare stmt from "
+update lineitem set l_extendedprice=l_extendedprice+? where $c12;
+";
+
+let $l_count = query_get_value('select count(*) as a
+ from lineitem where $c12;', a, 1 );
+let $l_old_sum = query_get_value('select ROUND(sum(l_extendedprice),2) as a
+ from lineitem where $c12;', a, 1 );
+eval select $l_count as count, $l_old_sum as old_sum;
+eval
+set @a1=20;
+execute stmt using @a1;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+20*$l_count) as 'old_sum+20*count'
+ from lineitem where $c12;
+set @a2=10;
+execute stmt using @a2;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+30*$l_count) as 'old_sum+30*count'
+ from lineitem where $c12;
+execute stmt using -(@a1+@a2);
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ $l_old_sum as old_sum from lineitem where $c12;
+
+deallocate prepare stmt;
+
+--echo # LooseScan SP
+--echo # ============
+
+eval
+create procedure p(d int)
+update lineitem set l_extendedprice=l_extendedprice+d where $c12;
+
+let $l_count = query_get_value('select count(*) as a
+ from lineitem where $c12;', a, 1 );
+let $l_old_sum = query_get_value('select ROUND(sum(l_extendedprice),2) as a
+ from lineitem where $c12;', a, 1 );
+eval select $l_count as count, $l_old_sum as old_sum;
+eval
+call p(10);
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+10*$l_count) as 'old_sum+10*count'
+ from lineitem where $c12;
+call p(20);
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+30*$l_count) as 'old_sum+30*count'
+ from lineitem where $c12;
+call p(-(10+20));
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ $l_old_sum as old_sum from lineitem where $c12;
+
+drop procedure p;
+
+--echo # DuplicateWeedout
+--echo # ================
+
+set @tmp_optimizer_switch= @@optimizer_switch;
+set optimizer_switch='materialization=off';
+
+analyze table lineitem;
+analyze table orders;
+
+let $c13 = l_partkey in (
+ select ps_partkey
+ from partsupp_small join lineitem on ps_partkey=l_partkey
+ where ps_suppkey in (
+ select s_suppkey from supplier where s_suppkey < 2
+ )
+);
+
+eval
+explain
+select count(*) from lineitem where $c13;
+eval
+explain format=json
+select count(*) from lineitem where $c13;
+eval
+select count(*) from lineitem where $c13;
+
+let $l_count = query_get_value('select count(*) as a
+ from lineitem where $c13;', a, 1 );
+let $l_old_sum = query_get_value('select ROUND(sum(l_extendedprice),2) as a
+ from lineitem where $c13;', a, 1 );
+eval select $l_count as count, $l_old_sum as old_sum;
+
+eval
+explain
+update lineitem set l_extendedprice=l_extendedprice+10 where $c13;
+eval
+explain format=json
+update lineitem set l_extendedprice=l_extendedprice+10 where $c13;
+eval
+update lineitem set l_extendedprice=l_extendedprice+10 where $c13;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+10*$l_count) as 'old_sum+10*count'
+ from lineitem where $c13;
+
+eval
+update lineitem set l_extendedprice=l_extendedprice-10 where $c13;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ $l_old_sum as old_sum from lineitem where $c13;
+
+
+--echo # DuplicateWeedout PS
+--echo # ===================
+
+eval
+prepare stmt from "
+update lineitem set l_extendedprice=l_extendedprice+? where $c13;
+";
+
+let $l_count =
+ query_get_value('select count(*) as a
+ from lineitem where $c13;', a, 1 );
+let $l_old_sum =
+ query_get_value('select ROUND(sum(l_extendedprice),2) as a
+ from lineitem where $c13;', a, 1);
+eval select $l_count as count, $l_old_sum as old_sum;
+eval
+set @a1=20;
+execute stmt using @a1;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+20*$l_count) as 'old_sum+20*count'
+ from lineitem where $c13;
+set @a2=10;
+execute stmt using @a2;
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+30*$l_count) as 'old_sum+30*count'
+ from lineitem where $c13;
+execute stmt using -(@a1+@a2);
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ $l_old_sum as old_sum from lineitem where $c13;
+
+deallocate prepare stmt;
+
+--echo # DuplicateWeedout SP
+--echo # ===================
+
+eval
+create procedure p(d int)
+update lineitem set l_extendedprice=l_extendedprice+d where $c13;
+
+let $l_count = query_get_value('select count(*) as a
+ from lineitem where $c13;', a, 1 );
+let $l_old_sum = query_get_value('select ROUND(sum(l_extendedprice),2) as a
+ from lineitem where $c13;', a, 1 );
+eval select $l_count as count, $l_old_sum as old_sum;
+eval
+call p(10);
+
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+10*$l_count) as 'old_sum+10*count'
+ from lineitem where $c13;
+call p(20);
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ ($l_old_sum+30*$l_count) as 'old_sum+30*count'
+ from lineitem where $c13;
+call p(-(10+20));
+eval
+select ROUND(sum(l_extendedprice),2), $l_count as count,
+ $l_old_sum as old_sum from lineitem where $c13;
+
+drop procedure p;
+set @@optimizer_switch=@tmp_optimizer_switch;
+
+drop table partsupp_small;
+
DROP DATABASE dbt3_s001;
diff --git a/mysql-test/main/update_use_source.result b/mysql-test/main/update_use_source.result
index 99d7242..d756775 100644
--- a/mysql-test/main/update_use_source.result
+++ b/mysql-test/main/update_use_source.result
@@ -1,4 +1,16 @@
-create table t1 (old_c1 integer, old_c2 integer,c1 integer, c2 integer, c3 integer) engine=InnoDB STATS_PERSISTENT=0;
+set @save_default_engine=@@default_storage_engine;
+#######################################
+# #
+# Engine InnoDB #
+# #
+#######################################
+set global innodb_stats_persistent=1;
+set default_storage_engine=InnoDB;
+create table t1 (old_c1 integer,
+old_c2 integer,
+c1 integer,
+c2 integer,
+c3 integer);
create view v1 as select * from t1 where c2=2;
create trigger trg_t1 before update on t1 for each row
begin
@@ -6,37 +18,39 @@ set new.old_c1=old.c1;
set new.old_c2=old.c2;
end;
/
-insert into t1(c1,c2,c3) values (1,1,1);
-insert into t1(c1,c2,c3) values (1,2,2);
-insert into t1(c1,c2,c3) values (1,3,3);
-insert into t1(c1,c2,c3) values (2,1,4);
-insert into t1(c1,c2,c3) values (2,2,5);
-insert into t1(c1,c2,c3) values (2,3,6);
-insert into t1(c1,c2,c3) values (2,4,7);
-insert into t1(c1,c2,c3) values (2,5,8);
-commit;
-select * from t1;
-old_c1 old_c2 c1 c2 c3
-NULL NULL 1 1 1
-NULL NULL 1 2 2
-NULL NULL 1 3 3
-NULL NULL 2 1 4
-NULL NULL 2 2 5
-NULL NULL 2 3 6
-NULL NULL 2 4 7
-NULL NULL 2 5 8
-Test without any index
-#
-# Update a with value from subquery on the same table, no search clause. ALL access
-#
-start transaction;
-update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select NULL, NULL, c1+10,c2,c3+10 from t1;
+insert into t1 select NULL, NULL, c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1;
+#######################################
+# Test without any index #
+#######################################
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -46,20 +60,56 @@ concat(old_c1,'->',c1) c3 Changed
2->6 6 *
2->7 7 *
2->8 8 *
-rollback;
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update with search clause on the same table
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
#
-start transaction;
-update t1
-set c1=10
-where c1 <2
-and exists (select 'X'
- from t1 a
-where a.c1 = t1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
affected rows: 3
info: Rows matched: 3 Changed: 3 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->10 1 *
1->10 2 *
@@ -69,19 +119,55 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update via RANGE or INDEX access if an index or a primary key exists
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
#
-explain update t1 set c1=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 > 3;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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)
-start transaction;
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-affected rows: 4
-info: Rows matched: 4 Changed: 4 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -91,13 +177,57 @@ NULL 5
2->12 6 *
2->12 7 *
2->12 8 *
-rollback;
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
# Update with order by
#
-start transaction;
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 order by c2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -107,18 +237,54 @@ NULL 5
2->12 6 *
2->12 7 *
2->12 8 *
-rollback;
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-Update using a view in subquery
+# Update with a reference to view in subquery
+# in settable value
#
-start transaction;
-update t1
-set c1=c1 +(select max(a.c2)
-from v1 a
-where a.c1 = t1.c1) ;
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->3 1 *
1->3 2 *
@@ -128,19 +294,53 @@ concat(old_c1,'->',c1) c3 Changed
2->4 6 *
2->4 7 *
2->4 8 *
-rollback;
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update throw a view
+# Update view
#
-start transaction;
-update v1
-set c1=c1 + (select max(a.c2)
-from t1 a
-where a.c1 = v1.c1) +10
-where c3 > 3;
-affected rows: 1
-info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -150,20 +350,55 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with reference to the same view in subquery
#
-start transaction;
-update v1
-set c1=c1 + 1
-where c1 <2
-and exists (select 'X'
- from v1 a
-where a.c1 = v1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->2 2 *
@@ -173,22 +408,57 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with EXISTS and reference to the same view in subquery
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
update v1
-set c1=(select max(a.c1)+10
-from v1 a
-where a.c1 = v1.c1)
-where c1 <10
-and exists (select 'X'
- from v1 a
-where a.c2 = v1.c2);
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->11 2 *
@@ -198,41 +468,107 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update of the index or primary key (c3)
+# Update with IN predicand over the updated table in WHERE
#
-start transaction;
-explain update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 8
-1 PRIMARY a ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t1)
-update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
select c3 from t1;
c3
-11
-12
-13
-14
-15
-16
-17
-18
-rollback;
-#
-# update with a limit
-#
-start transaction;
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
-limit 2;
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -242,19 +578,55 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# update with a limit and an order by
+# Update with a limit and an order by
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -262,22 +634,61 @@ NULL 3
NULL 4
NULL 5
NULL 6
-2->7 7 *
-2->8 8 *
-rollback;
-Test with an index on updated columns
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with an index #
+#######################################
create index t1_c2 on t1 (c2,c1);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
#
-# Update a with value from subquery on the same table, no search clause. ALL access
+# Update with value from subquery on the same table
#
-start transaction;
-update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -287,20 +698,56 @@ concat(old_c1,'->',c1) c3 Changed
2->6 6 *
2->7 7 *
2->8 8 *
-rollback;
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update with search clause on the same table
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
#
-start transaction;
-update t1
-set c1=10
-where c1 <2
-and exists (select 'X'
- from t1 a
-where a.c1 = t1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
affected rows: 3
info: Rows matched: 3 Changed: 3 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->10 1 *
1->10 2 *
@@ -310,19 +757,53 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update via RANGE or INDEX access if an index or a primary key exists
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
#
-explain update t1 set c1=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 > 3;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+explain update t1 set c1=c1+10 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 range t1_c2 t1_c2 5 NULL 2 Using index condition
-1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 8 Using index; FirstMatch(t1)
-start transaction;
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-affected rows: 4
-info: Rows matched: 4 Changed: 4 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -332,13 +813,55 @@ NULL 5
2->12 6 *
2->12 7 *
2->12 8 *
-rollback;
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
# Update with order by
#
-start transaction;
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 order by c2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+explain update t1 set c1=c1+10 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -348,18 +871,54 @@ NULL 5
2->12 6 *
2->12 7 *
2->12 8 *
-rollback;
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-Update using a view in subquery
+# Update with a reference to view in subquery
+# in settable value
#
-start transaction;
-update t1
-set c1=c1 +(select max(a.c2)
-from v1 a
-where a.c1 = t1.c1) ;
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->3 1 *
1->3 2 *
@@ -369,19 +928,53 @@ concat(old_c1,'->',c1) c3 Changed
2->4 6 *
2->4 7 *
2->4 8 *
-rollback;
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update throw a view
+# Update view
#
-start transaction;
-update v1
-set c1=c1 + (select max(a.c2)
-from t1 a
-where a.c1 = v1.c1) +10
-where c3 > 3;
-affected rows: 1
-info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref t1_c2 t1_c2 5 const 8
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a index NULL t1_c2 10 NULL 32 Using where; Using index
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -391,20 +984,55 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with reference to the same view in subquery
#
-start transaction;
-update v1
-set c1=c1 + 1
-where c1 <2
-and exists (select 'X'
- from v1 a
-where a.c1 = v1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 1 Using index condition
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index; FirstMatch(t1)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 1 Using index condition; Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func 1 Using where; Using index
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->2 2 *
@@ -414,22 +1042,57 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with EXISTS and reference to the same view in subquery
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 2 Using index condition
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 2 Using index condition
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 5 const 8 Using where; Using index
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
update v1
-set c1=(select max(a.c1)+10
-from v1 a
-where a.c1 = v1.c1)
-where c1 <10
-and exists (select 'X'
- from v1 a
-where a.c2 = v1.c2);
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->11 2 *
@@ -439,41 +1102,107 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update of the index or primary key (c3)
+# Update with IN predicand over the updated table in WHERE
#
-start transaction;
-explain update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 8 Using where
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
-update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
select c3 from t1;
c3
-11
-12
-13
-14
-15
-16
-17
-18
-rollback;
-#
-# update with a limit
-#
-start transaction;
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
-limit 2;
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -483,19 +1212,55 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# update with a limit and an order by
+# Update with a limit and an order by
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -503,22 +1268,62 @@ NULL 3
NULL 4
NULL 5
NULL 6
-2->7 7 *
-2->8 8 *
-rollback;
-Test with an index on updated columns
-create index t1_c3 on t1 (c3);
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
#
-# Update a with value from subquery on the same table, no search clause. ALL access
+# Update with value from subquery on the same table
#
-start transaction;
-update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -528,20 +1333,56 @@ concat(old_c1,'->',c1) c3 Changed
2->6 6 *
2->7 7 *
2->8 8 *
-rollback;
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update with search clause on the same table
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
#
-start transaction;
-update t1
-set c1=10
-where c1 <2
-and exists (select 'X'
- from t1 a
-where a.c1 = t1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
affected rows: 3
info: Rows matched: 3 Changed: 3 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->10 1 *
1->10 2 *
@@ -551,19 +1392,55 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update via RANGE or INDEX access if an index or a primary key exists
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
#
-explain update t1 set c1=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 > 3;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 a index t1_c2 t1_c2 10 NULL 8 Using where; Using index; LooseScan
-1 PRIMARY t1 ref t1_c2 t1_c2 5 test.a.c2 1
-start transaction;
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-affected rows: 4
-info: Rows matched: 4 Changed: 4 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -573,13 +1450,57 @@ NULL 5
2->12 6 *
2->12 7 *
2->12 8 *
-rollback;
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
# Update with order by
#
-start transaction;
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 order by c2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -589,18 +1510,54 @@ NULL 5
2->12 6 *
2->12 7 *
2->12 8 *
-rollback;
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-Update using a view in subquery
+# Update with a reference to view in subquery
+# in settable value
#
-start transaction;
-update t1
-set c1=c1 +(select max(a.c2)
-from v1 a
-where a.c1 = t1.c1) ;
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->3 1 *
1->3 2 *
@@ -610,19 +1567,53 @@ concat(old_c1,'->',c1) c3 Changed
2->4 6 *
2->4 7 *
2->4 8 *
-rollback;
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update throw a view
+# Update view
#
-start transaction;
-update v1
-set c1=c1 + (select max(a.c2)
-from t1 a
-where a.c1 = v1.c1) +10
-where c3 > 3;
-affected rows: 1
-info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range PRIMARY PRIMARY 4 NULL 29 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -632,20 +1623,55 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with reference to the same view in subquery
#
-start transaction;
-update v1
-set c1=c1 + 1
-where c1 <2
-and exists (select 'X'
- from v1 a
-where a.c1 = v1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->2 2 *
@@ -655,22 +1681,57 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with EXISTS and reference to the same view in subquery
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
update v1
-set c1=(select max(a.c1)+10
-from v1 a
-where a.c1 = v1.c1)
-where c1 <10
-and exists (select 'X'
- from v1 a
-where a.c2 = v1.c2);
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->11 2 *
@@ -680,41 +1741,107 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update of the index or primary key (c3)
+# Update with IN predicand over the updated table in WHERE
#
-start transaction;
-explain update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 8 Using where
-1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
-update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
select c3 from t1;
c3
-11
-12
-13
-14
-15
-16
-17
-18
-rollback;
-#
-# update with a limit
-#
-start transaction;
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
-limit 2;
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -724,19 +1851,55 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# update with a limit and an order by
+# Update with a limit and an order by
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL PRIMARY 4 NULL 2
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using buffer
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -744,127 +1907,7346 @@ NULL 3
NULL 4
NULL 5
NULL 6
-2->7 7 *
-2->8 8 *
-rollback;
-Test with a primary key on updated columns
-drop index t1_c3 on t1;
-alter table t1 add primary key (c3);
-#
-# Update a with value from subquery on the same table, no search clause. ALL access
-#
-start transaction;
-update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
-concat(old_c1,'->',c1) c3 Changed
-1->1 1
-1->2 2 *
-1->3 3 *
-2->4 4 *
-2->5 5 *
-2->6 6 *
-2->7 7 *
-2->8 8 *
-rollback;
-#
-# Update with search clause on the same table
-#
-start transaction;
-update t1
-set c1=10
-where c1 <2
-and exists (select 'X'
- from t1 a
-where a.c1 = t1.c1);
-affected rows: 3
-info: Rows matched: 3 Changed: 3 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
-concat(old_c1,'->',c1) c3 Changed
-1->10 1 *
-1->10 2 *
-1->10 3 *
-NULL 4
-NULL 5
-NULL 6
NULL 7
NULL 8
-rollback;
-#
-# Update via RANGE or INDEX access if an index or a primary key exists
-#
-explain update t1 set c1=0 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 a index t1_c2 t1_c2 10 NULL 8 Using where; Using index; LooseScan
-1 PRIMARY t1 ref t1_c2 t1_c2 5 test.a.c2 1
-start transaction;
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-affected rows: 4
-info: Rows matched: 4 Changed: 4 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-concat(old_c1,'->',c1) c3 Changed
-NULL 1
-NULL 2
-1->11 3 *
-NULL 4
-NULL 5
-2->12 6 *
-2->12 7 *
-2->12 8 *
-rollback;
-#
-# Update with order by
-#
-start transaction;
-update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 order by c2;
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-concat(old_c1,'->',c1) c3 Changed
-NULL 1
-NULL 2
-1->11 3 *
-NULL 4
-NULL 5
-2->12 6 *
-2->12 7 *
-2->12 8 *
-rollback;
-#
-Update using a view in subquery
-#
-start transaction;
-update t1
-set c1=c1 +(select max(a.c2)
-from v1 a
-where a.c1 = t1.c1) ;
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
-concat(old_c1,'->',c1) c3 Changed
-1->3 1 *
-1->3 2 *
-1->3 3 *
-2->4 4 *
-2->4 5 *
-2->4 6 *
-2->4 7 *
-2->4 8 *
-rollback;
-#
-# Update throw a view
-#
-start transaction;
-update v1
-set c1=c1 + (select max(a.c2)
-from t1 a
-where a.c1 = v1.c1) +10
-where c3 > 3;
-affected rows: 1
-info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+# Update with error "Subquery returns more than 1 row"
+update t1 set c2=(select c2 from t1);
+ERROR 21000: Subquery returns more than 1 row
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Update with error "Subquery returns more than 1 row"
+# and order by
+update t1 set c2=(select c2 from t1) order by c3;
+ERROR 21000: Subquery returns more than 1 row
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Duplicate value on update a primary key
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key and limit
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+# and limit
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Update no rows found
+update t1 set c1=10
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1 + 10);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+10 1 1
+10 2 2
+10 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Update no rows changed
+drop trigger trg_t1;
+update t1 set c1=c1
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 0
+info: Rows matched: 3 Changed: 0 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Check call of after trigger
+#
+create or replace trigger trg_t2 after update on t1 for each row
+begin
+declare msg varchar(100);
+if (new.c3 = 5) then
+set msg=concat('in after update trigger on ',new.c3);
+SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
+end if;
+end;
+/
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
+ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Check update with order by and after trigger
+#
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1)
+order by t1.c2, t1.c1;
+ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop view v1;
+#
+# Check update on view with check option
+#
+create view v1 as select * from t1 where c2=2 with check option;
+update v1 set c2=3 where c1=1;
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+update v1 set c2=(select max(c3) from v1) where c1=1;
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
+select c1,c2,c3 from t1;
+c1 c2 c3
+0 2 2
+1 1 1
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+#
+# Test on dynamic columns (blob)
+#
+create table assets (
+item_name varchar(32) primary key, -- A common attribute for all items
+dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets VALUES ('MariaDB T-shirt',
+COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets VALUES ('Thinkpad Laptop',
+COLUMN_CREATE('color', 'black', 'price', 500));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt blue
+Thinkpad Laptop black
+UPDATE assets
+SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years')
+WHERE item_name='Thinkpad Laptop';
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt NULL
+Thinkpad Laptop 3 years
+UPDATE assets
+SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
+WHERE item_name in
+(select b.item_name from assets b
+where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt NULL
+Thinkpad Laptop 4 years
+UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty',
+(select COLUMN_GET(b.dynamic_cols, 'color' as char)
+from assets b
+where assets.item_name = item_name));
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt blue
+Thinkpad Laptop black
+drop table assets;
+#
+# Test on fulltext columns
+#
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+('MySQL vs MariaDB database'),
+('Oracle vs MariaDB database'),
+('PostgreSQL vs MariaDB database'),
+('MariaDB overview'),
+('Foreign keys'),
+('Primary keys'),
+('Indexes'),
+('Transactions'),
+('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+MySQL vs MariaDB database
+Oracle vs MariaDB database
+PostgreSQL vs MariaDB database
+update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5)))
+from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
+where MATCH(copy) AGAINST('keys');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
+copy
+mykeyword Postg
+mykeyword Postg
+drop table ft2;
+#######################################
+# #
+# Engine Aria #
+# #
+#######################################
+set default_storage_engine=Aria;
+create table t1 (old_c1 integer,
+old_c2 integer,
+c1 integer,
+c2 integer,
+c3 integer);
+create view v1 as select * from t1 where c2=2;
+create trigger trg_t1 before update on t1 for each row
+begin
+set new.old_c1=old.c1;
+set new.old_c2=old.c2;
+end;
+/
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select NULL, NULL, c1+10,c2,c3+10 from t1;
+insert into t1 select NULL, NULL, c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1;
+#######################################
+# Test without any index #
+#######################################
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 range t1_c2 t1_c2 5 NULL 21 Using index condition
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+explain update t1 set c1=c1+10 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 range t1_c2 t1_c2 5 NULL 21 Using index condition
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 range t1_c2 t1_c2 5 NULL 21 Using index condition
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+explain update t1 set c1=c1+10 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 range t1_c2 t1_c2 5 NULL 21 Using index condition
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref t1_c2 t1_c2 5 const 8
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a index NULL t1_c2 10 NULL 32 Using where; Using index
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 1 Using index condition
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index; FirstMatch(t1)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 1 Using index condition; Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func 1 Using where; Using index
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 2 Using index condition
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 2 Using index condition
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 5 const 8 Using where; Using index
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range PRIMARY PRIMARY 4 NULL 30 Using index condition; Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL PRIMARY 4 NULL 2
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using buffer
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+# Update with error "Subquery returns more than 1 row"
+update t1 set c2=(select c2 from t1);
+ERROR 21000: Subquery returns more than 1 row
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Update with error "Subquery returns more than 1 row"
+# and order by
+update t1 set c2=(select c2 from t1) order by c3;
+ERROR 21000: Subquery returns more than 1 row
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Duplicate value on update a primary key
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key and limit
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+# and limit
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Update no rows found
+update t1 set c1=10
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1 + 10);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+10 1 1
+10 2 2
+10 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Update no rows changed
+drop trigger trg_t1;
+update t1 set c1=c1
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 0
+info: Rows matched: 3 Changed: 0 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Check call of after trigger
+#
+create or replace trigger trg_t2 after update on t1 for each row
+begin
+declare msg varchar(100);
+if (new.c3 = 5) then
+set msg=concat('in after update trigger on ',new.c3);
+SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
+end if;
+end;
+/
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
+ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 1
+2 1 4
+2 2 2
+2 2 5
+2 3 3
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Check update with order by and after trigger
+#
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1)
+order by t1.c2, t1.c1;
+ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 3 3
+11 2 12
+11 3 13
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 1
+2 1 11
+2 1 14
+2 1 4
+2 2 2
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop view v1;
+#
+# Check update on view with check option
+#
+create view v1 as select * from t1 where c2=2 with check option;
+update v1 set c2=3 where c1=1;
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+update v1 set c2=(select max(c3) from v1) where c1=1;
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
+select c1,c2,c3 from t1;
+c1 c2 c3
+0 2 2
+1 1 1
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+#
+# Test on dynamic columns (blob)
+#
+create table assets (
+item_name varchar(32) primary key, -- A common attribute for all items
+dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets VALUES ('MariaDB T-shirt',
+COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets VALUES ('Thinkpad Laptop',
+COLUMN_CREATE('color', 'black', 'price', 500));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt blue
+Thinkpad Laptop black
+UPDATE assets
+SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years')
+WHERE item_name='Thinkpad Laptop';
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt NULL
+Thinkpad Laptop 3 years
+UPDATE assets
+SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
+WHERE item_name in
+(select b.item_name from assets b
+where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt NULL
+Thinkpad Laptop 4 years
+UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty',
+(select COLUMN_GET(b.dynamic_cols, 'color' as char)
+from assets b
+where assets.item_name = item_name));
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt blue
+Thinkpad Laptop black
+drop table assets;
+#
+# Test on fulltext columns
+#
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+('MySQL vs MariaDB database'),
+('Oracle vs MariaDB database'),
+('PostgreSQL vs MariaDB database'),
+('MariaDB overview'),
+('Foreign keys'),
+('Primary keys'),
+('Indexes'),
+('Transactions'),
+('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+MySQL vs MariaDB database
+Oracle vs MariaDB database
+PostgreSQL vs MariaDB database
+update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5)))
+from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
+where MATCH(copy) AGAINST('keys');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
+copy
+mykeyword Postg
+mykeyword Postg
+drop table ft2;
+#######################################
+# #
+# Engine MyISAM #
+# #
+#######################################
+set default_storage_engine=MyISAM;
+create table t1 (old_c1 integer,
+old_c2 integer,
+c1 integer,
+c2 integer,
+c3 integer);
+create view v1 as select * from t1 where c2=2;
+create trigger trg_t1 before update on t1 for each row
+begin
+set new.old_c1=old.c1;
+set new.old_c2=old.c2;
+end;
+/
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select NULL, NULL, c1+10,c2,c3+10 from t1;
+insert into t1 select NULL, NULL, c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create table tmp as select * from t1;
+#######################################
+# Test without any index #
+#######################################
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a index NULL t1_c2 10 NULL 32 Using where; Using index; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+explain update t1 set c1=c1+10 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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+explain update t1 set c1=c1+10 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 5 Using index; FirstMatch(t1)
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref t1_c2 t1_c2 5 const 8
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using where
+2 DEPENDENT SUBQUERY a index NULL t1_c2 10 NULL 32 Using where; Using index
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 1 Using index condition
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index; FirstMatch(t1)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 1 Using index condition; Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func 1 Using where; Using index
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 2 Using index condition
+1 PRIMARY t1 ref t1_c2 t1_c2 5 const 8 Using index; FirstMatch(t1)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range t1_c2 t1_c2 10 NULL 2 Using index condition
+3 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 5 const 8 Using where; Using index
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 1 Using index
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status Table is already up to date
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL PRIMARY 4 NULL 2
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 index NULL PRIMARY 4 NULL 2 Using buffer
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1 Using index
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+# Update with error "Subquery returns more than 1 row"
+update t1 set c2=(select c2 from t1);
+ERROR 21000: Subquery returns more than 1 row
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Update with error "Subquery returns more than 1 row"
+# and order by
+update t1 set c2=(select c2 from t1) order by c3;
+ERROR 21000: Subquery returns more than 1 row
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Duplicate value on update a primary key
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key and limit
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+# and limit
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Update no rows found
+update t1 set c1=10
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1 + 10);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+10 1 1
+10 2 2
+10 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Update no rows changed
+drop trigger trg_t1;
+update t1 set c1=c1
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 0
+info: Rows matched: 3 Changed: 0 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Check call of after trigger
+#
+create or replace trigger trg_t2 after update on t1 for each row
+begin
+declare msg varchar(100);
+if (new.c3 = 5) then
+set msg=concat('in after update trigger on ',new.c3);
+SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
+end if;
+end;
+/
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
+ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 1
+2 1 4
+2 2 2
+2 2 5
+2 3 3
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Check update with order by and after trigger
+#
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1)
+order by t1.c2, t1.c1;
+ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 3 3
+11 2 12
+11 3 13
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 1
+2 1 11
+2 1 14
+2 1 4
+2 2 2
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop view v1;
+#
+# Check update on view with check option
+#
+create view v1 as select * from t1 where c2=2 with check option;
+update v1 set c2=3 where c1=1;
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+update v1 set c2=(select max(c3) from v1) where c1=1;
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
+select c1,c2,c3 from t1;
+c1 c2 c3
+0 2 2
+1 1 1
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop table tmp;
+drop view v1;
+drop table t1;
+#
+# Test on dynamic columns (blob)
+#
+create table assets (
+item_name varchar(32) primary key, -- A common attribute for all items
+dynamic_cols blob -- Dynamic columns will be stored here
+);
+INSERT INTO assets VALUES ('MariaDB T-shirt',
+COLUMN_CREATE('color', 'blue', 'size', 'XL'));
+INSERT INTO assets VALUES ('Thinkpad Laptop',
+COLUMN_CREATE('color', 'black', 'price', 500));
+SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt blue
+Thinkpad Laptop black
+UPDATE assets
+SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years')
+WHERE item_name='Thinkpad Laptop';
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt NULL
+Thinkpad Laptop 3 years
+UPDATE assets
+SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
+WHERE item_name in
+(select b.item_name from assets b
+where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt NULL
+Thinkpad Laptop 4 years
+UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty',
+(select COLUMN_GET(b.dynamic_cols, 'color' as char)
+from assets b
+where assets.item_name = item_name));
+SELECT item_name,
+COLUMN_GET(dynamic_cols, 'warranty' as char) AS color
+FROM assets;
+item_name color
+MariaDB T-shirt blue
+Thinkpad Laptop black
+drop table assets;
+#
+# Test on fulltext columns
+#
+CREATE TABLE ft2(copy TEXT,FULLTEXT(copy));
+INSERT INTO ft2(copy) VALUES
+('MySQL vs MariaDB database'),
+('Oracle vs MariaDB database'),
+('PostgreSQL vs MariaDB database'),
+('MariaDB overview'),
+('Foreign keys'),
+('Primary keys'),
+('Indexes'),
+('Transactions'),
+('Triggers');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
+copy
+MySQL vs MariaDB database
+Oracle vs MariaDB database
+PostgreSQL vs MariaDB database
+update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5)))
+from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
+where MATCH(copy) AGAINST('keys');
+SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
+copy
+mykeyword Postg
+mykeyword Postg
+drop table ft2;
+#######################################
+# #
+# Engine MEMORY #
+# #
+#######################################
+set default_storage_engine=MEMORY;
+create table t1 (old_c1 integer,
+old_c2 integer,
+c1 integer,
+c2 integer,
+c3 integer);
+create view v1 as select * from t1 where c2=2;
+create trigger trg_t1 before update on t1 for each row
+begin
+set new.old_c1=old.c1;
+set new.old_c2=old.c2;
+end;
+/
+insert into t1(c1,c2,c3)
+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);
+insert into t1 select NULL, NULL, c1+10,c2,c3+10 from t1;
+insert into t1 select NULL, NULL, c1+20,c2+1,c3+20 from t1;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+create table tmp as select * from t1;
+#######################################
+# Test without any index #
+#######################################
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with an index #
+#######################################
+create index t1_c2 on t1 (c2,c1);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL t1_c2 NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL t1_c2 NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL t1_c2 NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 t1_c2 NULL NULL NULL 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL t1_c2 NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 2
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL t1_c2 NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+2->17 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 2 FirstMatch(t1)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,func 2 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view with EXISTS and reference to the same view in subquery
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ref t1_c2 t1_c2 10 const,test.t1.c1 2
+update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+1->11 2 *
+NULL 3
+NULL 4
+2->12 5 *
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with IN predicand over the updated table in WHERE
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 2 FirstMatch(t1)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 32 Using where
+1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 2 FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select c3 from t1;
+c3
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit and an order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Operation failed
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+NULL 3
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#######################################
+# Test with a primary key #
+#######################################
+drop index t1_c2 on t1;
+alter table t1 add primary key (c3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+#
+# Update with value from subquery on the same table
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
+update t1 set c1=(select a.c3 from t1 a where a.c3 = t1.c3);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->1 1
+1->2 2 *
+1->3 3 *
+2->4 4 *
+2->5 5 *
+2->6 6 *
+2->7 7 *
+2->8 8 *
+11->11 11
+11->12 12 *
+11->13 13 *
+12->14 14 *
+12->15 15 *
+12->16 16 *
+12->17 17 *
+12->18 18 *
+21->21 21
+21->22 22 *
+21->23 23 *
+22->24 24 *
+22->25 25 *
+22->26 26 *
+22->27 27 *
+22->28 28 *
+31->31 31
+31->32 32 *
+31->33 33 *
+32->34 34 *
+32->35 35 *
+32->36 36 *
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + possibly sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c1=10 where c1 <2
+and exists (select 'X' from t1 a where a.c1 = t1.c1);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->10 1 *
+1->10 2 *
+1->10 3 *
+NULL 4
+NULL 5
+NULL 6
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with EXISTS subquery over the updated table
+# in WHERE + non-sargable condition
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with order by
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1+10 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 32 Using where; Using filesort
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED a ALL NULL NULL NULL NULL 32
+update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 order by c2;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+NULL 1
+NULL 2
+1->11 3 *
+NULL 4
+NULL 5
+2->12 6 *
+2->12 7 *
+2->12 8 *
+NULL 11
+NULL 12
+11->21 13 *
+NULL 14
+NULL 15
+12->22 16 *
+12->22 17 *
+12->22 18 *
+NULL 21
+21->31 22 *
+21->31 23 *
+NULL 24
+22->32 25 *
+22->32 26 *
+22->32 27 *
+22->32 28 *
+NULL 31
+31->41 32 *
+31->41 33 *
+NULL 34
+32->42 35 *
+32->42 36 *
+32->42 37 *
+32->42 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a reference to view in subquery
+# in settable value
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update t1 set c1=c1 +(select max(a.c2) from v1 a
+where a.c1 = t1.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+concat(old_c1,'->',c1) c3 Changed
+1->3 1 *
+1->3 2 *
+1->3 3 *
+2->4 4 *
+2->4 5 *
+2->4 6 *
+2->4 7 *
+2->4 8 *
+11->13 11 *
+11->13 12 *
+11->13 13 *
+12->14 14 *
+12->14 15 *
+12->14 16 *
+12->14 17 *
+12->14 18 *
+21->23 21 *
+21->23 22 *
+21->23 23 *
+22->24 24 *
+22->24 25 *
+22->24 26 *
+22->24 27 *
+22->24 28 *
+31->33 31 *
+31->33 32 *
+31->33 33 *
+32->34 34 *
+32->34 35 *
+32->34 36 *
+32->34 37 *
+32->34 38 *
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update view
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using where
+explain update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY a ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + (select max(a.c2) from t1 a
+where a.c1 = v1.c1) +10 where c3 > 3;
+affected rows: 7
+info: Rows matched: 7 Changed: 7 Warnings: 0
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -874,20 +9256,55 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+11->24 12 *
+NULL 13
+NULL 14
+12->27 15 *
+NULL 16
+NULL 17
+NULL 18
+21->35 21 *
+NULL 22
+NULL 23
+22->38 24 *
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+31->45 31 *
+NULL 32
+NULL 33
+32->48 34 *
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with reference to the same view in subquery
#
-start transaction;
-update v1
-set c1=c1 + 1
-where c1 <2
-and exists (select 'X'
- from v1 a
-where a.c1 = v1.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from v1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+update v1 set c1=c1 + 1 where c1 <2
+and exists (select 'X' from v1 a where a.c1 = v1.c1);
affected rows: 1
info: Rows matched: 1 Changed: 1 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->2 2 *
@@ -897,22 +9314,57 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update through a view and using the view in subquery
+# Update view with EXISTS and reference to the same view in subquery
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from v1 where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update v1
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using where
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 32 Using where
update v1
-set c1=(select max(a.c1)+10
-from v1 a
-where a.c1 = v1.c1)
-where c1 <10
-and exists (select 'X'
- from v1 a
-where a.c2 = v1.c2);
+set c1=(select max(a.c1)+10 from v1 a where a.c1 = v1.c1)
+where c1 <10 and exists (select 'X' from v1 a where a.c2 = v1.c2);
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
1->11 2 *
@@ -922,41 +9374,107 @@ NULL 4
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# Update of the index or primary key (c3)
+# Update with IN predicand over the updated table in WHERE
#
-start transaction;
-explain update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL t1_c2 NULL NULL NULL 8 Using where
-1 PRIMARY a ref t1_c2 t1_c2 10 test.t1.c2,test.t1.c1 1 Using index; FirstMatch(t1)
-update t1 set c3=c3+10 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
-affected rows: 8
-info: Rows matched: 8 Changed: 8 Warnings: 0
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
+explain update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+1 PRIMARY a ALL NULL NULL NULL NULL 32 Using where; FirstMatch(t1)
+update t1 set c3=c3+110 where c2 in (select distinct a.c2 from t1 a where t1.c1=a.c1);
+affected rows: 32
+info: Rows matched: 32 Changed: 32 Warnings: 0
select c3 from t1;
c3
-11
-14
-12
-15
-13
-16
-17
-18
-rollback;
-#
-# update with a limit
-#
-start transaction;
+111
+112
+113
+114
+115
+116
+117
+118
+121
+122
+123
+124
+125
+126
+127
+128
+131
+132
+133
+134
+135
+136
+137
+138
+141
+142
+143
+144
+145
+146
+147
+148
+truncate table t1;
+insert into t1 select * from tmp;
+#
+# Update with a limit
+#
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
-limit 2;
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3) limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
1->1 1
1->2 2 *
@@ -966,19 +9484,55 @@ NULL 5
NULL 6
NULL 7
NULL 8
-rollback;
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+NULL 37
+NULL 38
+truncate table t1;
+insert into t1 select * from tmp;
#
-# update with a limit and an order by
+# Update with a limit and an order by
#
-start transaction;
+analyze table t1 persistent for all;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze note The storage engine for the table doesn't support analyze
+explain select * from t1 order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using filesort
+explain update t1
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
+order by c3 desc limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 32 Using filesort
+2 DEPENDENT SUBQUERY a eq_ref PRIMARY PRIMARY 4 test.t1.c3 1
update t1
-set c1=(select a.c3
-from t1 a
-where a.c3 = t1.c3)
+set c1=(select a.c3 from t1 a where a.c3 = t1.c3)
order by c3 desc limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-select concat(old_c1,'->',c1),c3, case when c1 != old_c1 then '*' else ' ' end "Changed" from t1 ;
+select concat(old_c1,'->',c1),c3,
+case when c1 != old_c1 then '*' else ' ' end "Changed" from t1;
concat(old_c1,'->',c1) c3 Changed
NULL 1
NULL 2
@@ -986,58 +9540,357 @@ NULL 3
NULL 4
NULL 5
NULL 6
-2->7 7 *
-2->8 8 *
-rollback;
+NULL 7
+NULL 8
+NULL 11
+NULL 12
+NULL 13
+NULL 14
+NULL 15
+NULL 16
+NULL 17
+NULL 18
+NULL 21
+NULL 22
+NULL 23
+NULL 24
+NULL 25
+NULL 26
+NULL 27
+NULL 28
+NULL 31
+NULL 32
+NULL 33
+NULL 34
+NULL 35
+NULL 36
+32->37 37 *
+32->38 38 *
+truncate table t1;
+insert into t1 select * from tmp;
# Update with error "Subquery returns more than 1 row"
update t1 set c2=(select c2 from t1);
ERROR 21000: Subquery returns more than 1 row
-# Update with error "Subquery returns more than 1 row" and order by
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Update with error "Subquery returns more than 1 row"
+# and order by
update t1 set c2=(select c2 from t1) order by c3;
ERROR 21000: Subquery returns more than 1 row
-Duplicate value on update a primary key
-start transaction;
-update t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+# Duplicate value on update a primary key
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
-rollback;
-Duplicate value on update a primary key with ignore
-start transaction;
-update ignore t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-affected rows: 4
-info: Rows matched: 4 Changed: 4 Warnings: 0
-rollback;
-Duplicate value on update a primary key and limit
-start transaction;
-update t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 limit 2;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
+affected rows: 20
+info: Rows matched: 20 Changed: 20 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key and limit
+update t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
-rollback;
-Duplicate value on update a primary key with ignore and limit
-start transaction;
-update ignore t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 limit 2;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+# Duplicate value on update a primary key with ignore
+# and limit
+update ignore t1 set c3=0
+where exists (select 'X' from t1 a where a.c2 = t1.c2)
+and c2 >= 3 limit 2;
affected rows: 2
info: Rows matched: 2 Changed: 2 Warnings: 0
-rollback;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 0
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
# Update no rows found
-update t1
-set c1=10
-where c1 <2
-and exists (select 'X'
- from t1 a
-where a.c1 = t1.c1 + 10);
-affected rows: 0
-info: Rows matched: 0 Changed: 0 Warnings: 0
+update t1 set c1=10
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1 + 10);
+affected rows: 3
+info: Rows matched: 3 Changed: 3 Warnings: 0
+select c1,c2,c3 from t1;
+c1 c2 c3
+10 1 1
+10 2 2
+10 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
# Update no rows changed
drop trigger trg_t1;
-start transaction;
-update t1
-set c1=c1
-where c1 <2
-and exists (select 'X'
- from t1 a
-where a.c1 = t1.c1);
+update t1 set c1=c1
+where c1 <2 and exists (select 'X' from t1 a where a.c1 = t1.c1);
affected rows: 0
info: Rows matched: 3 Changed: 0 Warnings: 0
-rollback;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
#
# Check call of after trigger
#
@@ -1050,126 +9903,218 @@ SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
end if;
end;
/
-update t1 set c1=2 where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 1
+2 1 4
+2 2 2
+2 2 5
+2 3 3
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
#
# Check update with order by and after trigger
#
-update t1 set c1=2 where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1) order by t1.c2;
+update t1 set c1=2
+where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1)
+order by t1.c2, t1.c1;
ERROR 45000: in after update trigger on 5
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 3 3
+11 2 12
+11 3 13
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 1
+2 1 11
+2 1 14
+2 1 4
+2 2 2
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
drop view v1;
#
# Check update on view with check option
#
create view v1 as select * from t1 where c2=2 with check option;
-start transaction;
update v1 set c2=3 where c1=1;
ERROR 44000: CHECK OPTION failed `test`.`v1`
-rollback;
-start transaction;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
update v1 set c2=(select max(c3) from v1) where c1=1;
ERROR 44000: CHECK OPTION failed `test`.`v1`
-rollback;
-start transaction;
+select c1,c2,c3 from t1;
+c1 c2 c3
+1 1 1
+1 2 2
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
+2 1 4
+2 2 5
+2 3 6
+2 4 7
+2 5 8
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
-rollback;
-drop view v1;
-drop table t1;
-#
-# Test with a temporary table
-#
-create temporary table t1 (c1 integer, c2 integer, c3 integer) engine=InnoDb;
-insert into t1(c1,c2,c3) values (1,1,1);
-insert into t1(c1,c2,c3) values (1,2,2);
-insert into t1(c1,c2,c3) values (1,3,3);
-insert into t1(c1,c2,c3) values (2,1,4);
-insert into t1(c1,c2,c3) values (2,2,5);
-insert into t1(c1,c2,c3) values (2,3,6);
-insert into t1(c1,c2,c3) values (2,4,7);
-insert into t1(c1,c2,c3) values (2,5,8);
-start transaction;
-update t1
-set c1=(select a.c2
-from t1 a
-where a.c3 = t1.c3) limit 3;
-affected rows: 2
-info: Rows matched: 3 Changed: 2 Warnings: 0
-select * from t1 ;
+select c1,c2,c3 from t1;
c1 c2 c3
+0 2 2
1 1 1
-2 2 2
-3 3 3
+1 3 3
+11 1 11
+11 2 12
+11 3 13
+12 1 14
+12 2 15
+12 3 16
+12 4 17
+12 5 18
2 1 4
2 2 5
2 3 6
2 4 7
2 5 8
-rollback;
+21 2 21
+21 3 22
+21 4 23
+22 2 24
+22 3 25
+22 4 26
+22 5 27
+22 6 28
+31 2 31
+31 3 32
+31 4 33
+32 2 34
+32 3 35
+32 4 36
+32 5 37
+32 6 38
+truncate table t1;
+insert into t1 select * from tmp;
+drop table tmp;
+drop view v1;
drop table t1;
-#
-# Test on dynamic columns (blob)
-#
-create table assets (
-item_name varchar(32) primary key, -- A common attribute for all items
-dynamic_cols blob -- Dynamic columns will be stored here
-);
-INSERT INTO assets VALUES ('MariaDB T-shirt', COLUMN_CREATE('color', 'blue', 'size', 'XL'));
-INSERT INTO assets VALUES ('Thinkpad Laptop', COLUMN_CREATE('color', 'black', 'price', 500));
-SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color FROM assets;
-item_name color
-MariaDB T-shirt blue
-Thinkpad Laptop black
-UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years') WHERE item_name='Thinkpad Laptop';
-SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
-item_name color
-MariaDB T-shirt NULL
-Thinkpad Laptop 3 years
-UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
-WHERE item_name in (select b.item_name
-from assets b
-where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
-SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
-item_name color
-MariaDB T-shirt NULL
-Thinkpad Laptop 4 years
-UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', (select COLUMN_GET(b.dynamic_cols, 'color' as char)
-from assets b
-where assets.item_name = item_name));
-SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
-item_name color
-MariaDB T-shirt blue
-Thinkpad Laptop black
-drop table assets ;
-#
-# Test on fulltext columns
-#
-CREATE TABLE ft2(copy TEXT,FULLTEXT(copy)) ENGINE=MyISAM;
-INSERT INTO ft2(copy) VALUES
-('MySQL vs MariaDB database'),
-('Oracle vs MariaDB database'),
-('PostgreSQL vs MariaDB database'),
-('MariaDB overview'),
-('Foreign keys'),
-('Primary keys'),
-('Indexes'),
-('Transactions'),
-('Triggers');
-SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
-copy
-MySQL vs MariaDB database
-Oracle vs MariaDB database
-PostgreSQL vs MariaDB database
-update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5))) from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
-where MATCH(copy) AGAINST('keys');
-SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
-copy
-mykeyword Postg
-mykeyword Postg
-drop table ft2;
+set @@default_storage_engine=@save_default_engine;
#
# Test with MyISAM
#
-create table t1 (old_c1 integer, old_c2 integer,c1 integer, c2 integer, c3 integer) engine=MyISAM;
+create table t1 (old_c1 integer,
+old_c2 integer,
+c1 integer,
+c2 integer,
+c3 integer) engine=MyISAM;
insert t1 (c1,c2,c3) select 0,seq,seq%10 from seq_1_to_500;
insert t1 (c1,c2,c3) select 1,seq,seq%10 from seq_1_to_400;
insert t1 (c1,c2,c3) select 2,seq,seq%10 from seq_1_to_300;
@@ -1189,11 +10134,13 @@ count(*)
140
drop table t1;
#
-# Test error on multi_update conversion on view with order by or limit
+# Test error on multi_update conversion on view
+# with order by or limit
#
create table t1 (c1 integer) engine=InnoDb;
create table t2 (c1 integer) engine=InnoDb;
-create view v1 as select t1.c1 as "t1c1" ,t2.c1 as "t2c1" from t1,t2 where t1.c1=t2.c1;
+create view v1 as select t1.c1 as "t1c1" ,t2.c1 as "t2c1"
+ from t1,t2 where t1.c1=t2.c1;
update v1 set t1c1=2 order by 1;
update v1 set t1c1=2 limit 1;
drop table t1;
diff --git a/mysql-test/main/update_use_source.test b/mysql-test/main/update_use_source.test
index 3c32a25..ec27fa4 100644
--- a/mysql-test/main/update_use_source.test
+++ b/mysql-test/main/update_use_source.test
@@ -2,221 +2,55 @@
--source include/have_innodb.inc
--source include/no_valgrind_without_big.inc
-create table t1 (old_c1 integer, old_c2 integer,c1 integer, c2 integer, c3 integer) engine=InnoDB STATS_PERSISTENT=0;
-create view v1 as select * from t1 where c2=2;
-delimiter /;
-create trigger trg_t1 before update on t1 for each row
-begin
- set new.old_c1=old.c1;
- set new.old_c2=old.c2;
-end;
-/
-delimiter ;/
-
-insert into t1(c1,c2,c3) values (1,1,1);
-insert into t1(c1,c2,c3) values (1,2,2);
-insert into t1(c1,c2,c3) values (1,3,3);
-insert into t1(c1,c2,c3) values (2,1,4);
-insert into t1(c1,c2,c3) values (2,2,5);
-insert into t1(c1,c2,c3) values (2,3,6);
-insert into t1(c1,c2,c3) values (2,4,7);
-insert into t1(c1,c2,c3) values (2,5,8);
-
-commit;
-select * from t1;
-
---echo Test without any index
+set @save_default_engine=@@default_storage_engine;
+
+--echo #######################################
+--echo # #
+--echo # Engine InnoDB #
+--echo # #
+--echo #######################################
+set global innodb_stats_persistent=1;
+set default_storage_engine=InnoDB;
--source include/update_use_source.inc
-
---echo Test with an index on updated columns
-create index t1_c2 on t1 (c2,c1);
+--source include/update_use_source_ext.inc
+
+--echo #######################################
+--echo # #
+--echo # Engine Aria #
+--echo # #
+--echo #######################################
+set default_storage_engine=Aria;
--source include/update_use_source.inc
-
---echo Test with an index on updated columns
-create index t1_c3 on t1 (c3);
+--source include/update_use_source_ext.inc
+
+--echo #######################################
+--echo # #
+--echo # Engine MyISAM #
+--echo # #
+--echo #######################################
+set default_storage_engine=MyISAM;
--source include/update_use_source.inc
-
---echo Test with a primary key on updated columns
-drop index t1_c3 on t1;
-alter table t1 add primary key (c3);
+--source include/update_use_source_ext.inc
+
+--echo #######################################
+--echo # #
+--echo # Engine MEMORY #
+--echo # #
+--echo #######################################
+set default_storage_engine=MEMORY;
--source include/update_use_source.inc
---echo # Update with error "Subquery returns more than 1 row"
---error ER_SUBQUERY_NO_1_ROW
-update t1 set c2=(select c2 from t1);
-
---echo # Update with error "Subquery returns more than 1 row" and order by
---error ER_SUBQUERY_NO_1_ROW
-update t1 set c2=(select c2 from t1) order by c3;
-
--- echo Duplicate value on update a primary key
-start transaction;
---error ER_DUP_ENTRY
-update t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-rollback;
-
--- echo Duplicate value on update a primary key with ignore
-start transaction;
---enable_info ONCE
-update ignore t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
-rollback;
-
--- echo Duplicate value on update a primary key and limit
-start transaction;
---error ER_DUP_ENTRY
-update t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 limit 2;
-rollback;
-
--- echo Duplicate value on update a primary key with ignore and limit
-start transaction;
---enable_info ONCE
-update ignore t1 set c3=0 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3 limit 2;
-rollback;
-
---echo # Update no rows found
---enable_info ONCE
-update t1
- set c1=10
- where c1 <2
- and exists (select 'X'
- from t1 a
- where a.c1 = t1.c1 + 10);
-
---echo # Update no rows changed
-drop trigger trg_t1;
-start transaction;
---enable_info ONCE
-update t1
- set c1=c1
- where c1 <2
- and exists (select 'X'
- from t1 a
- where a.c1 = t1.c1);
-rollback;
-
---echo #
---echo # Check call of after trigger
---echo #
-
-delimiter /;
-create or replace trigger trg_t2 after update on t1 for each row
-begin
- declare msg varchar(100);
- if (new.c3 = 5) then
- set msg=concat('in after update trigger on ',new.c3);
- SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
- end if;
-end;
-/
-delimiter ;/
---error 1644
-update t1 set c1=2 where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1);
-
---echo #
---echo # Check update with order by and after trigger
---echo #
-
---error 1644
-update t1 set c1=2 where c3 in (select distinct a.c3 from t1 a where a.c1=t1.c1) order by t1.c2;
-
-drop view v1;
---echo #
---echo # Check update on view with check option
---echo #
-
-create view v1 as select * from t1 where c2=2 with check option;
-
-start transaction;
--- error 1369
-update v1 set c2=3 where c1=1;
-rollback;
-
-start transaction;
--- error 1369
-update v1 set c2=(select max(c3) from v1) where c1=1;
-rollback;
-
-start transaction;
-update v1 set c2=(select min(va.c3) from v1 va), c1=0 where c1=1;
-rollback;
-
-drop view v1;
-drop table t1;
-
---echo #
---echo # Test with a temporary table
---echo #
-
-create temporary table t1 (c1 integer, c2 integer, c3 integer) engine=InnoDb;
-insert into t1(c1,c2,c3) values (1,1,1);
-insert into t1(c1,c2,c3) values (1,2,2);
-insert into t1(c1,c2,c3) values (1,3,3);
-insert into t1(c1,c2,c3) values (2,1,4);
-insert into t1(c1,c2,c3) values (2,2,5);
-insert into t1(c1,c2,c3) values (2,3,6);
-insert into t1(c1,c2,c3) values (2,4,7);
-insert into t1(c1,c2,c3) values (2,5,8);
-
-start transaction;
---enable_info ONCE
-update t1
- set c1=(select a.c2
- from t1 a
- where a.c3 = t1.c3) limit 3;
-select * from t1 ;
-rollback;
-drop table t1;
-
---echo #
---echo # Test on dynamic columns (blob)
---echo #
-
-create table assets (
- item_name varchar(32) primary key, -- A common attribute for all items
- dynamic_cols blob -- Dynamic columns will be stored here
-);
-INSERT INTO assets VALUES ('MariaDB T-shirt', COLUMN_CREATE('color', 'blue', 'size', 'XL'));
-INSERT INTO assets VALUES ('Thinkpad Laptop', COLUMN_CREATE('color', 'black', 'price', 500));
-SELECT item_name, COLUMN_GET(dynamic_cols, 'color' as char) AS color FROM assets;
-UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '3 years') WHERE item_name='Thinkpad Laptop';
-SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
-UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', '4 years')
- WHERE item_name in (select b.item_name
- from assets b
- where COLUMN_GET(b.dynamic_cols, 'color' as char) ='black');
-SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
-
-UPDATE assets SET dynamic_cols=COLUMN_ADD(dynamic_cols, 'warranty', (select COLUMN_GET(b.dynamic_cols, 'color' as char)
- from assets b
- where assets.item_name = item_name));
-SELECT item_name, COLUMN_GET(dynamic_cols, 'warranty' as char) AS color FROM assets;
-drop table assets ;
-
---echo #
---echo # Test on fulltext columns
---echo #
-CREATE TABLE ft2(copy TEXT,FULLTEXT(copy)) ENGINE=MyISAM;
-INSERT INTO ft2(copy) VALUES
- ('MySQL vs MariaDB database'),
- ('Oracle vs MariaDB database'),
- ('PostgreSQL vs MariaDB database'),
- ('MariaDB overview'),
- ('Foreign keys'),
- ('Primary keys'),
- ('Indexes'),
- ('Transactions'),
- ('Triggers');
-SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('database');
-update ft2 set copy = (select max(concat('mykeyword ',substr(b.copy,1,5))) from ft2 b WHERE MATCH(b.copy) AGAINST('database'))
- where MATCH(copy) AGAINST('keys');
-SELECT * FROM ft2 WHERE MATCH(copy) AGAINST('mykeyword');
-drop table ft2;
+set @@default_storage_engine=@save_default_engine;
--echo #
--echo # Test with MyISAM
--echo #
-create table t1 (old_c1 integer, old_c2 integer,c1 integer, c2 integer, c3 integer) engine=MyISAM;
+create table t1 (old_c1 integer,
+ old_c2 integer,
+ c1 integer,
+ c2 integer,
+ c3 integer) engine=MyISAM;
insert t1 (c1,c2,c3) select 0,seq,seq%10 from seq_1_to_500;
insert t1 (c1,c2,c3) select 1,seq,seq%10 from seq_1_to_400;
insert t1 (c1,c2,c3) select 2,seq,seq%10 from seq_1_to_300;
@@ -232,12 +66,14 @@ drop table t1;
--echo #
---echo # Test error on multi_update conversion on view with order by or limit
+--echo # Test error on multi_update conversion on view
+--echo # with order by or limit
--echo #
create table t1 (c1 integer) engine=InnoDb;
create table t2 (c1 integer) engine=InnoDb;
-create view v1 as select t1.c1 as "t1c1" ,t2.c1 as "t2c1" from t1,t2 where t1.c1=t2.c1;
+create view v1 as select t1.c1 as "t1c1" ,t2.c1 as "t2c1"
+ from t1,t2 where t1.c1=t2.c1;
# 'order by 1' should be considered as in 'select * from v1 order 1'
update v1 set t1c1=2 order by 1;
update v1 set t1c1=2 limit 1;
diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result
index 900348d..ed385f8 100644
--- a/mysql-test/suite/json/r/json_table.result
+++ b/mysql-test/suite/json/r/json_table.result
@@ -1146,3 +1146,104 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
#
# End of 10.9 tests
#
+#
+# MDEV-29390: Improve coverage for UPDATE and DELETE statements in MTR test suites
+#
+# Multi-update with JSON_TABLE
+create table t1 ( name varchar(10),
+color varchar(10),
+price decimal(8,2),
+instock BOOLEAN);
+insert into t1 values ("Laptop", "black", 20000, 1);
+insert into t1 values ("Jacket", "brown", 5000, 1);
+insert into t1 values ("Jeans", "blue", 5000, 1);
+select * from t1;
+name color price instock
+Laptop black 20000.00 1
+Jacket brown 5000.00 1
+Jeans blue 5000.00 1
+set @json='
+[
+ {"name":"Laptop", "color":"black", "price":"1000", "ordered":"3"},
+ {"name":"Jeans", "color":"blue", "ordered":"0"},
+ {"name":"Phone", "color":"red", "ordered":"0"}
+]';
+select * from json_table(@json, '$[*]'
+columns(
+name varchar(10) path '$.name',
+color varchar(10) path '$.color',
+price decimal(8,2) path '$.price',
+ordered boolean path '$.ordered' )
+) as jt;
+name color price ordered
+Laptop black 1000.00 3
+Jeans blue NULL 0
+Phone red NULL 0
+explain update t1, JSON_TABLE(@json,'$[*]'
+COLUMNS (
+name varchar(10) path '$.name',
+color varchar(10) path '$.color',
+price decimal(8,2) path '$.price',
+ordered boolean path '$.ordered'
+ )) AS jt1
+SET t1.instock=0 where t1.name=jt1.name and jt1.ordered=3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3
+1 SIMPLE jt1 ALL NULL NULL NULL NULL 40 Table function: json_table; Using where
+update t1, JSON_TABLE(@json,'$[*]'
+COLUMNS (
+name varchar(10) path '$.name',
+color varchar(10) path '$.color',
+price decimal(8,2) path '$.price',
+ordered boolean path '$.ordered'
+ )) AS jt1
+SET t1.instock=0 where t1.name=jt1.name and jt1.ordered=2;
+select * from t1;
+name color price instock
+Laptop black 20000.00 1
+Jacket brown 5000.00 1
+Jeans blue 5000.00 1
+explain update t1
+SET t1.instock=2 where t1.name in (
+select jt1.name from json_table(@json, '$[*]'
+columns(
+name varchar(10) path '$.name',
+color varchar(10) path '$.color',
+price decimal(8,2) path '$.price',
+ordered boolean path '$.ordered' )
+) as jt1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY jt1 ALL NULL NULL NULL NULL 40 Table function: json_table; Using where; FirstMatch(t1)
+update t1
+SET t1.instock=2 where t1.name in (
+select jt1.name from json_table(@json, '$[*]'
+columns(
+name varchar(10) path '$.name',
+color varchar(10) path '$.color',
+price decimal(8,2) path '$.price',
+ordered boolean path '$.ordered' )
+) as jt1);
+select * from t1;
+name color price instock
+Laptop black 20000.00 2
+Jacket brown 5000.00 1
+Jeans blue 5000.00 2
+update t1, JSON_TABLE(@json,'$[*]'
+COLUMNS (
+name varchar(10) path '$.name',
+color varchar(10) path '$.color',
+price decimal(8,2) path '$.price',
+ordered boolean path '$.ordered'
+ )) AS jt1
+SET t1.instock=0, jt1.ordered=1 where t1.name=jt1.name;
+ERROR HY000: The target table jt1 of the UPDATE is not updatable
+select * from t1;
+name color price instock
+Laptop black 20000.00 2
+Jacket brown 5000.00 1
+Jeans blue 5000.00 2
+drop table t1;
+#
+# End of 11.0 tests
+#
diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test
index 982922f..5a8fe98 100644
--- a/mysql-test/suite/json/t/json_table.test
+++ b/mysql-test/suite/json/t/json_table.test
@@ -997,3 +997,97 @@ COLUMNS
--echo #
--echo # End of 10.9 tests
--echo #
+
+--echo #
+--echo # MDEV-29390: Improve coverage for UPDATE and DELETE statements in MTR test suites
+--echo #
+
+--echo # Multi-update with JSON_TABLE
+
+create table t1 ( name varchar(10),
+ color varchar(10),
+ price decimal(8,2),
+ instock BOOLEAN);
+
+insert into t1 values ("Laptop", "black", 20000, 1);
+insert into t1 values ("Jacket", "brown", 5000, 1);
+insert into t1 values ("Jeans", "blue", 5000, 1);
+
+select * from t1;
+
+set @json='
+[
+ {"name":"Laptop", "color":"black", "price":"1000", "ordered":"3"},
+ {"name":"Jeans", "color":"blue", "ordered":"0"},
+ {"name":"Phone", "color":"red", "ordered":"0"}
+]';
+
+select * from json_table(@json, '$[*]'
+ columns(
+ name varchar(10) path '$.name',
+ color varchar(10) path '$.color',
+ price decimal(8,2) path '$.price',
+ ordered boolean path '$.ordered' )
+) as jt;
+
+explain update t1, JSON_TABLE(@json,'$[*]'
+ COLUMNS (
+ name varchar(10) path '$.name',
+ color varchar(10) path '$.color',
+ price decimal(8,2) path '$.price',
+ ordered boolean path '$.ordered'
+ )) AS jt1
+ SET t1.instock=0 where t1.name=jt1.name and jt1.ordered=3;
+
+update t1, JSON_TABLE(@json,'$[*]'
+ COLUMNS (
+ name varchar(10) path '$.name',
+ color varchar(10) path '$.color',
+ price decimal(8,2) path '$.price',
+ ordered boolean path '$.ordered'
+ )) AS jt1
+ SET t1.instock=0 where t1.name=jt1.name and jt1.ordered=2;
+
+select * from t1;
+
+explain update t1
+ SET t1.instock=2 where t1.name in (
+ select jt1.name from json_table(@json, '$[*]'
+ columns(
+ name varchar(10) path '$.name',
+ color varchar(10) path '$.color',
+ price decimal(8,2) path '$.price',
+ ordered boolean path '$.ordered' )
+ ) as jt1);
+
+
+update t1
+ SET t1.instock=2 where t1.name in (
+ select jt1.name from json_table(@json, '$[*]'
+ columns(
+ name varchar(10) path '$.name',
+ color varchar(10) path '$.color',
+ price decimal(8,2) path '$.price',
+ ordered boolean path '$.ordered' )
+ ) as jt1);
+
+select * from t1;
+
+
+-- error ER_NON_UPDATABLE_TABLE
+update t1, JSON_TABLE(@json,'$[*]'
+ COLUMNS (
+ name varchar(10) path '$.name',
+ color varchar(10) path '$.color',
+ price decimal(8,2) path '$.price',
+ ordered boolean path '$.ordered'
+ )) AS jt1
+ SET t1.instock=0, jt1.ordered=1 where t1.name=jt1.name;
+
+select * from t1;
+
+drop table t1;
+
+--echo #
+--echo # End of 11.0 tests
+--echo #
diff --git a/storage/connect/mysql-test/connect/r/upd.result b/storage/connect/mysql-test/connect/r/upd.result
index 8faf0089..ad17f0f 100644
--- a/storage/connect/mysql-test/connect/r/upd.result
+++ b/storage/connect/mysql-test/connect/r/upd.result
@@ -1627,3 +1627,159 @@ serialno name sex title manager department secretary salary
DROP PROCEDURE test.tst_up;
DROP TABLE employee;
SET sql_mode = DEFAULT;
+#
+# End of 10.10 tests
+#
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+CREATE TABLE t1
+(
+name char(12) not null,
+city char(11) not null,
+birth date not null date_format='DD/MM/YYYY',
+hired date not null date_format='DD/MM/YYYY' flag=36
+) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='boys.txt' ENDING=1;
+CREATE TABLE t2 (
+_id INT(2) NOT NULL,
+name_first CHAR(9) NOT NULL JPATH='$.name.first',
+name_aka CHAR(4) DEFAULT NULL JPATH='$.name.aka',
+name_last CHAR(10) NOT NULL JPATH='$.name.last',
+title CHAR(12) DEFAULT NULL,
+birth CHAR(20) DEFAULT NULL,
+death CHAR(20) DEFAULT NULL,
+contribs CHAR(50) NOT NULL JPATH='$.contribs',
+awards_award CHAR(42) DEFAULT NULL JPATH='$.awards.award',
+awards_year CHAR(4) DEFAULT NULL JPATH='$.awards.year',
+awards_by CHAR(38) DEFAULT NULL JPATH='$.awards.by'
+) ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bios.json';
+# Multi-update
+select t1.name, t1.city from t1;
+name city
+John Boston
+Henry Boston
+George San Jose
+Sam Chicago
+James Dallas
+Bill Boston
+select t2._id, t2.name_first, t2.name_aka, t2.name_last from t2;
+_id name_first name_aka name_last
+1 John NULL Backus
+2 John NULL McCarthy
+3 Grace NULL Hopper
+4 Kristen NULL Nygaard
+5 Ole-Johan NULL Dahl
+6 Guido NULL van Rossum
+7 Dennis NULL Ritchie
+8 Yukihiro Matz Matsumoto
+9 James NULL Gosling
+10 Martin NULL Odersky
+select t1.name, t2.name_last, t2.name_aka, t1.city from t1, t2 where t1.name=t2.name_first and t1.birth
+BETWEEN '1992-01-01' and '1995-01-01';
+name name_last name_aka city
+James Gosling NULL Dallas
+explain update t1, t2
+set t1.city='Washington', t2.name_aka='von' where t1.name=t2.name_first and t1.birth
+BETWEEN '1992-01-01' and '1995-01-01';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using where
+1 SIMPLE t2 ALL NULL NULL NULL NULL 10 Using where
+update t1, t2
+set t1.city='Washington', t2.name_aka='von' where t1.name=t2.name_first and t1.birth
+BETWEEN '1992-01-01' and '1995-01-01';
+select t1.name, t2.name_last, t2.name_aka, t1.city from t1, t2 where t1.name=t2.name_first and t1.birth
+BETWEEN '1992-01-01' and '1995-01-01';
+name name_last name_aka city
+James Gosling von Washington
+# Conversion to multi-update
+select t1.name, t1.city from t1;
+name city
+John Boston
+Henry Boston
+George San Jose
+Sam Chicago
+James Washington
+Bill Boston
+explain update t1
+set t1.city='New York' where t1.name in (select t2.name_first from t2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 6
+1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where; FirstMatch(t1)
+update t1
+set t1.city='New York' where t1.name in (select t2.name_first from t2);
+select t1.name, t1.city from t1;
+name city
+John New York
+Henry Boston
+George San Jose
+Sam Chicago
+James New York
+Bill Boston
+select t1.name, t1.city from t1 where t1.name in (select a.name from t1 as a where a.birth
+BETWEEN '1981-01-01' and '1982-01-01');
+name city
+George San Jose
+explain update t1 set t1.city='Los Angeles' where t1.name in (select a.name from t1 as a where a.birth
+BETWEEN '1981-01-01' and '1982-01-01');
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 6
+1 PRIMARY a ALL NULL NULL NULL NULL 6 Using where; FirstMatch(t1)
+update t1 set t1.city='Los Angeles' where t1.name in (select a.name from t1 as a where a.birth
+BETWEEN '1981-01-01' and '1982-01-01');
+select t1.name, t1.city from t1 where t1.name in (select a.name from t1 as a where a.birth
+BETWEEN '1981-01-01' and '1982-01-01');
+name city
+George Los Angeles
+# Multi-delete
+explain delete t1.*, t2.* from t1, t2 where t1.name=t2.name_first and t1.birth
+BETWEEN '1992-01-01' and '1995-01-01';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using where
+1 SIMPLE t2 ALL NULL NULL NULL NULL 10 Using where
+delete t1.*, t2.* from t1, t2 where t1.name=t2.name_first and t1.birth
+BETWEEN '1992-01-01' and '1995-01-01';
+select t1.name, t1.city from t1;
+name city
+John New York
+Henry Boston
+George Los Angeles
+Sam Chicago
+Bill Boston
+select t2._id, t2.name_first, t2.name_aka, t2.name_last from t2;
+_id name_first name_aka name_last
+1 John NULL Backus
+2 John NULL McCarthy
+3 Grace NULL Hopper
+4 Kristen NULL Nygaard
+5 Ole-Johan NULL Dahl
+6 Guido NULL van Rossum
+7 Dennis NULL Ritchie
+8 Yukihiro Matz Matsumoto
+10 Martin NULL Odersky
+# Conversion to multi-delete
+explain delete from t1 where t1.name in (select t2.name_first from t2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5
+1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where; FirstMatch(t1)
+delete from t1 where t1.name in (select t2.name_first from t2);
+select t1.name, t1.city from t1;
+name city
+Henry Boston
+George Los Angeles
+Sam Chicago
+Bill Boston
+explain delete from t1 where t1.name in (select a.name from t1 as a where a.birth
+BETWEEN '1981-01-01' and '1982-01-01');
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY a ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1)
+delete from t1 where t1.name in (select a.name from t1 as a where a.birth
+BETWEEN '1981-01-01' and '1982-01-01');
+select t1.name, t1.city from t1;
+name city
+Henry Boston
+Sam Chicago
+Bill Boston
+drop tables t1, t2;
+SET sql_mode = DEFAULT;
+#
+# End of 11.0 tests
+#
diff --git a/storage/connect/mysql-test/connect/t/upd.test b/storage/connect/mysql-test/connect/t/upd.test
index 28b566b..0372a9a 100644
--- a/storage/connect/mysql-test/connect/t/upd.test
+++ b/storage/connect/mysql-test/connect/t/upd.test
@@ -155,3 +155,99 @@ DROP TABLE employee;
SET sql_mode = DEFAULT;
--remove_file $MYSQLD_DATADIR/test/employee.dat
+
+--echo #
+--echo # End of 10.10 tests
+--echo #
+
+--copy_file $MTR_SUITE_DIR/std_data/boys.txt $MYSQLD_DATADIR/test/boys.txt
+--copy_file $MTR_SUITE_DIR/std_data/bios.json $MYSQLD_DATADIR/test/bios.json
+
+SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
+
+CREATE TABLE t1
+(
+ name char(12) not null,
+ city char(11) not null,
+ birth date not null date_format='DD/MM/YYYY',
+ hired date not null date_format='DD/MM/YYYY' flag=36
+) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='boys.txt' ENDING=1;
+
+CREATE TABLE t2 (
+ _id INT(2) NOT NULL,
+ name_first CHAR(9) NOT NULL JPATH='$.name.first',
+ name_aka CHAR(4) DEFAULT NULL JPATH='$.name.aka',
+ name_last CHAR(10) NOT NULL JPATH='$.name.last',
+ title CHAR(12) DEFAULT NULL,
+ birth CHAR(20) DEFAULT NULL,
+ death CHAR(20) DEFAULT NULL,
+ contribs CHAR(50) NOT NULL JPATH='$.contribs',
+ awards_award CHAR(42) DEFAULT NULL JPATH='$.awards.award',
+ awards_year CHAR(4) DEFAULT NULL JPATH='$.awards.year',
+ awards_by CHAR(38) DEFAULT NULL JPATH='$.awards.by'
+) ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bios.json';
+
+--echo # Multi-update
+
+select t1.name, t1.city from t1;
+select t2._id, t2.name_first, t2.name_aka, t2.name_last from t2;
+
+let $c1 = where t1.name=t2.name_first and t1.birth
+ BETWEEN '1992-01-01' and '1995-01-01';
+
+eval select t1.name, t2.name_last, t2.name_aka, t1.city from t1, t2 $c1;
+eval explain update t1, t2
+ set t1.city='Washington', t2.name_aka='von' $c1;
+eval update t1, t2
+ set t1.city='Washington', t2.name_aka='von' $c1;
+eval select t1.name, t2.name_last, t2.name_aka, t1.city from t1, t2 $c1;
+
+--echo # Conversion to multi-update
+
+let $c2 = where t1.name in (select t2.name_first from t2);
+
+select t1.name, t1.city from t1;
+eval explain update t1
+ set t1.city='New York' $c2;
+eval update t1
+ set t1.city='New York' $c2;
+select t1.name, t1.city from t1;
+
+let $c3 = where t1.name in (select a.name from t1 as a where a.birth
+ BETWEEN '1981-01-01' and '1982-01-01');
+
+eval select t1.name, t1.city from t1 $c3;
+eval explain update t1 set t1.city='Los Angeles' $c3;
+eval update t1 set t1.city='Los Angeles' $c3;
+eval select t1.name, t1.city from t1 $c3;
+
+--echo # Multi-delete
+
+eval explain delete t1.*, t2.* from t1, t2 $c1;
+eval delete t1.*, t2.* from t1, t2 $c1;
+
+select t1.name, t1.city from t1;
+select t2._id, t2.name_first, t2.name_aka, t2.name_last from t2;
+
+--echo # Conversion to multi-delete
+
+eval explain delete from t1 $c2;
+eval delete from t1 $c2;
+
+select t1.name, t1.city from t1;
+
+eval explain delete from t1 $c3;
+eval delete from t1 $c3;
+
+select t1.name, t1.city from t1;
+
+drop tables t1, t2;
+
+SET sql_mode = DEFAULT;
+
+--remove_file $MYSQLD_DATADIR/test/boys.txt
+--remove_file $MYSQLD_DATADIR/test/bios.json
+
+--echo #
+--echo # End of 11.0 tests
+--echo #
1
0
[Commits] 70bfa51: MDEV-30539 EXPLAIN EXTENDED: no message with query for DML statements
by IgorBabaev 14 Mar '23
by IgorBabaev 14 Mar '23
14 Mar '23
revision-id: 70bfa51d7e5096ea6bac5ac7971427875ca4bc89 (mariadb-10.4.27-113-g70bfa51)
parent(s): ccec9b1de95a66b7597bc30e0a60bd61866f225d
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-14 12:59:33 -0700
message:
MDEV-30539 EXPLAIN EXTENDED: no message with query for DML statements
Preliminary patch.
---
mysql-test/main/explain_non_select.result | 4 +
mysql-test/main/multi_update.result | 2 +-
mysql-test/main/multi_update.test | 2 +-
.../main/myisam_explain_non_select_all.result | 138 +++++++++
mysql-test/main/opt_trace.result | 2 +-
mysql-test/main/ps.result | 4 +
sql/sql_delete.cc | 2 +
sql/sql_explain.cc | 19 +-
sql/sql_explain.h | 2 +-
sql/sql_insert.cc | 6 +-
sql/sql_lex.cc | 2 +
sql/sql_lex.h | 6 +
sql/sql_parse.cc | 20 +-
sql/sql_select.cc | 326 ++++++++++++++++++---
sql/sql_update.cc | 10 +-
sql/table.h | 2 +
16 files changed, 490 insertions(+), 57 deletions(-)
diff --git a/mysql-test/main/explain_non_select.result b/mysql-test/main/explain_non_select.result
index 111b4c8..d60f10f 100644
--- a/mysql-test/main/explain_non_select.result
+++ b/mysql-test/main/explain_non_select.result
@@ -157,9 +157,13 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
explain extended update t2 set b=3 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`b` = 3 where `test`.`t2`.`a` in (3,4)
explain extended delete from t2 where a in (3,4);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`a` in (3,4)
drop table t1,t2;
#
# Check the special case where partition pruning removed all partitions
diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result
index d6cf9ba..222c592 100644
--- a/mysql-test/main/multi_update.result
+++ b/mysql-test/main/multi_update.result
@@ -1253,7 +1253,7 @@ EXPLAIN
DROP TABLES t1, t2;
# End of 10.3 tests
#
-# MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in
+# MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
#
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
insert into t1 values
diff --git a/mysql-test/main/multi_update.test b/mysql-test/main/multi_update.test
index 48e6250..329394e 100644
--- a/mysql-test/main/multi_update.test
+++ b/mysql-test/main/multi_update.test
@@ -1134,7 +1134,7 @@ DROP TABLES t1, t2;
--echo # End of 10.3 tests
--echo #
---echo # MDEV-28538: multi-table UPDATE/DELETE with possible exists-to-in
+--echo # MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
--echo #
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 7f24cb4..6681a9d 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -17,6 +17,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` < 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -60,6 +62,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -103,6 +107,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE a = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t1` where `test`.`t1`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -150,6 +156,8 @@ EXPLAIN EXTENDED UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 update `test`.`t1` join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t1`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -200,6 +208,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` = 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -248,6 +258,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(1,<exists>(/* select#2 */ select 1 from `test`.`t2` where `test`.`t2`.`b` < 3 and 1))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -300,6 +312,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`b` from `test`.`t2` where `test`.`t1`.`a` < 3 and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -353,6 +366,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` set `test`.`t1`.`a` = 10 where `test`.`t2`.`b` < 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -405,6 +420,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -457,6 +474,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` set `test`.`t11`.`a` = `test`.`t11`.`a` + 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -511,6 +530,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` `t11` join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` set `test`.`t11`.`a` = 10 where `test`.`t11`.`a` > 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -555,6 +576,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a > 1 LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 1 limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -598,6 +621,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` where 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -638,6 +663,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t1` where 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -678,6 +705,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a = 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` = 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 5
@@ -719,6 +748,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` < 3
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 5
@@ -758,6 +789,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -797,6 +830,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`a` > 0 order by `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -840,6 +875,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where @a:=`test`.`t1`.`a` order by `test`.`t1`.`a` limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -884,6 +921,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -941,6 +980,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 100.00
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1`,`test`.`t2`,`test`.`t3` using `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a2` = `test`.`t1`.`a1` and `test`.`t3`.`a3` = `test`.`t2`.`b2` and `test`.`t3`.`b3` = `test`.`t1`.`b1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 13
@@ -993,6 +1034,8 @@ EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where <cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1043,6 +1086,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1088,6 +1133,8 @@ EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(/* select#2 */ select `test`.`t2`.`a2` from `test`.`t2` where `test`.`t2`.`a2` > 2 and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1132,6 +1179,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`i` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -1175,6 +1224,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL 5 NULL Deleting all rows
+Warnings:
+Note 1003 delete from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -1221,6 +1272,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1267,6 +1320,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 insert into `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1311,6 +1366,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 replaceinto `test`.`t2` select `test`.`t1`.`i` AS `i` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1351,6 +1408,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1`(i) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -1374,6 +1433,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 replaceinto `test`.`t1`(i) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -1402,6 +1463,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1447,6 +1510,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`i` > 10 and `test`.`t1`.`i` <= 18 order by `test`.`t1`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1500,6 +1565,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1554,6 +1621,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1603,6 +1672,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1657,6 +1728,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1712,6 +1785,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1765,6 +1840,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where
+Warnings:
+Note 1003 delete from `test`.`t2` where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1812,6 +1889,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort
+Warnings:
+Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1866,6 +1945,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 6 NULL 5 100.00
+Warnings:
+Note 1003 delete from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -1915,6 +1996,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -1963,6 +2046,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -2017,6 +2102,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2072,6 +2159,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2122,6 +2211,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2176,6 +2267,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`d` = 10 where `test`.`t2`.`b` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2231,6 +2324,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`i` = 123 where `test`.`t2`.`key1` < 13 or `test`.`t2`.`key2` < 14 order by `test`.`t2`.`key1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2284,6 +2379,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 5 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`a` = 10 where `test`.`t2`.`i` > 10 and `test`.`t2`.`i` <= 18 order by `test`.`t2`.`i` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -2332,6 +2429,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2387,6 +2486,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 index NULL a 6 NULL 5 100.00 Using buffer
+Warnings:
+Note 1003 update `test`.`t2` set `test`.`t2`.`c` = 10 order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2439,6 +2540,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`c2` = 0 where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2485,6 +2588,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort
+Warnings:
+Note 1003 delete from `test`.`t1` where `test`.`t1`.`c1_idx` = 'y' order by `test`.`t1`.`pk` desc limit 2
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2534,6 +2639,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 10 where `test`.`t1`.`a` > 34
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -2581,6 +2688,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` set NULL = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2624,6 +2733,8 @@ EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 W
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 Const row not found
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+Warnings:
+Note 1003 update `test`.`t1` set NULL = 10 where `test`.`t1`.`c3` = 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2676,6 +2787,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`f2` = (/* select#2 */ select max(`test`.`t2`.`f4`) from `test`.`t2` where `test`.`t2`.`f3` = `test`.`t1`.`f1`)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 7
@@ -2747,6 +2859,8 @@ EXPLAIN EXTENDED UPDATE v1 SET a = 1 WHERE a > 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` > 0
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -2792,6 +2906,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 update `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` set `test`.`t11`.`a` = 1 where `test`.`t11`.`a` = `test`.`t1`.`a`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -2841,6 +2957,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM v1 WHERE a < 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 /* select#1 */ delete from `test`.`t1` where `test`.`t1`.`a` < 4
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -2892,6 +3010,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2943,6 +3063,8 @@ EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00
+Warnings:
+Note 1003 delete from `test`.`t1` using `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`x`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 6
@@ -2987,6 +3109,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL
+Warnings:
+Note 1003 insert into `test`.`t1`(x) values (10)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 2
@@ -3027,6 +3151,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 0 0.00 Const row not found
+Warnings:
+Note 1003 insert into `test`.`t2`(x) /* select#1 */ select NULL AS `a` from `test`.`t1`
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3084,6 +3210,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` set `test`.`t1`.`a` = 10 where <in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0)))
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3140,6 +3268,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#3 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` set `test`.`t1`.`a` = 10 where 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3198,6 +3328,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 3 100.00
4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t1` semi join ((/* select#4 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join (/* select#2 */ select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` set `test`.`t1`.`a` = 10 where 1
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -3248,6 +3380,8 @@ JOIN t1 AS a12 ON a12.c1 = a11.c1
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
DROP TABLE t1, t2, t3;
#73
CREATE TABLE t1 (id INT);
@@ -3276,6 +3410,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using buffer
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -3315,6 +3451,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using filesort
+Warnings:
+Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1 where `test`.`t1`.`a` > 10 order by `test`.`t1`.`a` + 20
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index a343d59..a8b391f 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -3766,7 +3766,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"select_id": 1,
"steps": [
{
- "expanded_query": "select NULL AS `NULL` from t0 join t1 where t0.a = t1.a and t1.a < 3"
+ "expanded_query": "delete from t0,t1 using t0 join t1 where t0.a = t1.a and t1.a < 3"
}
]
}
diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result
index 673b18c..408b1ec 100644
--- a/mysql-test/main/ps.result
+++ b/mysql-test/main/ps.result
@@ -5566,11 +5566,15 @@ EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 F
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 )";
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1003 /* select#1 */ update `test`.`t3` set `test`.`t3`.`c3` = (/* select#2 */ select count(NULL) from `test`.`t1` `a11` straight_join `test`.`t2` `a21` join `test`.`t1` `a12` where 0)
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2, t3;
#
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1b3fa30..776dfff 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1084,6 +1084,8 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
select_lex->fix_prepare_information(thd, conds, &fake_conds);
+ if (!thd->lex->upd_del_where)
+ thd->lex->upd_del_where= *conds;
DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 70e3009..6b76db8 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -161,7 +161,7 @@ void Explain_query::query_plan_ready()
Send EXPLAIN output to the client.
*/
-int Explain_query::send_explain(THD *thd)
+int Explain_query::send_explain(THD *thd, bool extended)
{
select_result *result;
LEX *lex= thd->lex;
@@ -174,8 +174,22 @@ int Explain_query::send_explain(THD *thd)
if (thd->lex->explain_json)
print_explain_json(result, thd->lex->analyze_stmt);
else
+ {
res= print_explain(result, lex->describe, thd->lex->analyze_stmt);
-
+ if (extended)
+ {
+ char buff[1024];
+ String str(buff,(uint32) sizeof(buff), system_charset_info);
+ str.length(0);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ lex->unit.print(&str, QT_EXPLAIN_EXTENDED);
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str.c_ptr_safe());
+ }
+ }
if (res)
result->abort_result_set();
else
@@ -185,6 +199,7 @@ int Explain_query::send_explain(THD *thd)
}
+
/*
The main entry point to print EXPLAIN of the entire query
*/
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 7b5042b..3add404 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -474,7 +474,7 @@ class Explain_query : public Sql_alloc
bool is_analyze);
/* Send tabular EXPLAIN to the client */
- int send_explain(THD *thd);
+ int send_explain(THD *thd, bool extended);
/* Return tabular EXPLAIN output as a text string */
bool print_explain_str(THD *thd, String *out_str, bool is_analyze);
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index f31c9ea..9a76061 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -827,7 +827,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
save_insert_query_plan(thd, table_list);
if (thd->lex->describe)
{
- retval= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ retval= thd->lex->explain->send_explain(thd, extended);
goto abort;
}
@@ -1250,7 +1251,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
goto abort;
if (thd->lex->analyze_stmt)
{
- retval= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ retval= thd->lex->explain->send_explain(thd, extended);
goto abort;
}
DBUG_PRINT("info", ("touched: %llu copied: %llu updated: %llu deleted: %llu",
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index e14d9f7..e7689a9 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -780,6 +780,8 @@ void LEX::start(THD *thd_arg)
frame_bottom_bound= NULL;
win_spec= NULL;
+ upd_del_where= NULL;
+
vers_conditions.empty();
period_conditions.empty();
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 769b1750..6170637 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1417,6 +1417,10 @@ class st_select_lex: public st_select_lex_node
}
bool setup_ref_array(THD *thd, uint order_group_num);
void print(THD *thd, String *str, enum_query_type query_type);
+ void print_item_list(THD *thd, String *str, enum_query_type query_type);
+ void print_set_clause(THD *thd, String *str, enum_query_type query_type);
+ void print_on_duplicate_key_clause(THD *thd, String *str,
+ enum_query_type query_type);
static void print_order(String *str,
ORDER *order,
enum_query_type query_type);
@@ -3493,6 +3497,8 @@ struct LEX: public Query_tables_list
Window_frame_bound *frame_bottom_bound;
Window_spec *win_spec;
+ Item *upd_del_where;
+
/* System Versioning */
vers_select_conds_t vers_conditions;
vers_select_conds_t period_conditions;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 1f1962a..c495ae2 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4744,7 +4744,10 @@ mysql_execute_command(THD *thd)
}
if (!res && (explain || lex->analyze_stmt))
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
/* revert changes for SP */
MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func());
@@ -4813,7 +4816,10 @@ mysql_execute_command(THD *thd)
if (thd->lex->analyze_stmt || thd->lex->describe)
{
if (!res)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
delete sel_result;
@@ -4875,7 +4881,10 @@ mysql_execute_command(THD *thd)
else
{
if (lex->describe || lex->analyze_stmt)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
multi_delete_error:
delete result;
@@ -6463,7 +6472,10 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
thd->protocol= save_protocol;
}
if (!res)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
}
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2c12d1c..7fabb1c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -305,6 +305,9 @@ static Item **get_sargable_cond(JOIN *join, TABLE *table);
bool is_eq_cond_injected_for_split_opt(Item_func_eq *eq_item);
+void print_list_item(String *str, List_item *list,
+ enum_query_type query_type);
+
#ifndef DBUG_OFF
/*
@@ -27981,6 +27984,162 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str,
}
}
+enum explainable_cmd_type
+{
+ SELECT_CMD, INSERT_CMD, REPLACE_CMD, UPDATE_CMD, DELETE_CMD, NO_CMD
+};
+
+static
+const char * const explainable_cmd_name []=
+{
+ "select ",
+ "insert ",
+ "replace ",
+ "update ",
+ "delete ",
+};
+
+static
+char const *get_explainable_cmd_name(enum explainable_cmd_type cmd)
+{
+ return explainable_cmd_name[cmd];
+}
+
+static
+enum explainable_cmd_type get_explainable_cmd_type(THD *thd)
+{
+ switch (thd->lex->sql_command) {
+ case SQLCOM_SELECT:
+ return SELECT_CMD;
+ case SQLCOM_INSERT:
+ case SQLCOM_INSERT_SELECT:
+ return INSERT_CMD;
+ case SQLCOM_REPLACE:
+ case SQLCOM_REPLACE_SELECT:
+ return REPLACE_CMD;
+ case SQLCOM_UPDATE:
+ case SQLCOM_UPDATE_MULTI:
+ return UPDATE_CMD;
+ case SQLCOM_DELETE:
+ case SQLCOM_DELETE_MULTI:
+ return DELETE_CMD;
+ default:
+ return SELECT_CMD;
+ }
+}
+
+
+void TABLE_LIST::print_leaf_tables(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ if (merge_underlying_list)
+ {
+ for (TABLE_LIST *tbl= merge_underlying_list; tbl; tbl= tbl->next_local)
+ tbl->print_leaf_tables(thd, str, query_type);
+ }
+ else
+ print(thd, 0, str, query_type);
+}
+
+
+void st_select_lex::print_item_list(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ bool top_level= (get_master()->get_master() == 0);
+ List_iterator_fast<Item> it(item_list);
+ Item *item;
+ while ((item= it++))
+ {
+ if (first)
+ first= 0;
+ else
+ str->append(',');
+
+ if ((is_subquery_function() && item->is_autogenerated_name) ||
+ !item->name.str)
+ {
+ /*
+ Do not print auto-generated aliases in subqueries. It has no purpose
+ in a view definition or other contexts where the query is printed.
+ */
+ item->print(str, query_type);
+ }
+ else
+ {
+ /*
+ Do not print illegal names (if it is not top level SELECT).
+ Top level view checked (and correct name are assigned),
+ other cases of top level SELECT are not important, because
+ it is not "table field".
+ */
+ if (top_level ||
+ !item->is_autogenerated_name ||
+ !check_column_name(item->name.str))
+ item->print_item_w_name(str, query_type);
+ else
+ item->print(str, query_type);
+ }
+ }
+}
+
+
+void st_select_lex::print_set_clause(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ /*
+ outer_select() can not be used here because it is for name resolution
+ and will return NULL at any end of name resolution chain (view/derived)
+ */
+ List_iterator_fast<Item> it(item_list);
+ List_iterator_fast<Item> vt(thd->lex->value_list);
+ Item *item;
+ Item *val;
+ while ((item= it++, val= vt++ ))
+ {
+ if (first)
+ {
+ str->append(STRING_WITH_LEN(" set "));
+ first= 0;
+ }
+ else
+ str->append(',');
+
+ item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" = "));
+ val->print(str, query_type);
+ }
+}
+
+
+void st_select_lex::print_on_duplicate_key_clause(THD *thd, String *str,
+ enum_query_type query_type)
+{
+ bool first= 1;
+ List_iterator_fast<Item> it(thd->lex->update_list);
+ List_iterator_fast<Item> vt(thd->lex->value_list);
+ Item *item;
+ Item *val;
+ while ((item= it++, val= vt++ ))
+ {
+ if (first)
+ {
+ str->append(STRING_WITH_LEN(" on duplicate key update "));
+ first= 0;
+ }
+ else
+ str->append(',');
+
+ item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" = "));
+ val->print(str, query_type);
+ }
+}
void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
{
@@ -27998,6 +28157,61 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
return;
}
+ bool top_level= (get_master()->get_master() == 0);
+ enum explainable_cmd_type sel_type= SELECT_CMD;
+ if (top_level)
+ sel_type= get_explainable_cmd_type(thd);
+
+ if (sel_type == INSERT_CMD || sel_type == REPLACE_CMD)
+ {
+ str->append(STRING_WITH_LEN(get_explainable_cmd_name(sel_type)));
+ str->append(STRING_WITH_LEN("into "));
+ TABLE_LIST *tbl= thd->lex->query_tables;
+ while (tbl->merge_underlying_list)
+ tbl= tbl->merge_underlying_list;
+ tbl->print(thd, 0, str, query_type);
+ if (thd->lex->field_list.elements)
+ {
+ str->append ('(');
+ List_iterator_fast<Item> it(thd->lex->field_list);
+ Item *item;
+ bool first= true;
+ while ((item= it++))
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ str->append(item->name);
+ }
+ str->append(')');
+ }
+
+ str->append(' ');
+
+ if (thd->lex->sql_command == SQLCOM_INSERT ||
+ thd->lex->sql_command == SQLCOM_REPLACE)
+ {
+ str->append(STRING_WITH_LEN("values "));
+ bool is_first_elem= true;
+ List_iterator_fast<List_item> li(thd->lex->many_values);
+ List_item *list;
+
+ while ((list= li++))
+ {
+ if (is_first_elem)
+ is_first_elem= false;
+ else
+ str->append(',');
+
+ print_list_item(str, list, query_type);
+ }
+ if (thd->lex->update_list.elements)
+ print_on_duplicate_key_clause(thd, str, query_type);
+ return;
+ }
+ }
+
if ((query_type & QT_SHOW_SELECT_NUMBER) &&
thd->lex->all_selects_list &&
thd->lex->all_selects_list->link_next &&
@@ -28021,7 +28235,10 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
str->append(" */ ");
}
- str->append(STRING_WITH_LEN("select "));
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
+ str->append(STRING_WITH_LEN("select "));
if (join && join->cleaned)
{
@@ -28067,57 +28284,66 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
}
//Item List
- bool first= 1;
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
+ print_item_list(thd, str, query_type);
/*
- outer_select() can not be used here because it is for name resolution
- and will return NULL at any end of name resolution chain (view/derived)
+ from clause
+ TODO: support USING/FORCE/IGNORE index
*/
- bool top_level= (get_master()->get_master() == 0);
- List_iterator_fast<Item> it(item_list);
- Item *item;
- while ((item= it++))
+ if (table_list.elements)
{
- if (first)
- first= 0;
- else
- str->append(',');
-
- if ((is_subquery_function() && item->is_autogenerated_name) ||
- !item->name.str)
+ if (sel_type == SELECT_CMD ||
+ sel_type == INSERT_CMD ||
+ sel_type == REPLACE_CMD)
{
- /*
- Do not print auto-generated aliases in subqueries. It has no purpose
- in a view definition or other contexts where the query is printed.
- */
- item->print(str, query_type);
+ str->append(STRING_WITH_LEN(" from "));
+ /* go through join tree */
+ print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list,
+ query_type);
}
- else
+ if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ str->append(STRING_WITH_LEN(get_explainable_cmd_name(sel_type)));
+ if (sel_type == DELETE_CMD)
{
- /*
- Do not print illegal names (if it is not top level SELECT).
- Top level view checked (and correct name are assigned),
- other cases of top level SELECT are not important, because
- it is not "table field".
- */
- if (top_level ||
- !item->is_autogenerated_name ||
- !check_column_name(item->name.str))
- item->print_item_w_name(str, query_type);
+ str->append(STRING_WITH_LEN(" from "));
+ bool first= true;
+ for (TABLE_LIST *target_tbl= thd->lex->auxiliary_table_list.first;
+ target_tbl;
+ target_tbl= target_tbl->next_local)
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ target_tbl->correspondent_table->print_leaf_tables(thd, str,
+ query_type);
+ }
+
+ if (!first)
+ str->append(STRING_WITH_LEN(" using "));
+ }
+ if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ {
+ if (join)
+ print_join(thd, 0, str, &top_join_list, query_type);
else
- item->print(str, query_type);
+ {
+ bool first= true;
+ List_iterator_fast<TABLE_LIST> li(leaf_tables);
+ TABLE_LIST *tbl;
+ while ((tbl= li++))
+ {
+ if (first)
+ first= false;
+ else
+ str->append(',');
+ tbl->print(thd, 0, str, query_type);
+ }
+ }
}
}
-
- /*
- from clause
- TODO: support USING/FORCE/IGNORE index
- */
- if (table_list.elements)
- {
- str->append(STRING_WITH_LEN(" from "));
- /* go through join tree */
- print_join(thd, join? join->eliminated_tables: 0, str, &top_join_list, query_type);
- }
else if (where)
{
/*
@@ -28127,10 +28353,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
str->append(STRING_WITH_LEN(" from DUAL "));
}
+ if (sel_type == UPDATE_CMD)
+ print_set_clause(thd, str, query_type);
+
// Where
Item *cur_where= where;
if (join)
cur_where= join->conds;
+ else if (sel_type == UPDATE_CMD || sel_type == DELETE_CMD)
+ cur_where= thd->lex->upd_del_where;
if (cur_where || cond_value != Item::COND_UNDEF)
{
str->append(STRING_WITH_LEN(" where "));
@@ -28187,6 +28418,15 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
else if (lock_type == TL_WRITE)
str->append(" for update");
+ if ((sel_type == INSERT_CMD || sel_type == REPLACE_CMD) &&
+ thd->lex->update_list.elements)
+ print_on_duplicate_key_clause(thd, str, query_type);
+
+ // returning clause
+ if (sel_type == DELETE_CMD && !item_list.elements)
+ {
+ print_item_list(thd, str, query_type);
+ }
// PROCEDURE unsupported here
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index a298071..834fa61 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1371,7 +1371,8 @@ int mysql_update(THD *thd,
goto err;
emit_explain_and_leave:
- int err2= thd->lex->explain->send_explain(thd);
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ int err2= thd->lex->explain->send_explain(thd, extended);
delete select;
free_underlaid_joins(thd, select_lex);
@@ -1445,6 +1446,8 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
select_lex->fix_prepare_information(thd, conds, &fake_conds);
+ if (!thd->lex->upd_del_where)
+ thd->lex->upd_del_where= *conds;
DBUG_RETURN(FALSE);
}
@@ -1974,7 +1977,10 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, List<Item> *fields,
else
{
if (thd->lex->describe || thd->lex->analyze_stmt)
- res= thd->lex->explain->send_explain(thd);
+ {
+ bool extended= thd->lex->describe & DESCRIBE_EXTENDED;
+ res= thd->lex->explain->send_explain(thd, extended);
+ }
}
thd->abort_on_warning= 0;
DBUG_RETURN(res);
diff --git a/sql/table.h b/sql/table.h
index c4b0d78..6f7f4e6 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2708,6 +2708,8 @@ struct TABLE_LIST
}
void print(THD *thd, table_map eliminated_tables, String *str,
enum_query_type query_type);
+ void print_leaf_tables(THD *thd, String *str,
+ enum_query_type query_type);
bool check_single_table(TABLE_LIST **table, table_map map,
TABLE_LIST *view);
bool set_insert_values(MEM_ROOT *mem_root);
1
0
[Commits] e97560e: MDEV-28958 Crash when checking whether condition can be pushed into view
by IgorBabaev 14 Mar '23
by IgorBabaev 14 Mar '23
14 Mar '23
revision-id: e97560eac0321d43e98033f00fb0bd4f008bc9e9 (mariadb-10.8.6-38-ge97560e)
parent(s): 20d2c9038aa6e1582d9f76ba866b250438887208
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-14 11:05:36 -0700
message:
MDEV-28958 Crash when checking whether condition can be pushed into view
Do not set any flags in the items for constant subformulas TRUE/FALSE when
checking pushability of a formula into a view. Occurrences of these
subformulas can be ignored when checking pushability of the formula.
At the same time the items used for these constants became immutable
starting from version 10.7.
Approved by Oleksandr Byelkin <sanja(a)mariadb.com>
---
mysql-test/main/derived_cond_pushdown.result | 17 +++++++++++++++++
mysql-test/main/derived_cond_pushdown.test | 21 +++++++++++++++++++++
sql/item.h | 23 ++++++++++++++++-------
3 files changed, 54 insertions(+), 7 deletions(-)
diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result
index 8c936f3..4a00218 100644
--- a/mysql-test/main/derived_cond_pushdown.result
+++ b/mysql-test/main/derived_cond_pushdown.result
@@ -20697,3 +20697,20 @@ id select_type table type possible_keys key key_len ref rows Extra
drop view v1;
drop table t1;
# End of 10.4 tests
+#
+# MDEV-28958: condition pushable into view after simplification
+# contains constant TRUE/FALSE as subformula
+#
+create table t1 (c1 int);
+insert into t1 values (3), (7), (1), (3), (1), (3);
+create table t2 (c2 int);
+insert into t2 values (3), (5), (7), (3);
+create view v1 as select * from t1 group by c1;
+create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2;
+select * from v2 group by a,b having a=b or b > a+10;
+a b
+3 3
+7 7
+drop view v1,v2;
+drop table t1,t2;
+# End of 10.7 tests
diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test
index 17115c1..dc454bf 100644
--- a/mysql-test/main/derived_cond_pushdown.test
+++ b/mysql-test/main/derived_cond_pushdown.test
@@ -3944,3 +3944,24 @@ drop view v1;
drop table t1;
--echo # End of 10.4 tests
+
+--echo #
+--echo # MDEV-28958: condition pushable into view after simplification
+--echo # contains constant TRUE/FALSE as subformula
+--echo #
+
+create table t1 (c1 int);
+insert into t1 values (3), (7), (1), (3), (1), (3);
+
+create table t2 (c2 int);
+insert into t2 values (3), (5), (7), (3);
+
+create view v1 as select * from t1 group by c1;
+create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2;
+
+select * from v2 group by a,b having a=b or b > a+10;
+
+drop view v1,v2;
+drop table t1,t2;
+
+--echo # End of 10.7 tests
diff --git a/sql/item.h b/sql/item.h
index cf0fe45..a90cb01 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2687,18 +2687,27 @@ class Item :public Value_source,
void register_in(THD *thd);
bool depends_only_on(table_map view_map)
- { return marker & MARKER_FULL_EXTRACTION; }
- int get_extraction_flag() const
- { return marker & MARKER_EXTRACTION_MASK; }
+ { return get_extraction_flag() & MARKER_FULL_EXTRACTION; }
+ int get_extraction_flag() const
+ {
+ if (basic_const_item())
+ return MARKER_FULL_EXTRACTION;
+ else
+ return marker & MARKER_EXTRACTION_MASK;
+ }
void set_extraction_flag(int16 flags)
{
- marker &= ~MARKER_EXTRACTION_MASK;
- marker|= flags;
+ if (!basic_const_item())
+ {
+ marker= marker & ~MARKER_EXTRACTION_MASK;
+ marker|= flags;
+ }
}
void clear_extraction_flag()
{
- marker &= ~MARKER_EXTRACTION_MASK;
- }
+ if (!basic_const_item())
+ marker= marker & ~MARKER_EXTRACTION_MASK;
+ }
void check_pushable_cond(Pushdown_checker excl_dep_func, uchar *arg);
bool pushable_cond_checker_for_derived(uchar *arg)
{
1
0
10 Mar '23
revision-id: 2ae8dc24351b830fd15970758b65f58caf504678 (mariadb-10.11.1-108-g2ae8dc2)
parent(s): 12840543e531bf5809f662ec6e70c117d0c16de9
author: Igor Babaev
committer: Igor Babaev
timestamp: 2023-03-09 21:48:58 -0800
message:
Adjusted test results after rebase against 11.0.1
---
mysql-test/main/delete.result | 6 +-
mysql-test/main/delete_single_to_multi.result | 1491 +++++++++++--
mysql-test/main/delete_single_to_multi.test | 196 +-
mysql-test/main/derived_cond_pushdown.result | 15 +-
mysql-test/main/log_state.result | 2 +-
mysql-test/main/multi_update.result | 1 +
.../main/myisam_explain_non_select_all.result | 24 +-
mysql-test/main/opt_trace.result | 4 +-
mysql-test/main/subselect.result | 12 +
mysql-test/main/subselect.test | 6 +
mysql-test/main/subselect_no_exists_to_in.result | 12 +
mysql-test/main/subselect_no_mat.result | 12 +
mysql-test/main/subselect_no_opts.result | 12 +
mysql-test/main/subselect_no_scache.result | 12 +
mysql-test/main/subselect_no_semijoin.result | 12 +
mysql-test/main/update_single_to_multi.result | 2273 ++++++++++++++------
mysql-test/main/update_single_to_multi.test | 147 +-
mysql-test/main/update_use_source.result | 2 +-
sql/sql_select.cc | 3 +-
19 files changed, 3128 insertions(+), 1114 deletions(-)
diff --git a/mysql-test/main/delete.result b/mysql-test/main/delete.result
index dd62e09..c4bf335 100644
--- a/mysql-test/main/delete.result
+++ b/mysql-test/main/delete.result
@@ -583,8 +583,7 @@ 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 <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED a ALL NULL NULL NULL NULL 8
+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;
@@ -600,8 +599,7 @@ 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 <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED a ALL NULL NULL NULL NULL 8
+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;
diff --git a/mysql-test/main/delete_single_to_multi.result b/mysql-test/main/delete_single_to_multi.result
index fe27f69..eba4ca8 100644
--- a/mysql-test/main/delete_single_to_multi.result
+++ b/mysql-test/main/delete_single_to_multi.result
@@ -2,10 +2,26 @@ DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
create index i_n_name on nation(n_name);
-analyze table nation;
+analyze table
+nation, lineitem, customer, orders, part, supplier, partsupp, region
+persistent for all;
Table Op Msg_type Msg_text
dbt3_s001.nation analyze status Engine-independent statistics collected
dbt3_s001.nation analyze status OK
+dbt3_s001.lineitem analyze status Engine-independent statistics collected
+dbt3_s001.lineitem analyze status OK
+dbt3_s001.customer analyze status Engine-independent statistics collected
+dbt3_s001.customer analyze status OK
+dbt3_s001.orders analyze status Engine-independent statistics collected
+dbt3_s001.orders analyze status OK
+dbt3_s001.part analyze status Engine-independent statistics collected
+dbt3_s001.part analyze status OK
+dbt3_s001.supplier analyze status Engine-independent statistics collected
+dbt3_s001.supplier analyze status OK
+dbt3_s001.partsupp analyze status Engine-independent statistics collected
+dbt3_s001.partsupp analyze status OK
+dbt3_s001.region analyze status Engine-independent statistics collected
+dbt3_s001.region analyze status OK
# Pullout
# =======
explain
@@ -15,8 +31,8 @@ where c_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
explain format=json
select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
@@ -26,6 +42,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.052271677,
"nested_loop": [
{
"table": {
@@ -36,7 +53,9 @@ EXPLAIN
"key_length": "26",
"used_key_parts": ["n_name"],
"ref": ["const"],
+ "loops": 1,
"rows": 1,
+ "cost": 0.002024411,
"filtered": 100,
"index_condition": "nation.n_name = 'PERU'"
}
@@ -50,7 +69,9 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["c_nationkey"],
"ref": ["dbt3_s001.nation.n_nationkey"],
- "rows": 11,
+ "loops": 1,
+ "rows": 6,
+ "cost": 0.008193756,
"filtered": 100
}
},
@@ -71,7 +92,9 @@ EXPLAIN
"rows": 108,
"selectivity_pct": 7.2
},
- "rows": 11,
+ "loops": 6,
+ "rows": 15,
+ "cost": 0.04205351,
"filtered": 7.199999809,
"attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'"
}
@@ -104,8 +127,8 @@ where c_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
explain format=json
delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
@@ -115,6 +138,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.052271677,
"nested_loop": [
{
"table": {
@@ -125,7 +149,9 @@ EXPLAIN
"key_length": "26",
"used_key_parts": ["n_name"],
"ref": ["const"],
+ "loops": 1,
"rows": 1,
+ "cost": 0.002024411,
"filtered": 100,
"index_condition": "nation.n_name = 'PERU'"
}
@@ -139,7 +165,9 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["c_nationkey"],
"ref": ["dbt3_s001.nation.n_nationkey"],
- "rows": 11,
+ "loops": 1,
+ "rows": 6,
+ "cost": 0.008193756,
"filtered": 100
}
},
@@ -160,7 +188,9 @@ EXPLAIN
"rows": 108,
"selectivity_pct": 7.2
},
- "rows": 11,
+ "loops": 6,
+ "rows": 15,
+ "cost": 0.04205351,
"filtered": 7.199999809,
"attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'"
}
@@ -200,9 +230,9 @@ s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in
(select p_partkey, s_suppkey from part, supplier
where p_retailprice between 901 and 910 and
@@ -230,9 +260,9 @@ s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
delete from partsupp where (ps_partkey, ps_suppkey) in
(select p_partkey, s_suppkey from part, supplier
where p_retailprice between 901 and 910 and
@@ -267,9 +297,9 @@ where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
ps_suppkey in (select s_suppkey from supplier
@@ -297,9 +327,9 @@ where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
delete from partsupp where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
ps_suppkey in (select s_suppkey from supplier
@@ -344,11 +374,11 @@ where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter PRIMARY,i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
+1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
-1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter
-1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders
where o_custkey in
(select c_custkey from customer
@@ -401,11 +431,11 @@ where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter PRIMARY,i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
+1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
-1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter
-1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
delete from lineitem where l_orderkey in (select o_orderkey from orders
where o_custkey in
(select c_custkey from customer
@@ -466,9 +496,9 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where
-1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter
+1 PRIMARY nation ALL PRIMARY,i_n_regionkey NULL NULL NULL 25 Using where
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (9%) Using where; FirstMatch(customer); Using rowid filter
explain format=json
select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -479,37 +509,33 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.40015207,
"nested_loop": [
{
"table": {
- "table_name": "customer",
+ "table_name": "nation",
"access_type": "ALL",
- "possible_keys": ["PRIMARY", "i_c_nationkey"],
- "rows": 150,
- "filtered": 100,
- "attached_condition": "customer.c_nationkey is not null"
+ "possible_keys": ["PRIMARY", "i_n_regionkey"],
+ "loops": 1,
+ "rows": 25,
+ "cost": 0.013945725,
+ "filtered": 40,
+ "attached_condition": "nation.n_regionkey in (1,2)"
}
},
{
"table": {
- "table_name": "nation",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_n_regionkey"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["n_nationkey"],
- "ref": ["dbt3_s001.customer.c_nationkey"],
- "rowid_filter": {
- "range": {
- "key": "i_n_regionkey",
- "used_key_parts": ["n_regionkey"]
- },
- "rows": 10,
- "selectivity_pct": 40
- },
- "rows": 1,
- "filtered": 40,
- "attached_condition": "nation.n_regionkey in (1,2)"
+ "table_name": "customer",
+ "access_type": "ref",
+ "possible_keys": ["PRIMARY", "i_c_nationkey"],
+ "key": "i_c_nationkey",
+ "key_length": "5",
+ "used_key_parts": ["c_nationkey"],
+ "ref": ["dbt3_s001.nation.n_nationkey"],
+ "loops": 10,
+ "rows": 6,
+ "cost": 0.08009436,
+ "filtered": 100
}
},
{
@@ -529,10 +555,12 @@ EXPLAIN
"rows": 140,
"selectivity_pct": 9.333333333
},
- "rows": 11,
- "filtered": 9.333333015,
+ "loops": 60,
+ "rows": 15,
+ "cost": 0.306111985,
+ "filtered": 6.666666508,
"attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'",
- "first_match": "nation"
+ "first_match": "customer"
}
}
]
@@ -589,9 +617,9 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where
-1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter
+1 PRIMARY nation ALL PRIMARY,i_n_regionkey NULL NULL NULL 25 Using where
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (9%) Using where; FirstMatch(customer); Using rowid filter
explain format=json
delete from customer where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -602,37 +630,33 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.40015207,
"nested_loop": [
{
"table": {
- "table_name": "customer",
+ "table_name": "nation",
"access_type": "ALL",
- "possible_keys": ["PRIMARY", "i_c_nationkey"],
- "rows": 150,
- "filtered": 100,
- "attached_condition": "customer.c_nationkey is not null"
+ "possible_keys": ["PRIMARY", "i_n_regionkey"],
+ "loops": 1,
+ "rows": 25,
+ "cost": 0.013945725,
+ "filtered": 40,
+ "attached_condition": "nation.n_regionkey in (1,2)"
}
},
{
"table": {
- "table_name": "nation",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_n_regionkey"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["n_nationkey"],
- "ref": ["dbt3_s001.customer.c_nationkey"],
- "rowid_filter": {
- "range": {
- "key": "i_n_regionkey",
- "used_key_parts": ["n_regionkey"]
- },
- "rows": 10,
- "selectivity_pct": 40
- },
- "rows": 1,
- "filtered": 40,
- "attached_condition": "nation.n_regionkey in (1,2)"
+ "table_name": "customer",
+ "access_type": "ref",
+ "possible_keys": ["PRIMARY", "i_c_nationkey"],
+ "key": "i_c_nationkey",
+ "key_length": "5",
+ "used_key_parts": ["c_nationkey"],
+ "ref": ["dbt3_s001.nation.n_nationkey"],
+ "loops": 10,
+ "rows": 6,
+ "cost": 0.08009436,
+ "filtered": 100
}
},
{
@@ -652,10 +676,12 @@ EXPLAIN
"rows": 140,
"selectivity_pct": 9.333333333
},
- "rows": 11,
- "filtered": 9.333333015,
+ "loops": 60,
+ "rows": 15,
+ "cost": 0.306111985,
+ "filtered": 6.666666508,
"attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'",
- "first_match": "nation"
+ "first_match": "customer"
}
}
]
@@ -720,8 +746,8 @@ c_custkey in (select o_custkey from orders
where o_orderDATE between "1992-01-09" and "1993-01-08");
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (14%) Using where; FirstMatch(customer); Using rowid filter
select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU')
and
c_custkey in (select o_custkey from orders
@@ -745,8 +771,8 @@ c_custkey in (select o_custkey from orders
where o_orderDATE between "1992-01-09" and "1993-01-08");
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (14%) Using where; FirstMatch(customer); Using rowid filter
delete from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU')
and
c_custkey in (select o_custkey from orders
@@ -771,27 +797,138 @@ Customer#000000133 2314.67
drop table t;
# Materialization
# ===============
+set optimizer_switch='firstmatch=off';
+explain
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY nation range PRIMARY,i_n_name i_n_name 26 NULL 4 Using index condition
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
+3 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+c_name c_acctbal
+Customer#000000008 6819.74
+Customer#000000014 5266.3
+Customer#000000025 7133.7
+Customer#000000035 1228.24
+Customer#000000038 6345.11
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000067 8166.59
+Customer#000000077 1738.87
+Customer#000000094 5500.11
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000103 2757.45
+Customer#000000106 3288.42
+Customer#000000113 2912
+Customer#000000121 6428.32
+Customer#000000130 5073.58
+Customer#000000133 2314.67
+Customer#000000139 7897.78
+Customer#000000142 2209.81
+create table t as
+select * from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+explain
+delete from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY nation range PRIMARY,i_n_name i_n_name 26 NULL 4 Using index condition
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
+3 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
+delete from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+c_name c_acctbal
+insert into customer select * from t;
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+c_name c_acctbal
+Customer#000000008 6819.74
+Customer#000000014 5266.3
+Customer#000000025 7133.7
+Customer#000000035 1228.24
+Customer#000000038 6345.11
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000067 8166.59
+Customer#000000077 1738.87
+Customer#000000094 5500.11
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000103 2757.45
+Customer#000000106 3288.42
+Customer#000000113 2912
+Customer#000000121 6428.32
+Customer#000000130 5073.58
+Customer#000000133 2314.67
+Customer#000000139 7897.78
+Customer#000000142 2209.81
+drop table t;
+set optimizer_switch='firstmatch=default';
explain
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
-1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1
-2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where
+1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
explain format=json
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.382051418,
"nested_loop": [
{
"table": {
- "table_name": "<subquery2>",
+ "table_name": "customer",
"access_type": "ALL",
+ "possible_keys": ["PRIMARY"],
+ "loops": 1,
+ "rows": 150,
+ "cost": 0.03493875,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
"possible_keys": ["distinct_key"],
- "rows": 28,
+ "key": "distinct_key",
+ "key_length": "4",
+ "used_key_parts": ["o_custkey"],
+ "ref": ["func"],
+ "rows": 1,
"filtered": 100,
"materialized": {
"unique": 1,
@@ -801,89 +938,155 @@ EXPLAIN
{
"table": {
"table_name": "orders",
- "access_type": "range",
+ "access_type": "ALL",
"possible_keys": ["i_o_orderdate", "i_o_custkey"],
- "key": "i_o_orderdate",
- "key_length": "4",
- "used_key_parts": ["o_orderDATE"],
- "rows": 28,
- "filtered": 100,
- "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'",
- "attached_condition": "orders.o_custkey is not null"
+ "loops": 1,
+ "rows": 1500,
+ "cost": 0.2532975,
+ "filtered": 16.13333321,
+ "attached_condition": "orders.o_orderDATE between '1992-01-09' and '1993-03-08'"
}
}
]
}
}
}
- },
- {
- "table": {
- "table_name": "customer",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["c_custkey"],
- "ref": ["dbt3_s001.orders.o_custkey"],
- "rows": 1,
- "filtered": 100
- }
}
]
}
}
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
+Customer#000000019 8914.71
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
create table t as
select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
explain
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
-1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1
-2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where
+1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
explain format=json
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.37364371,
"nested_loop": [
{
"table": {
- "table_name": "<subquery2>",
+ "table_name": "customer",
"access_type": "ALL",
+ "possible_keys": ["PRIMARY"],
+ "loops": 1,
+ "rows": 150,
+ "cost": 0.026531042,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
"possible_keys": ["distinct_key"],
- "rows": 28,
+ "key": "distinct_key",
+ "key_length": "4",
+ "used_key_parts": ["o_custkey"],
+ "ref": ["func"],
+ "rows": 1,
"filtered": 100,
"materialized": {
"unique": 1,
@@ -893,71 +1096,121 @@ EXPLAIN
{
"table": {
"table_name": "orders",
- "access_type": "range",
+ "access_type": "ALL",
"possible_keys": ["i_o_orderdate", "i_o_custkey"],
- "key": "i_o_orderdate",
- "key_length": "4",
- "used_key_parts": ["o_orderDATE"],
- "rows": 28,
- "filtered": 100,
- "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'",
- "attached_condition": "orders.o_custkey is not null"
+ "loops": 1,
+ "rows": 1500,
+ "cost": 0.2532975,
+ "filtered": 16.13333321,
+ "attached_condition": "orders.o_orderDATE between '1992-01-09' and '1993-03-08'"
}
}
]
}
}
}
- },
- {
- "table": {
- "table_name": "customer",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["c_custkey"],
- "ref": ["dbt3_s001.orders.o_custkey"],
- "rows": 1,
- "filtered": 100
- }
}
]
}
}
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
insert into customer select * from t;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
+Customer#000000019 8914.71
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
-Customer#000000076 5745.33
-Customer#000000091 4643.14
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
drop table t;
explain
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
@@ -1141,18 +1394,22 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.085533248,
"nested_loop": [
{
"table": {
"table_name": "<subquery2>",
"access_type": "ALL",
"possible_keys": ["distinct_key"],
+ "loops": 1,
"rows": 28,
+ "cost": 0.03691572,
"filtered": 100,
"materialized": {
"unique": 1,
"query_block": {
"select_id": 2,
+ "cost": 0.053826401,
"having_condition": "count(orders.o_custkey) > 1",
"temporary_table": {
"nested_loop": [
@@ -1164,7 +1421,9 @@ EXPLAIN
"key": "i_o_orderdate",
"key_length": "4",
"used_key_parts": ["o_orderDATE"],
+ "loops": 1,
"rows": 28,
+ "cost": 0.035889016,
"filtered": 100,
"index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'"
}
@@ -1184,7 +1443,9 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["c_custkey"],
"ref": ["<subquery2>.o_custkey"],
+ "loops": 28,
"rows": 1,
+ "cost": 0.048617528,
"filtered": 100
}
}
@@ -1220,18 +1481,22 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.054856476,
"nested_loop": [
{
"table": {
"table_name": "<subquery2>",
"access_type": "ALL",
"possible_keys": ["distinct_key"],
+ "loops": 1,
"rows": 28,
+ "cost": 0.03691572,
"filtered": 100,
"materialized": {
"unique": 1,
"query_block": {
"select_id": 2,
+ "cost": 0.053826401,
"having_condition": "count(orders.o_custkey) > 1",
"temporary_table": {
"nested_loop": [
@@ -1243,7 +1508,9 @@ EXPLAIN
"key": "i_o_orderdate",
"key_length": "4",
"used_key_parts": ["o_orderDATE"],
+ "loops": 1,
"rows": 28,
+ "cost": 0.035889016,
"filtered": 100,
"index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'"
}
@@ -1263,7 +1530,9 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["c_custkey"],
"ref": ["<subquery2>.o_custkey"],
+ "loops": 28,
"rows": 1,
+ "cost": 0.017940756,
"filtered": 100
}
}
@@ -1295,7 +1564,7 @@ where o_orderDATE between '1992-01-09' and '1993-03-08'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1
-2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary
+2 MATERIALIZED orders ALL i_o_orderdate NULL NULL NULL 1500 Using where; Using temporary
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1993-03-08'
group by o_custkey having count(o_custkey) > 5);
@@ -1320,7 +1589,7 @@ where o_orderDATE between '1992-01-09' and '1993-03-08'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1
-2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary
+2 MATERIALIZED orders ALL i_o_orderdate NULL NULL NULL 1500 Using where; Using temporary
delete from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1993-03-08'
group by o_custkey having count(o_custkey) > 5);
@@ -1418,6 +1687,7 @@ drop table t,r;
deallocate prepare stmt;
# FirstMatch PS
# =============
+set optimizer_switch='materialization=off';
prepare stmt from "
delete from customer where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -1569,155 +1839,468 @@ Customer#000000139 7897.78
Customer#000000142 2209.81
drop table t,r;
deallocate prepare stmt;
+set optimizer_switch='materialization=default';
# Materialization PS
# ==================
prepare stmt from "
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like ?;
+where o_orderDATE between '1992-01-09' and '1993-03-08') and c_name like ?;
";
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
+Customer#000000019 8914.71
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
set @a1='Customer#%1_';
create table t as
select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like @a1;
+where o_orderDATE between '1992-01-09' and '1993-03-08') and c_name like @a1;
execute stmt using @a1;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
insert into customer select * from t;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
+Customer#000000019 8914.71
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
set @a2='Customer#%3_';
create table r as
select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') and c_name like @a2;
+where o_orderDATE between '1992-01-09' and '1993-03-08') and c_name like @a2;
execute stmt using @a2;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
+Customer#000000019 8914.71
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
insert into customer select * from r;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
+Customer#000000019 8914.71
Customer#000000022 591.98
Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
drop table t,r;
deallocate prepare stmt;
# Materialization SJM PS
# ======================
prepare stmt from "
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') and c_acctbal between ? and ?;
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1) and c_acctbal between ? and ?;
";
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1992-03-08'
@@ -1795,6 +2378,7 @@ o_orderkey o_totalprice
3142 16030.15
5095 184583.99
5121 150334.57
+5382 138423.03
644 201268.06
737 12984.85
create table t as
@@ -1811,6 +2395,7 @@ o_orderkey o_totalprice
1729 12137.76
2880 145761.99
3142 16030.15
+5382 138423.03
644 201268.06
737 12984.85
insert into orders select * from t;
@@ -1824,6 +2409,7 @@ o_orderkey o_totalprice
3142 16030.15
5095 184583.99
5121 150334.57
+5382 138423.03
644 201268.06
737 12984.85
create table r as
@@ -1841,6 +2427,7 @@ o_orderkey o_totalprice
2880 145761.99
3142 16030.15
5121 150334.57
+5382 138423.03
737 12984.85
insert into orders select * from r;
select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
@@ -1853,12 +2440,14 @@ o_orderkey o_totalprice
3142 16030.15
5095 184583.99
5121 150334.57
+5382 138423.03
644 201268.06
737 12984.85
drop table t,r;
drop procedure p;
# FirstMatch SP
# =============
+set optimizer_switch='materialization=off';
create procedure p(a int)
delete from customer where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -1873,10 +2462,13 @@ where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
Customer#000000007 9561.95
Customer#000000008 6819.74
+Customer#000000017 6.34
Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000025 7133.7
Customer#000000028 1007.18
Customer#000000037 -917.75
+Customer#000000040 1335.3
Customer#000000047 274.58
Customer#000000059 3458.6
Customer#000000061 1536.24
@@ -1913,8 +2505,11 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
+Customer#000000017 6.34
+Customer#000000022 591.98
Customer#000000028 1007.18
Customer#000000037 -917.75
+Customer#000000040 1335.3
Customer#000000047 274.58
Customer#000000059 3458.6
Customer#000000061 1536.24
@@ -1936,10 +2531,13 @@ where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
Customer#000000007 9561.95
Customer#000000008 6819.74
+Customer#000000017 6.34
Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000025 7133.7
Customer#000000028 1007.18
Customer#000000037 -917.75
+Customer#000000040 1335.3
Customer#000000047 274.58
Customer#000000059 3458.6
Customer#000000061 1536.24
@@ -1976,8 +2574,11 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
+Customer#000000017 6.34
+Customer#000000022 591.98
Customer#000000028 1007.18
Customer#000000037 -917.75
+Customer#000000040 1335.3
Customer#000000047 274.58
Customer#000000061 1536.24
Customer#000000064 -646.64
@@ -1993,10 +2594,13 @@ where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
Customer#000000007 9561.95
Customer#000000008 6819.74
+Customer#000000017 6.34
Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000025 7133.7
Customer#000000028 1007.18
Customer#000000037 -917.75
+Customer#000000040 1335.3
Customer#000000047 274.58
Customer#000000059 3458.6
Customer#000000061 1536.24
@@ -2022,81 +2626,304 @@ Customer#000000139 7897.78
Customer#000000142 2209.81
drop table t,r;
drop procedure p;
+set optimizer_switch='materialization=default';
# Materialization SP
# ==================
create procedure p()
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
+Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
+Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
+Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
create table t as
select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
call p();
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
insert into customer select * from t;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
+Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
+Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
+Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
create table r as
select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
call p();
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
insert into customer select * from r;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
+Customer#000000023 3332.02
Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
Customer#000000032 3471.53
+Customer#000000034 8589.7
+Customer#000000035 1228.24
Customer#000000037 -917.75
Customer#000000038 6345.11
+Customer#000000040 1335.3
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
Customer#000000116 8403.99
Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
drop table t,r;
drop procedure p;
# Materialization SJM SP
@@ -2158,72 +2985,294 @@ drop procedure p;
# ====================
# Check for DELETE ... RETURNING with SJ subquery in WHERE
select c_name from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name
+Customer#000000001
+Customer#000000002
+Customer#000000005
+Customer#000000007
+Customer#000000008
+Customer#000000010
+Customer#000000011
Customer#000000013
+Customer#000000014
Customer#000000016
+Customer#000000017
+Customer#000000019
+Customer#000000022
+Customer#000000023
Customer#000000025
+Customer#000000028
+Customer#000000029
+Customer#000000031
Customer#000000032
+Customer#000000034
+Customer#000000035
Customer#000000037
Customer#000000038
+Customer#000000040
+Customer#000000041
+Customer#000000043
+Customer#000000044
+Customer#000000046
+Customer#000000047
+Customer#000000049
Customer#000000052
+Customer#000000053
+Customer#000000055
Customer#000000056
+Customer#000000058
+Customer#000000059
+Customer#000000061
+Customer#000000062
+Customer#000000064
Customer#000000065
+Customer#000000067
+Customer#000000070
+Customer#000000071
+Customer#000000073
+Customer#000000074
Customer#000000076
+Customer#000000079
+Customer#000000080
+Customer#000000082
+Customer#000000083
+Customer#000000085
+Customer#000000086
+Customer#000000088
+Customer#000000089
Customer#000000091
+Customer#000000092
+Customer#000000094
+Customer#000000095
+Customer#000000097
+Customer#000000098
+Customer#000000100
+Customer#000000101
+Customer#000000103
+Customer#000000104
+Customer#000000106
+Customer#000000107
+Customer#000000109
+Customer#000000110
+Customer#000000112
Customer#000000115
Customer#000000116
Customer#000000118
+Customer#000000121
+Customer#000000122
+Customer#000000127
+Customer#000000128
+Customer#000000130
+Customer#000000131
+Customer#000000133
+Customer#000000134
+Customer#000000136
+Customer#000000137
+Customer#000000139
Customer#000000140
+Customer#000000142
+Customer#000000143
+Customer#000000145
+Customer#000000148
+Customer#000000149
create table t as
select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
explain
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name;
+where o_orderDATE between '1992-01-09' and '1993-03-08') returning c_name;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where
-2 DEPENDENT SUBQUERY orders index_subquery|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 func 175 (2%) Using where; Using rowid filter
+1 PRIMARY customer ALL NULL NULL NULL NULL 150 Using where
+2 DEPENDENT SUBQUERY orders index_subquery i_o_orderdate,i_o_custkey i_o_custkey 5 func 15 Using where
delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name;
+where o_orderDATE between '1992-01-09' and '1993-03-08') returning c_name;
c_name
+Customer#000000001
+Customer#000000002
+Customer#000000005
+Customer#000000007
+Customer#000000008
+Customer#000000010
+Customer#000000011
Customer#000000013
+Customer#000000014
Customer#000000016
+Customer#000000017
+Customer#000000019
+Customer#000000022
+Customer#000000023
Customer#000000025
+Customer#000000028
+Customer#000000029
+Customer#000000031
Customer#000000032
+Customer#000000034
+Customer#000000035
Customer#000000037
Customer#000000038
+Customer#000000040
+Customer#000000041
+Customer#000000043
+Customer#000000044
+Customer#000000046
+Customer#000000047
+Customer#000000049
Customer#000000052
+Customer#000000053
+Customer#000000055
Customer#000000056
+Customer#000000058
+Customer#000000059
+Customer#000000061
+Customer#000000062
+Customer#000000064
Customer#000000065
+Customer#000000067
+Customer#000000070
+Customer#000000071
+Customer#000000073
+Customer#000000074
Customer#000000076
+Customer#000000079
+Customer#000000080
+Customer#000000082
+Customer#000000083
+Customer#000000085
+Customer#000000086
+Customer#000000088
+Customer#000000089
Customer#000000091
+Customer#000000092
+Customer#000000094
+Customer#000000095
+Customer#000000097
+Customer#000000098
+Customer#000000100
+Customer#000000101
+Customer#000000103
+Customer#000000104
+Customer#000000106
+Customer#000000107
+Customer#000000109
+Customer#000000110
+Customer#000000112
Customer#000000115
Customer#000000116
Customer#000000118
+Customer#000000121
+Customer#000000122
+Customer#000000127
+Customer#000000128
+Customer#000000130
+Customer#000000131
+Customer#000000133
+Customer#000000134
+Customer#000000136
+Customer#000000137
+Customer#000000139
Customer#000000140
+Customer#000000142
+Customer#000000143
+Customer#000000145
+Customer#000000148
+Customer#000000149
select c_name from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name
insert into customer select * from t;
select c_name from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name
+Customer#000000001
+Customer#000000002
+Customer#000000005
+Customer#000000007
+Customer#000000008
+Customer#000000010
+Customer#000000011
Customer#000000013
+Customer#000000014
Customer#000000016
+Customer#000000017
+Customer#000000019
+Customer#000000022
+Customer#000000023
Customer#000000025
+Customer#000000028
+Customer#000000029
+Customer#000000031
Customer#000000032
+Customer#000000034
+Customer#000000035
Customer#000000037
Customer#000000038
+Customer#000000040
+Customer#000000041
+Customer#000000043
+Customer#000000044
+Customer#000000046
+Customer#000000047
+Customer#000000049
Customer#000000052
+Customer#000000053
+Customer#000000055
Customer#000000056
+Customer#000000058
+Customer#000000059
+Customer#000000061
+Customer#000000062
+Customer#000000064
Customer#000000065
+Customer#000000067
+Customer#000000070
+Customer#000000071
+Customer#000000073
+Customer#000000074
Customer#000000076
+Customer#000000079
+Customer#000000080
+Customer#000000082
+Customer#000000083
+Customer#000000085
+Customer#000000086
+Customer#000000088
+Customer#000000089
Customer#000000091
+Customer#000000092
+Customer#000000094
+Customer#000000095
+Customer#000000097
+Customer#000000098
+Customer#000000100
+Customer#000000101
+Customer#000000103
+Customer#000000104
+Customer#000000106
+Customer#000000107
+Customer#000000109
+Customer#000000110
+Customer#000000112
Customer#000000115
Customer#000000116
Customer#000000118
+Customer#000000121
+Customer#000000122
+Customer#000000127
+Customer#000000128
+Customer#000000130
+Customer#000000131
+Customer#000000133
+Customer#000000134
+Customer#000000136
+Customer#000000137
+Customer#000000139
Customer#000000140
+Customer#000000142
+Customer#000000143
+Customer#000000145
+Customer#000000148
+Customer#000000149
drop table t;
select c_name from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1992-03-08'
@@ -2243,7 +3292,7 @@ delete from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1992-03-08'
group by o_custkey having count(o_custkey) > 1) returning c_name;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where
+1 PRIMARY customer ALL NULL NULL NULL NULL 150 Using where
2 DEPENDENT SUBQUERY orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary
delete from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1992-03-08'
@@ -2269,64 +3318,16 @@ Customer#000000037
Customer#000000056
Customer#000000118
drop table t;
-# Check for DELETE ... RETURNING with SJ subquery in WHERE
-select c_name from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-c_name
-Customer#000000013
-Customer#000000016
-Customer#000000025
-Customer#000000032
-Customer#000000037
-Customer#000000038
-Customer#000000052
-Customer#000000056
-Customer#000000065
-Customer#000000076
-Customer#000000091
-Customer#000000115
-Customer#000000116
-Customer#000000118
-Customer#000000140
-create table t as
-select * from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-explain
-delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name;
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL NULL NULL NULL NULL 141 Using where
-2 DEPENDENT SUBQUERY orders index_subquery|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 func 175 (2%) Using where; Using rowid filter
-delete from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08') returning c_name;
-c_name
-Customer#000000013
-Customer#000000016
-Customer#000000025
-Customer#000000032
-Customer#000000037
-Customer#000000038
-Customer#000000052
-Customer#000000056
-Customer#000000065
-Customer#000000076
-Customer#000000091
-Customer#000000115
-Customer#000000116
-Customer#000000118
-Customer#000000140
-select c_name from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-c_name
-insert into customer select * from t;
-drop table t;
# Check for DELETE ... ORDER BY ...LIMIT with SJ subquery in WHERE
select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
o_orderkey o_totalprice
1221 117397.16
+1344 43809.37
1856 189361.42
+1925 146382.71
+3139 40975.96
324 26868.85
4903 34363.63
5607 24660.06
@@ -2338,18 +3339,21 @@ where c_nationkey in (1,2))
order by o_totalprice limit 500;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY orders range i_o_orderdate i_o_orderdate 4 NULL 108 Using where; Using filesort
-2 DEPENDENT SUBQUERY customer unique_subquery|filter PRIMARY,i_c_nationkey PRIMARY|i_c_nationkey 4|5 func 1 (10%) Using where; Using rowid filter
+2 DEPENDENT SUBQUERY customer unique_subquery PRIMARY,i_c_nationkey PRIMARY 4 func 1 Using where
create table t as
select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
select o_orderkey, o_totalprice from t;
o_orderkey o_totalprice
+1221 117397.16
324 26868.85
1856 189361.42
-1221 117397.16
4903 34363.63
5607 24660.06
+1344 43809.37
+1925 146382.71
+3139 40975.96
delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2))
@@ -2364,7 +3368,10 @@ o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
o_orderkey o_totalprice
1221 117397.16
+1344 43809.37
1856 189361.42
+1925 146382.71
+3139 40975.96
324 26868.85
4903 34363.63
5607 24660.06
@@ -2375,19 +3382,22 @@ delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 14 Using index condition
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 12 (7%) Using where; Using rowid filter
+1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 13 Using index condition
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
create table t as
select * from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
select o_orderkey, o_totalprice from t;
o_orderkey o_totalprice
-1856 189361.42
-324 26868.85
1221 117397.16
+324 26868.85
+1856 189361.42
4903 34363.63
5607 24660.06
+1344 43809.37
+1925 146382.71
+3139 40975.96
delete from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
@@ -2401,7 +3411,10 @@ o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
o_orderkey o_totalprice
1221 117397.16
+1344 43809.37
1856 189361.42
+1925 146382.71
+3139 40975.96
324 26868.85
4903 34363.63
5607 24660.06
diff --git a/mysql-test/main/delete_single_to_multi.test b/mysql-test/main/delete_single_to_multi.test
index 2c49128..2829ae1 100644
--- a/mysql-test/main/delete_single_to_multi.test
+++ b/mysql-test/main/delete_single_to_multi.test
@@ -15,7 +15,9 @@ use dbt3_s001;
--enable_query_log
create index i_n_name on nation(n_name);
-analyze table nation;
+analyze table
+ nation, lineitem, customer, orders, part, supplier, partsupp, region
+persistent for all;
--echo # Pullout
@@ -242,16 +244,18 @@ drop table t;
--echo # Materialization
--echo # ===============
+set optimizer_switch='firstmatch=off';
+
let $c7=
+ c_nationkey in (select n_nationkey from nation where
+ n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+ and
c_custkey in (select o_custkey from orders
- where o_orderDATE between '1992-01-09' and '1992-03-08');
+ where o_orderDATE between "1992-01-09" and "1995-01-08");
eval
explain
select c_name, c_acctbal from customer where $c7;
-eval
-explain format=json
-select c_name, c_acctbal from customer where $c7;
--sorted_result
eval
select c_name, c_acctbal from customer where $c7;
@@ -263,9 +267,6 @@ eval
explain
delete from customer where $c7;
eval
-explain format=json
-delete from customer where $c7;
-eval
delete from customer where $c7;
eval
select c_name, c_acctbal from customer where $c7;
@@ -276,14 +277,18 @@ eval
select c_name, c_acctbal from customer where $c7;
drop table t;
+set optimizer_switch='firstmatch=default';
let $c8=
c_custkey in (select o_custkey from orders
- where o_orderDATE between '1992-06-09' and '1993-01-08');
+ where o_orderDATE between '1992-01-09' and '1993-03-08');
eval
explain
select c_name, c_acctbal from customer where $c8;
+eval
+explain format=json
+select c_name, c_acctbal from customer where $c8;
--sorted_result
eval
select c_name, c_acctbal from customer where $c8;
@@ -295,6 +300,9 @@ eval
explain
delete from customer where $c8;
eval
+explain format=json
+delete from customer where $c8;
+eval
delete from customer where $c8;
eval
select c_name, c_acctbal from customer where $c8;
@@ -306,20 +314,13 @@ select c_name, c_acctbal from customer where $c8;
drop table t;
---echo # Materialization SJM
---echo # ===================
-
let $c9=
c_custkey in (select o_custkey from orders
- where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
+ where o_orderDATE between '1992-06-09' and '1993-01-08');
eval
explain
select c_name, c_acctbal from customer where $c9;
-eval
-explain format=json
-select c_name, c_acctbal from customer where $c9;
--sorted_result
eval
select c_name, c_acctbal from customer where $c9;
@@ -331,9 +332,6 @@ eval
explain
delete from customer where $c9;
eval
-explain format=json
-delete from customer where $c9;
-eval
delete from customer where $c9;
eval
select c_name, c_acctbal from customer where $c9;
@@ -345,14 +343,20 @@ select c_name, c_acctbal from customer where $c9;
drop table t;
+--echo # Materialization SJM
+--echo # ===================
+
let $c10=
c_custkey in (select o_custkey from orders
- where o_orderDATE between '1992-01-09' and '1993-03-08'
- group by o_custkey having count(o_custkey) > 5);
+ where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
eval
explain
select c_name, c_acctbal from customer where $c10;
+eval
+explain format=json
+select c_name, c_acctbal from customer where $c10;
--sorted_result
eval
select c_name, c_acctbal from customer where $c10;
@@ -364,6 +368,9 @@ eval
explain
delete from customer where $c10;
eval
+explain format=json
+delete from customer where $c10;
+eval
delete from customer where $c10;
eval
select c_name, c_acctbal from customer where $c10;
@@ -375,6 +382,36 @@ select c_name, c_acctbal from customer where $c10;
drop table t;
+let $c11=
+ c_custkey in (select o_custkey from orders
+ where o_orderDATE between '1992-01-09' and '1993-03-08'
+ group by o_custkey having count(o_custkey) > 5);
+
+eval
+explain
+select c_name, c_acctbal from customer where $c11;
+--sorted_result
+eval
+select c_name, c_acctbal from customer where $c11;
+eval
+create table t as
+select * from customer where $c11;
+
+eval
+explain
+delete from customer where $c11;
+eval
+delete from customer where $c11;
+eval
+select c_name, c_acctbal from customer where $c11;
+
+insert into customer select * from t;
+--sorted_result
+eval
+select c_name, c_acctbal from customer where $c11;
+drop table t;
+
+
--echo # Pullout PS
--echo # ==========
@@ -416,6 +453,8 @@ deallocate prepare stmt;
--echo # FirstMatch PS
--echo # =============
+set optimizer_switch='materialization=off';
+
eval
prepare stmt from "
delete from customer where $c5;
@@ -450,42 +489,43 @@ drop table t,r;
deallocate prepare stmt;
+set optimizer_switch='materialization=default';
--echo # Materialization PS
--echo # ==================
eval
prepare stmt from "
-delete from customer where $c7 and c_name like ?;
+delete from customer where $c8 and c_name like ?;
";
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
set @a1='Customer#%1_';
eval
create table t as
-select * from customer where $c7 and c_name like @a1;
+select * from customer where $c8 and c_name like @a1;
execute stmt using @a1;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
insert into customer select * from t;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
set @a2='Customer#%3_';
eval
create table r as
-select * from customer where $c7 and c_name like @a2;
+select * from customer where $c8 and c_name like @a2;
execute stmt using @a2;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
insert into customer select * from r;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
drop table t,r;
deallocate prepare stmt;
@@ -496,38 +536,38 @@ deallocate prepare stmt;
eval
prepare stmt from "
-delete from customer where $c7 and c_acctbal between ? and ?;
+delete from customer where $c10 and c_acctbal between ? and ?;
";
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
set @a1=3500;
set @a2=4000;
eval
create table t as
-select * from customer where $c9 and c_acctbal between @a1 and @a2;
+select * from customer where $c10 and c_acctbal between @a1 and @a2;
execute stmt using @a1, @a2;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
insert into customer select * from t;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
set @a3=-1000;
set @a4=3500;
eval
create table r as
-select * from customer where $c9 and c_acctbal between @a3 and @a4;
+select * from customer where $c10 and c_acctbal between @a3 and @a4;
execute stmt using @a3, @a4;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
insert into customer select * from r;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
drop table t,r;
deallocate prepare stmt;
@@ -573,6 +613,8 @@ drop procedure p;
--echo # FirstMatch SP
--echo # =============
+set optimizer_switch='materialization=off';
+
eval
create procedure p(a int)
delete from customer where $c5 and c_acctbal > a;
@@ -606,39 +648,41 @@ drop table t,r;
drop procedure p;
+set optimizer_switch='materialization=default';
+
--echo # Materialization SP
--echo # ==================
eval
create procedure p()
-delete from customer where $c7;
+delete from customer where $c8;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
eval
create table t as
-select * from customer where $c7;
+select * from customer where $c8;
call p();
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
insert into customer select * from t;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
eval
create table r as
-select * from customer where $c7;
+select * from customer where $c8;
call p();
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
insert into customer select * from r;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
drop table t,r;
drop procedure p;
@@ -649,33 +693,33 @@ drop procedure p;
eval
create procedure p()
-delete from customer where $c9;
+delete from customer where $c10;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
eval
create table t as
-select * from customer where $c9;
+select * from customer where $c10;
call p();
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
insert into customer select * from t;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
eval
create table r as
-select * from customer where $c9;
+select * from customer where $c10;
call p();
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
insert into customer select * from r;
--sorted_result
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
drop table t,r;
drop procedure p;
@@ -687,64 +731,44 @@ drop procedure p;
--sorted_result
eval
-select c_name from customer where $c7;
+select c_name from customer where $c8;
eval
create table t as
-select * from customer where $c7;
+select * from customer where $c8;
eval
explain
-delete from customer where $c7 returning c_name;
+delete from customer where $c8 returning c_name;
--sorted_result
eval
-delete from customer where $c7 returning c_name;
+delete from customer where $c8 returning c_name;
--sorted_result
eval
-select c_name from customer where $c7;
+select c_name from customer where $c8;
insert into customer select * from t;
--sorted_result
eval
-select c_name from customer where $c7;
+select c_name from customer where $c8;
drop table t;
--sorted_result
eval
-select c_name from customer where $c9;
+select c_name from customer where $c10;
eval
create table t as
-select * from customer where $c9;
+select * from customer where $c10;
eval
explain
-delete from customer where $c9 returning c_name;
+delete from customer where $c10 returning c_name;
--sorted_result
eval
-delete from customer where $c9 returning c_name;
+delete from customer where $c10 returning c_name;
--sorted_result
eval
-select c_name from customer where $c9;
+select c_name from customer where $c10;
insert into customer select * from t;
--sorted_result
eval
-select c_name from customer where $c9;
-drop table t;
-
---echo # Check for DELETE ... RETURNING with SJ subquery in WHERE
-
---sorted_result
-eval
-select c_name from customer where $c7;
-eval
-create table t as
-select * from customer where $c7;
-eval
-explain
-delete from customer where $c7 returning c_name;
---sorted_result
-eval
-delete from customer where $c7 returning c_name;
---sorted_result
-eval
-select c_name from customer where $c7;
-insert into customer select * from t;
+select c_name from customer where $c10;
drop table t;
--echo # Check for DELETE ... ORDER BY ...LIMIT with SJ subquery in WHERE
diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result
index 7523e28..fd3530b 100644
--- a/mysql-test/main/derived_cond_pushdown.result
+++ b/mysql-test/main/derived_cond_pushdown.result
@@ -13134,20 +13134,7 @@ EXPLAIN
"materialized": {
"query_block": {
"select_id": 3,
-<<<<<<< 2ad65c4dbcb291867725d50d1f53c8da8549afb3
"cost": "COST_REPLACED",
- "nested_loop": [
- {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "loops": 1,
- "rows": 2,
- "cost": "COST_REPLACED",
- "filtered": 100,
- "attached_condition": "t1.f2 < 2"
- }
-=======
"filesort": {
"sort_key": "t1.f2",
"temporary_table": {
@@ -13156,7 +13143,9 @@ EXPLAIN
"table": {
"table_name": "t1",
"access_type": "ALL",
+ "loops": 1,
"rows": 2,
+ "cost": "COST_REPLACED",
"filtered": 100,
"attached_condition": "t1.f2 < 2"
}
diff --git a/mysql-test/main/log_state.result b/mysql-test/main/log_state.result
index 1b1c737..18c8da7 100644
--- a/mysql-test/main/log_state.result
+++ b/mysql-test/main/log_state.result
@@ -243,7 +243,7 @@ rows_examined sql_text
4 UPDATE t1 SET a=a+sleep(.02) WHERE a>2
8 UPDATE t1 SET a=a+sleep(.02) ORDER BY a DESC
1 UPDATE t2 set b=b+sleep(.02) limit 1
-10 UPDATE t1 SET a=a+sleep(.02) WHERE a in (SELECT b from t2)
+6 UPDATE t1 SET a=a+sleep(.02) WHERE a in (SELECT b from t2)
6 DELETE FROM t1 WHERE a=a+sleep(.02) ORDER BY a LIMIT 2
disconnect con2;
connection default;
diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result
index e5ed031..2364ee7 100644
--- a/mysql-test/main/multi_update.result
+++ b/mysql-test/main/multi_update.result
@@ -1270,6 +1270,7 @@ DROP TABLES t1, t2;
# End of 10.3 tests
#
# MDEV-30538: multi-table UPDATE/DELETE with possible exists-to-in
+#
create table t1 (c1 int, c2 int, c3 int, index idx(c2));
insert into t1 values
(1,1,1),(3,2,2),(1,3,3),
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 3edbf29..2f56847 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -218,16 +218,14 @@ INSERT INTO t2 VALUES (1), (2), (3);
#
EXPLAIN UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 33.33 Using where; FirstMatch
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -248,9 +246,9 @@ Handler_read_key 4
Handler_read_rnd_next 5
# Status of testing query execution:
Variable_name Value
-Handler_read_key 5
+Handler_read_key 4
Handler_read_rnd 3
-Handler_read_rnd_next 12
+Handler_read_rnd_next 9
Handler_update 3
DROP TABLE t1, t2;
@@ -904,15 +902,13 @@ INSERT INTO t2 VALUES (1), (2), (3), (1000);
EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1)
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(t1)
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 4
@@ -933,8 +929,8 @@ Handler_read_key 4
Handler_read_rnd_next 9
# Status of testing query execution:
Variable_name Value
-Handler_read_key 7
-Handler_read_rnd_next 8
+Handler_read_key 4
+Handler_read_rnd_next 10
Handler_update 3
DROP TABLE t1, t2;
@@ -2828,14 +2824,14 @@ INSERT INTO t2 VALUES (1), (2), (3);
EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
-1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 FirstMatch(t1)
+1 PRIMARY <derived3> eq_ref distinct_key distinct_key 5 test.t1.a 1
3 DERIVED t2 ALL NULL NULL NULL NULL 3 Using filesort
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
-1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 100.00 FirstMatch(t1)
+1 PRIMARY <derived3> eq_ref distinct_key distinct_key 5 test.t1.a 1 100.00
3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort
# Status of EXPLAIN EXTENDED query
Variable_name Value
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 1e32802..d5213d4 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -4495,7 +4495,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"rowid_filters": [
{
"key": "a",
- "build_cost": 0.174715752,
+ "build_cost": 0.001129926,
"rows": 3
}
]
@@ -4570,7 +4570,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"rowid_filters": [
{
"key": "a",
- "build_cost": 0.174715752,
+ "build_cost": 0.001129926,
"rows": 3
}
]
diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result
index ce156f1..3a246e2 100644
--- a/mysql-test/main/subselect.result
+++ b/mysql-test/main/subselect.result
@@ -634,6 +634,18 @@ a b
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+a b
+0 10
+1 11
+select * from t12;
+a b
+33 10
+22 11
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
ERROR 21000: Subquery returns more than 1 row
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test
index 8fefa39..578dbe8 100644
--- a/mysql-test/main/subselect.test
+++ b/mysql-test/main/subselect.test
@@ -387,6 +387,12 @@ insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t11;
select * from t12;
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+select * from t12;
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
-- error ER_SUBQUERY_NO_1_ROW
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result
index 37a503d..3be4f07 100644
--- a/mysql-test/main/subselect_no_exists_to_in.result
+++ b/mysql-test/main/subselect_no_exists_to_in.result
@@ -638,6 +638,18 @@ a b
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+a b
+0 10
+1 11
+select * from t12;
+a b
+33 10
+22 11
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
ERROR 21000: Subquery returns more than 1 row
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result
index 32a6358..58124a9 100644
--- a/mysql-test/main/subselect_no_mat.result
+++ b/mysql-test/main/subselect_no_mat.result
@@ -641,6 +641,18 @@ a b
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+a b
+0 10
+1 11
+select * from t12;
+a b
+33 10
+22 11
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
ERROR 21000: Subquery returns more than 1 row
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result
index d75c421..10153b0 100644
--- a/mysql-test/main/subselect_no_opts.result
+++ b/mysql-test/main/subselect_no_opts.result
@@ -637,6 +637,18 @@ a b
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+a b
+0 10
+1 11
+select * from t12;
+a b
+33 10
+22 11
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
ERROR 21000: Subquery returns more than 1 row
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result
index 336936d..cd31b9b 100644
--- a/mysql-test/main/subselect_no_scache.result
+++ b/mysql-test/main/subselect_no_scache.result
@@ -640,6 +640,18 @@ a b
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+a b
+0 10
+1 11
+select * from t12;
+a b
+33 10
+22 11
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
ERROR 21000: Subquery returns more than 1 row
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result
index c34dfe6..eba0f55 100644
--- a/mysql-test/main/subselect_no_semijoin.result
+++ b/mysql-test/main/subselect_no_semijoin.result
@@ -637,6 +637,18 @@ a b
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
+select * from t11;
+a b
+0 10
+1 11
+select * from t12;
+a b
+33 10
+22 11
+delete from t11;
+delete from t12;
+insert into t11 values (0, 10),(1, 11),(2, 12);
+insert into t12 values (33, 10),(22, 11),(2, 12);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
ERROR 21000: Subquery returns more than 1 row
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
diff --git a/mysql-test/main/update_single_to_multi.result b/mysql-test/main/update_single_to_multi.result
index cc28a0f..11969f7 100644
--- a/mysql-test/main/update_single_to_multi.result
+++ b/mysql-test/main/update_single_to_multi.result
@@ -2,10 +2,26 @@ DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
create index i_n_name on nation(n_name);
-analyze table nation;
+analyze table
+nation, lineitem, customer, orders, part, supplier, partsupp, region
+persistent for all;
Table Op Msg_type Msg_text
dbt3_s001.nation analyze status Engine-independent statistics collected
dbt3_s001.nation analyze status OK
+dbt3_s001.lineitem analyze status Engine-independent statistics collected
+dbt3_s001.lineitem analyze status OK
+dbt3_s001.customer analyze status Engine-independent statistics collected
+dbt3_s001.customer analyze status OK
+dbt3_s001.orders analyze status Engine-independent statistics collected
+dbt3_s001.orders analyze status OK
+dbt3_s001.part analyze status Engine-independent statistics collected
+dbt3_s001.part analyze status OK
+dbt3_s001.supplier analyze status Engine-independent statistics collected
+dbt3_s001.supplier analyze status OK
+dbt3_s001.partsupp analyze status Engine-independent statistics collected
+dbt3_s001.partsupp analyze status OK
+dbt3_s001.region analyze status Engine-independent statistics collected
+dbt3_s001.region analyze status OK
# Pullout
# =======
explain
@@ -15,8 +31,8 @@ where c_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
explain format=json
select o_orderkey, o_totalprice from orders where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
@@ -26,6 +42,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.052271677,
"nested_loop": [
{
"table": {
@@ -36,7 +53,9 @@ EXPLAIN
"key_length": "26",
"used_key_parts": ["n_name"],
"ref": ["const"],
+ "loops": 1,
"rows": 1,
+ "cost": 0.002024411,
"filtered": 100,
"index_condition": "nation.n_name = 'PERU'"
}
@@ -50,7 +69,9 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["c_nationkey"],
"ref": ["dbt3_s001.nation.n_nationkey"],
- "rows": 11,
+ "loops": 1,
+ "rows": 6,
+ "cost": 0.008193756,
"filtered": 100
}
},
@@ -71,7 +92,9 @@ EXPLAIN
"rows": 108,
"selectivity_pct": 7.2
},
- "rows": 11,
+ "loops": 6,
+ "rows": 15,
+ "cost": 0.04205351,
"filtered": 7.199999809,
"attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'"
}
@@ -99,8 +122,8 @@ where c_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
explain format=json
update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
@@ -110,6 +133,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.052271677,
"nested_loop": [
{
"table": {
@@ -120,7 +144,9 @@ EXPLAIN
"key_length": "26",
"used_key_parts": ["n_name"],
"ref": ["const"],
+ "loops": 1,
"rows": 1,
+ "cost": 0.002024411,
"filtered": 100,
"index_condition": "nation.n_name = 'PERU'"
}
@@ -134,7 +160,9 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["c_nationkey"],
"ref": ["dbt3_s001.nation.n_nationkey"],
- "rows": 11,
+ "loops": 1,
+ "rows": 6,
+ "cost": 0.008193756,
"filtered": 100
}
},
@@ -155,7 +183,9 @@ EXPLAIN
"rows": 108,
"selectivity_pct": 7.2
},
- "rows": 11,
+ "loops": 6,
+ "rows": 15,
+ "cost": 0.04205351,
"filtered": 7.199999809,
"attached_condition": "orders.o_orderDATE between '1992-01-01' and '1992-06-30'"
}
@@ -205,22 +235,22 @@ s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
select ps_partkey, ps_suppkey, ps_supplycost from partsupp where (ps_partkey, ps_suppkey) in
(select p_partkey, s_suppkey from part, supplier
where p_retailprice between 901 and 910 and
s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
ps_partkey ps_suppkey ps_supplycost
-4 1 444.37
-6 1 642.13
-8 1 957.34
1 8 357.84
3 8 645.4
+4 1 444.37
5 8 50.52
+6 1 642.13
7 8 763.98
+8 1 957.34
explain
update partsupp set ps_supplycost = ps_supplycost+2 where (ps_partkey, ps_suppkey) in
(select p_partkey, s_suppkey from part, supplier
@@ -229,9 +259,9 @@ s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
update partsupp set ps_supplycost = ps_supplycost+2 where (ps_partkey, ps_suppkey) in
(select p_partkey, s_suppkey from part, supplier
where p_retailprice between 901 and 910 and
@@ -243,13 +273,13 @@ where p_retailprice between 901 and 910 and
s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
ps_partkey ps_suppkey ps_supplycost
-4 1 446.37
-6 1 644.13
-8 1 959.34
1 8 359.84
3 8 647.4
+4 1 446.37
5 8 52.52
+6 1 644.13
7 8 765.98
+8 1 959.34
update partsupp set ps_supplycost = ps_supplycost-2 where (ps_partkey, ps_suppkey) in
(select p_partkey, s_suppkey from part, supplier
where p_retailprice between 901 and 910 and
@@ -261,13 +291,13 @@ where p_retailprice between 901 and 910 and
s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
ps_partkey ps_suppkey ps_supplycost
-4 1 444.37
-6 1 642.13
-8 1 957.34
1 8 357.84
3 8 645.4
+4 1 444.37
5 8 50.52
+6 1 642.13
7 8 763.98
+8 1 957.34
explain
select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
@@ -276,22 +306,22 @@ where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
select ps_partkey, ps_suppkey, ps_supplycost from partsupp where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
ps_suppkey in (select s_suppkey from supplier
where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
ps_partkey ps_suppkey ps_supplycost
-4 1 444.37
-6 1 642.13
-8 1 957.34
1 8 357.84
3 8 645.4
+4 1 444.37
5 8 50.52
+6 1 642.13
7 8 763.98
+8 1 957.34
explain
update partsupp set ps_supplycost = ps_supplycost+10 where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
@@ -300,9 +330,9 @@ where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 16
-1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 Using where
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1
update partsupp set ps_supplycost = ps_supplycost+10 where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
ps_suppkey in (select s_suppkey from supplier
@@ -314,13 +344,13 @@ ps_suppkey in (select s_suppkey from supplier
where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
ps_partkey ps_suppkey ps_supplycost
-4 1 454.37
-6 1 652.13
-8 1 967.34
1 8 367.84
3 8 655.4
+4 1 454.37
5 8 60.52
+6 1 652.13
7 8 773.98
+8 1 967.34
update partsupp set ps_supplycost = ps_supplycost-10 where ps_partkey in (select p_partkey from part
where p_retailprice between 901 and 910) and
ps_suppkey in (select s_suppkey from supplier
@@ -332,13 +362,13 @@ ps_suppkey in (select s_suppkey from supplier
where s_nationkey in (select n_nationkey from nation
where n_name='PERU'));
ps_partkey ps_suppkey ps_supplycost
-4 1 444.37
-6 1 642.13
-8 1 957.34
1 8 357.84
3 8 645.4
+4 1 444.37
5 8 50.52
+6 1 642.13
7 8 763.98
+8 1 957.34
explain
select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders
where o_custkey in
@@ -357,11 +387,11 @@ where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter PRIMARY,i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
+1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
-1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter
-1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
select l_orderkey, l_linenumber, l_tax from lineitem where l_orderkey in (select o_orderkey from orders
where o_custkey in
(select c_custkey from customer
@@ -399,11 +429,11 @@ where n_name='PERU'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 2
-1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey 5 dbt3_s001.supplier.s_suppkey 100 Using where
+1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter PRIMARY,i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
+1 PRIMARY lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
-1 PRIMARY orders eq_ref|filter PRIMARY,i_o_orderdate,i_o_custkey PRIMARY|i_o_orderdate 4|4 dbt3_s001.lineitem.l_orderkey 1 (7%) Using where; Using rowid filter
-1 PRIMARY customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
update lineitem set l_tax = (l_tax*100+1)/100 where l_orderkey in (select o_orderkey from orders
where o_custkey in
(select c_custkey from customer
@@ -480,9 +510,9 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where
-1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter
+1 PRIMARY nation ALL PRIMARY,i_n_regionkey NULL NULL NULL 25 Using where
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (9%) Using where; FirstMatch(customer); Using rowid filter
explain format=json
select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -493,37 +523,33 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.40015207,
"nested_loop": [
{
"table": {
- "table_name": "customer",
+ "table_name": "nation",
"access_type": "ALL",
- "possible_keys": ["PRIMARY", "i_c_nationkey"],
- "rows": 150,
- "filtered": 100,
- "attached_condition": "customer.c_nationkey is not null"
+ "possible_keys": ["PRIMARY", "i_n_regionkey"],
+ "loops": 1,
+ "rows": 25,
+ "cost": 0.013945725,
+ "filtered": 40,
+ "attached_condition": "nation.n_regionkey in (1,2)"
}
},
{
"table": {
- "table_name": "nation",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_n_regionkey"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["n_nationkey"],
- "ref": ["dbt3_s001.customer.c_nationkey"],
- "rowid_filter": {
- "range": {
- "key": "i_n_regionkey",
- "used_key_parts": ["n_regionkey"]
- },
- "rows": 10,
- "selectivity_pct": 40
- },
- "rows": 1,
- "filtered": 40,
- "attached_condition": "nation.n_regionkey in (1,2)"
+ "table_name": "customer",
+ "access_type": "ref",
+ "possible_keys": ["PRIMARY", "i_c_nationkey"],
+ "key": "i_c_nationkey",
+ "key_length": "5",
+ "used_key_parts": ["c_nationkey"],
+ "ref": ["dbt3_s001.nation.n_nationkey"],
+ "loops": 10,
+ "rows": 6,
+ "cost": 0.08009436,
+ "filtered": 100
}
},
{
@@ -543,10 +569,12 @@ EXPLAIN
"rows": 140,
"selectivity_pct": 9.333333333
},
- "rows": 11,
- "filtered": 9.333333015,
+ "loops": 60,
+ "rows": 15,
+ "cost": 0.306111985,
+ "filtered": 6.666666508,
"attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'",
- "first_match": "nation"
+ "first_match": "customer"
}
}
]
@@ -558,38 +586,38 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
-Customer#000000007 9561.95
-Customer#000000008 6819.74
+Customer#000000059 3458.6
+Customer#000000106 3288.42
Customer#000000017 6.34
-Customer#000000019 8914.71
+Customer#000000047 274.58
+Customer#000000092 1182.91
+Customer#000000101 7470.96
Customer#000000022 591.98
-Customer#000000025 7133.7
-Customer#000000028 1007.18
-Customer#000000037 -917.75
Customer#000000040 1335.3
-Customer#000000047 274.58
-Customer#000000059 3458.6
-Customer#000000061 1536.24
Customer#000000064 -646.64
-Customer#000000067 8166.59
-Customer#000000077 1738.87
-Customer#000000082 9468.34
+Customer#000000122 7865.46
+Customer#000000028 1007.18
+Customer#000000037 -917.75
Customer#000000091 4643.14
-Customer#000000092 1182.91
+Customer#000000115 7508.92
+Customer#000000067 8166.59
Customer#000000094 5500.11
-Customer#000000097 2164.48
-Customer#000000101 7470.96
Customer#000000103 2757.45
-Customer#000000106 3288.42
-Customer#000000115 7508.92
-Customer#000000121 6428.32
-Customer#000000122 7865.46
-Customer#000000124 1842.49
-Customer#000000127 9280.71
Customer#000000130 5073.58
-Customer#000000133 2314.67
Customer#000000139 7897.78
Customer#000000142 2209.81
+Customer#000000025 7133.7
+Customer#000000008 6819.74
+Customer#000000061 1536.24
+Customer#000000077 1738.87
+Customer#000000097 2164.48
+Customer#000000121 6428.32
+Customer#000000133 2314.67
+Customer#000000007 9561.95
+Customer#000000019 8914.71
+Customer#000000082 9468.34
+Customer#000000124 1842.49
+Customer#000000127 9280.71
explain
update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -597,9 +625,9 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL PRIMARY,i_c_nationkey NULL NULL NULL 150 Using where
-1 PRIMARY nation eq_ref|filter PRIMARY,i_n_regionkey PRIMARY|i_n_regionkey 4|5 dbt3_s001.customer.c_nationkey 1 (40%) Using where; Using rowid filter
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (9%) Using where; FirstMatch(nation); Using rowid filter
+1 PRIMARY nation ALL PRIMARY,i_n_regionkey NULL NULL NULL 25 Using where
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (9%) Using where; FirstMatch(customer); Using rowid filter
explain format=json
update customer set c_acctbal = c_acctbal+10 where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -610,37 +638,33 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.40015207,
"nested_loop": [
{
"table": {
- "table_name": "customer",
+ "table_name": "nation",
"access_type": "ALL",
- "possible_keys": ["PRIMARY", "i_c_nationkey"],
- "rows": 150,
- "filtered": 100,
- "attached_condition": "customer.c_nationkey is not null"
+ "possible_keys": ["PRIMARY", "i_n_regionkey"],
+ "loops": 1,
+ "rows": 25,
+ "cost": 0.013945725,
+ "filtered": 40,
+ "attached_condition": "nation.n_regionkey in (1,2)"
}
},
{
"table": {
- "table_name": "nation",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_n_regionkey"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["n_nationkey"],
- "ref": ["dbt3_s001.customer.c_nationkey"],
- "rowid_filter": {
- "range": {
- "key": "i_n_regionkey",
- "used_key_parts": ["n_regionkey"]
- },
- "rows": 10,
- "selectivity_pct": 40
- },
- "rows": 1,
- "filtered": 40,
- "attached_condition": "nation.n_regionkey in (1,2)"
+ "table_name": "customer",
+ "access_type": "ref",
+ "possible_keys": ["PRIMARY", "i_c_nationkey"],
+ "key": "i_c_nationkey",
+ "key_length": "5",
+ "used_key_parts": ["c_nationkey"],
+ "ref": ["dbt3_s001.nation.n_nationkey"],
+ "loops": 10,
+ "rows": 6,
+ "cost": 0.08009436,
+ "filtered": 100
}
},
{
@@ -660,10 +684,12 @@ EXPLAIN
"rows": 140,
"selectivity_pct": 9.333333333
},
- "rows": 11,
- "filtered": 9.333333015,
+ "loops": 60,
+ "rows": 15,
+ "cost": 0.306111985,
+ "filtered": 6.666666508,
"attached_condition": "orders.o_orderDATE between '1992-10-09' and '1993-06-08'",
- "first_match": "nation"
+ "first_match": "customer"
}
}
]
@@ -680,38 +706,38 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
-Customer#000000007 9571.95
-Customer#000000008 6829.74
+Customer#000000059 3468.6
+Customer#000000106 3298.42
Customer#000000017 16.34
-Customer#000000019 8924.71
+Customer#000000047 284.58
+Customer#000000092 1192.91
+Customer#000000101 7480.96
Customer#000000022 601.98
-Customer#000000025 7143.7
-Customer#000000028 1017.18
-Customer#000000037 -907.75
Customer#000000040 1345.3
-Customer#000000047 284.58
-Customer#000000059 3468.6
-Customer#000000061 1546.24
Customer#000000064 -636.64
-Customer#000000067 8176.59
-Customer#000000077 1748.87
-Customer#000000082 9478.34
+Customer#000000122 7875.46
+Customer#000000028 1017.18
+Customer#000000037 -907.75
Customer#000000091 4653.14
-Customer#000000092 1192.91
+Customer#000000115 7518.92
+Customer#000000067 8176.59
Customer#000000094 5510.11
-Customer#000000097 2174.48
-Customer#000000101 7480.96
Customer#000000103 2767.45
-Customer#000000106 3298.42
-Customer#000000115 7518.92
-Customer#000000121 6438.32
-Customer#000000122 7875.46
-Customer#000000124 1852.49
-Customer#000000127 9290.71
Customer#000000130 5083.58
-Customer#000000133 2324.67
Customer#000000139 7907.78
Customer#000000142 2219.81
+Customer#000000025 7143.7
+Customer#000000008 6829.74
+Customer#000000061 1546.24
+Customer#000000077 1748.87
+Customer#000000097 2174.48
+Customer#000000121 6438.32
+Customer#000000133 2324.67
+Customer#000000007 9571.95
+Customer#000000019 8924.71
+Customer#000000082 9478.34
+Customer#000000124 1852.49
+Customer#000000127 9290.71
update customer set c_acctbal = c_acctbal-10 where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
and
@@ -723,38 +749,38 @@ and
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-10-09' and '1993-06-08');
c_name c_acctbal
-Customer#000000007 9561.95
-Customer#000000008 6819.74
+Customer#000000059 3458.6
+Customer#000000106 3288.42
Customer#000000017 6.34
-Customer#000000019 8914.71
+Customer#000000047 274.58
+Customer#000000092 1182.91
+Customer#000000101 7470.96
Customer#000000022 591.98
-Customer#000000025 7133.7
-Customer#000000028 1007.18
-Customer#000000037 -917.75
Customer#000000040 1335.3
-Customer#000000047 274.58
-Customer#000000059 3458.6
-Customer#000000061 1536.24
Customer#000000064 -646.64
-Customer#000000067 8166.59
-Customer#000000077 1738.87
-Customer#000000082 9468.34
+Customer#000000122 7865.46
+Customer#000000028 1007.18
+Customer#000000037 -917.75
Customer#000000091 4643.14
-Customer#000000092 1182.91
+Customer#000000115 7508.92
+Customer#000000067 8166.59
Customer#000000094 5500.11
-Customer#000000097 2164.48
-Customer#000000101 7470.96
Customer#000000103 2757.45
-Customer#000000106 3288.42
-Customer#000000115 7508.92
-Customer#000000121 6428.32
-Customer#000000122 7865.46
-Customer#000000124 1842.49
-Customer#000000127 9280.71
Customer#000000130 5073.58
-Customer#000000133 2314.67
Customer#000000139 7897.78
Customer#000000142 2209.81
+Customer#000000025 7133.7
+Customer#000000008 6819.74
+Customer#000000061 1536.24
+Customer#000000077 1738.87
+Customer#000000097 2164.48
+Customer#000000121 6428.32
+Customer#000000133 2314.67
+Customer#000000007 9561.95
+Customer#000000019 8914.71
+Customer#000000082 9468.34
+Customer#000000124 1842.49
+Customer#000000127 9280.71
set optimizer_switch='materialization=default';
explain
select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU')
@@ -763,8 +789,8 @@ c_custkey in (select o_custkey from orders
where o_orderDATE between "1992-01-09" and "1993-01-08");
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (14%) Using where; FirstMatch(customer); Using rowid filter
select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where n_name='PERU')
and
c_custkey in (select o_custkey from orders
@@ -783,8 +809,8 @@ c_custkey in (select o_custkey from orders
where o_orderDATE between "1992-01-09" and "1993-01-08");
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY nation ref PRIMARY,i_n_name i_n_name 26 const 1 Using index condition
-1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 11
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (14%) Using where; FirstMatch(customer); Using rowid filter
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (14%) Using where; FirstMatch(customer); Using rowid filter
update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where n_name='PERU')
and
c_custkey in (select o_custkey from orders
@@ -817,116 +843,155 @@ Customer#000000121 6428.32
Customer#000000133 2314.67
# Materialization
# ===============
+set optimizer_switch='firstmatch=off';
explain
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
-1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1
-2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where
-explain format=json
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "nested_loop": [
- {
- "table": {
- "table_name": "<subquery2>",
- "access_type": "ALL",
- "possible_keys": ["distinct_key"],
- "rows": 28,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "nested_loop": [
- {
- "table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["i_o_orderdate", "i_o_custkey"],
- "key": "i_o_orderdate",
- "key_length": "4",
- "used_key_parts": ["o_orderDATE"],
- "rows": 28,
- "filtered": 100,
- "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'",
- "attached_condition": "orders.o_custkey is not null"
- }
- }
- ]
- }
- }
- }
- },
- {
- "table": {
- "table_name": "customer",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["c_custkey"],
- "ref": ["dbt3_s001.orders.o_custkey"],
- "rows": 1,
- "filtered": 100
- }
- }
- ]
- }
-}
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+1 PRIMARY nation range PRIMARY,i_n_name i_n_name 26 NULL 4 Using index condition
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
+3 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
c_name c_acctbal
+Customer#000000014 5266.3
+Customer#000000059 3458.6
+Customer#000000106 3288.42
+Customer#000000067 8166.59
+Customer#000000094 5500.11
+Customer#000000103 2757.45
+Customer#000000130 5073.58
+Customer#000000139 7897.78
+Customer#000000142 2209.81
Customer#000000025 7133.7
-Customer#000000013 3857.34
-Customer#000000065 8795.16
-Customer#000000032 3471.53
-Customer#000000023 3332.02
-Customer#000000035 1228.24
-Customer#000000091 4643.14
-Customer#000000016 4681.03
+Customer#000000038 6345.11
Customer#000000098 -551.37
-Customer#000000037 -917.75
-Customer#000000136 -842.39
-Customer#000000118 3582.37
-Customer#000000022 591.98
-Customer#000000005 794.47
-Customer#000000109 -716.1
+Customer#000000113 2912
+Customer#000000008 6819.74
+Customer#000000035 1228.24
+Customer#000000061 1536.24
+Customer#000000077 1738.87
+Customer#000000097 2164.48
+Customer#000000121 6428.32
+Customer#000000133 2314.67
+explain
+update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY nation range PRIMARY,i_n_name i_n_name 26 NULL 4 Using index condition
+1 PRIMARY customer ref PRIMARY,i_c_nationkey i_c_nationkey 5 dbt3_s001.nation.n_nationkey 6
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
+3 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
+update customer set c_acctbal = c_acctbal+20 where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+c_name c_acctbal
+Customer#000000014 5286.3
+Customer#000000059 3478.6
+Customer#000000106 3308.42
+Customer#000000067 8186.59
+Customer#000000094 5520.11
+Customer#000000103 2777.45
+Customer#000000130 5093.58
+Customer#000000139 7917.78
+Customer#000000142 2229.81
+Customer#000000025 7153.7
+Customer#000000038 6365.11
+Customer#000000098 -531.37
+Customer#000000113 2932
+Customer#000000008 6839.74
+Customer#000000035 1248.24
+Customer#000000061 1556.24
+Customer#000000077 1758.87
+Customer#000000097 2184.48
+Customer#000000121 6448.32
+Customer#000000133 2334.67
+update customer set c_acctbal = c_acctbal-20 where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+select c_name, c_acctbal from customer where c_nationkey in (select n_nationkey from nation where
+n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+and
+c_custkey in (select o_custkey from orders
+where o_orderDATE between "1992-01-09" and "1995-01-08");
+c_name c_acctbal
+Customer#000000014 5266.3
+Customer#000000059 3458.6
+Customer#000000106 3288.42
+Customer#000000067 8166.59
+Customer#000000094 5500.11
+Customer#000000103 2757.45
+Customer#000000130 5073.58
+Customer#000000139 7897.78
+Customer#000000142 2209.81
+Customer#000000025 7133.7
Customer#000000038 6345.11
-Customer#000000076 5745.33
-Customer#000000056 6530.86
-Customer#000000040 1335.3
-Customer#000000116 8403.99
-Customer#000000115 7508.92
-Customer#000000140 9963.15
-Customer#000000017 6.34
-Customer#000000052 5630.28
+Customer#000000098 -551.37
+Customer#000000113 2912
+Customer#000000008 6819.74
+Customer#000000035 1228.24
+Customer#000000061 1536.24
+Customer#000000077 1738.87
+Customer#000000097 2164.48
+Customer#000000121 6428.32
+Customer#000000133 2314.67
+set optimizer_switch='firstmatch=default';
explain
-update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
-1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1
-2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 28 Using index condition; Using where
+1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
explain format=json
-update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
EXPLAIN
{
"query_block": {
"select_id": 1,
+ "cost": 0.382051418,
"nested_loop": [
{
"table": {
- "table_name": "<subquery2>",
+ "table_name": "customer",
"access_type": "ALL",
+ "possible_keys": ["PRIMARY"],
+ "loops": 1,
+ "rows": 150,
+ "cost": 0.03493875,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
"possible_keys": ["distinct_key"],
- "rows": 28,
+ "key": "distinct_key",
+ "key_length": "4",
+ "used_key_parts": ["o_custkey"],
+ "ref": ["func"],
+ "rows": 1,
"filtered": 100,
"materialized": {
"unique": 1,
@@ -936,112 +1001,35 @@ EXPLAIN
{
"table": {
"table_name": "orders",
- "access_type": "range",
+ "access_type": "ALL",
"possible_keys": ["i_o_orderdate", "i_o_custkey"],
- "key": "i_o_orderdate",
- "key_length": "4",
- "used_key_parts": ["o_orderDATE"],
- "rows": 28,
- "filtered": 100,
- "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'",
- "attached_condition": "orders.o_custkey is not null"
+ "loops": 1,
+ "rows": 1500,
+ "cost": 0.2532975,
+ "filtered": 16.13333321,
+ "attached_condition": "orders.o_orderDATE between '1992-01-09' and '1993-03-08'"
}
}
]
}
}
}
- },
- {
- "table": {
- "table_name": "customer",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["c_custkey"],
- "ref": ["dbt3_s001.orders.o_custkey"],
- "rows": 1,
- "filtered": 100
- }
}
]
}
}
-update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-c_name c_acctbal
-Customer#000000025 7138.7
-Customer#000000013 3862.34
-Customer#000000065 8800.16
-Customer#000000032 3476.53
-Customer#000000023 3337.02
-Customer#000000035 1233.24
-Customer#000000091 4648.14
-Customer#000000016 4686.03
-Customer#000000098 -546.37
-Customer#000000037 -912.75
-Customer#000000136 -837.39
-Customer#000000118 3587.37
-Customer#000000022 596.98
-Customer#000000005 799.47
-Customer#000000109 -711.1
-Customer#000000038 6350.11
-Customer#000000076 5750.33
-Customer#000000056 6535.86
-Customer#000000040 1340.3
-Customer#000000116 8408.99
-Customer#000000115 7513.92
-Customer#000000140 9968.15
-Customer#000000017 11.34
-Customer#000000052 5635.28
-update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-c_name c_acctbal
-Customer#000000025 7133.7
-Customer#000000013 3857.34
-Customer#000000065 8795.16
-Customer#000000032 3471.53
-Customer#000000023 3332.02
-Customer#000000035 1228.24
-Customer#000000091 4643.14
-Customer#000000016 4681.03
-Customer#000000098 -551.37
-Customer#000000037 -917.75
-Customer#000000136 -842.39
-Customer#000000118 3582.37
-Customer#000000022 591.98
-Customer#000000005 794.47
-Customer#000000109 -716.1
-Customer#000000038 6345.11
-Customer#000000076 5745.33
-Customer#000000056 6530.86
-Customer#000000040 1335.3
-Customer#000000116 8403.99
-Customer#000000115 7508.92
-Customer#000000140 9963.15
-Customer#000000017 6.34
-Customer#000000052 5630.28
-explain
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
Customer#000000001 711.56
Customer#000000002 121.65
+Customer#000000005 794.47
Customer#000000007 9561.95
Customer#000000008 6819.74
Customer#000000010 2753.54
Customer#000000011 -272.6
+Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
Customer#000000019 8914.71
@@ -1051,18 +1039,28 @@ Customer#000000025 7133.7
Customer#000000028 1007.18
Customer#000000029 7618.27
Customer#000000031 5236.89
+Customer#000000032 3471.53
Customer#000000034 8589.7
+Customer#000000035 1228.24
Customer#000000037 -917.75
+Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
Customer#000000043 9904.28
Customer#000000044 7315.94
Customer#000000046 5744.59
Customer#000000047 274.58
Customer#000000049 4573.94
+Customer#000000052 5630.28
Customer#000000053 4113.64
Customer#000000055 4572.11
+Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
Customer#000000061 1536.24
+Customer#000000062 595.61
Customer#000000064 -646.64
+Customer#000000065 8795.16
Customer#000000067 8166.59
Customer#000000070 4867.52
Customer#000000071 -611.19
@@ -1076,22 +1074,29 @@ Customer#000000083 6463.51
Customer#000000085 3386.64
Customer#000000086 3306.32
Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
Customer#000000092 1182.91
+Customer#000000094 5500.11
Customer#000000095 5327.38
Customer#000000097 2164.48
+Customer#000000098 -551.37
Customer#000000100 9889.89
Customer#000000101 7470.96
Customer#000000103 2757.45
Customer#000000104 -588.38
Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
Customer#000000110 7462.99
Customer#000000112 2953.35
+Customer#000000115 7508.92
+Customer#000000116 8403.99
Customer#000000118 3582.37
Customer#000000121 6428.32
Customer#000000122 7865.46
Customer#000000127 9280.71
+Customer#000000128 -986.96
Customer#000000130 5073.58
Customer#000000131 8595.53
Customer#000000133 2314.67
@@ -1099,100 +1104,183 @@ Customer#000000134 4608.9
Customer#000000136 -842.39
Customer#000000137 7838.3
Customer#000000139 7897.78
+Customer#000000140 9963.15
Customer#000000142 2209.81
Customer#000000143 2186.5
+Customer#000000145 9748.93
Customer#000000148 2135.6
Customer#000000149 8959.65
explain
-update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
+update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where
-update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
-c_name c_acctbal
-Customer#000000001 712.56
-Customer#000000002 122.65
-Customer#000000007 9562.95
-Customer#000000008 6820.74
-Customer#000000010 2754.54
-Customer#000000011 -271.6
-Customer#000000016 4682.03
-Customer#000000017 7.34
-Customer#000000019 8915.71
-Customer#000000022 592.98
-Customer#000000023 3333.02
-Customer#000000025 7134.7
-Customer#000000028 1008.18
-Customer#000000029 7619.27
-Customer#000000031 5237.89
-Customer#000000034 8590.7
-Customer#000000037 -916.75
-Customer#000000040 1336.3
-Customer#000000043 9905.28
-Customer#000000044 7316.94
-Customer#000000046 5745.59
-Customer#000000047 275.58
-Customer#000000049 4574.94
-Customer#000000053 4114.64
-Customer#000000055 4573.11
-Customer#000000061 1537.24
-Customer#000000064 -645.64
-Customer#000000067 8167.59
-Customer#000000070 4868.52
-Customer#000000071 -610.19
-Customer#000000073 4289.5
-Customer#000000074 2765.43
-Customer#000000076 5746.33
-Customer#000000079 5122.28
-Customer#000000080 7384.53
-Customer#000000082 9469.34
-Customer#000000083 6464.51
-Customer#000000085 3387.64
-Customer#000000086 3307.32
-Customer#000000088 8032.44
-Customer#000000091 4644.14
-Customer#000000092 1183.91
-Customer#000000095 5328.38
-Customer#000000097 2165.48
-Customer#000000100 9890.89
-Customer#000000101 7471.96
-Customer#000000103 2758.45
-Customer#000000104 -587.38
-Customer#000000106 3289.42
-Customer#000000109 -715.1
-Customer#000000110 7463.99
-Customer#000000112 2954.35
-Customer#000000118 3583.37
-Customer#000000121 6429.32
-Customer#000000122 7866.46
-Customer#000000127 9281.71
-Customer#000000130 5074.58
-Customer#000000131 8596.53
-Customer#000000133 2315.67
-Customer#000000134 4609.9
-Customer#000000136 -841.39
-Customer#000000137 7839.3
-Customer#000000139 7898.78
-Customer#000000142 2210.81
-Customer#000000143 2187.5
-Customer#000000148 2136.6
-Customer#000000149 8960.65
-update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
+2 MATERIALIZED orders ALL i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where
+explain format=json
+update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.382051418,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "customer",
+ "access_type": "ALL",
+ "possible_keys": ["PRIMARY"],
+ "loops": 1,
+ "rows": 150,
+ "cost": 0.03493875,
+ "filtered": 100
+ }
+ },
+ {
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
+ "key_length": "4",
+ "used_key_parts": ["o_custkey"],
+ "ref": ["func"],
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "ALL",
+ "possible_keys": ["i_o_orderdate", "i_o_custkey"],
+ "loops": 1,
+ "rows": 1500,
+ "cost": 0.2532975,
+ "filtered": 16.13333321,
+ "attached_condition": "orders.o_orderDATE between '1992-01-09' and '1993-03-08'"
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-06-09' and '1993-01-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
+c_name c_acctbal
+Customer#000000001 716.56
+Customer#000000002 126.65
+Customer#000000005 799.47
+Customer#000000007 9566.95
+Customer#000000008 6824.74
+Customer#000000010 2758.54
+Customer#000000011 -267.6
+Customer#000000013 3862.34
+Customer#000000014 5271.3
+Customer#000000016 4686.03
+Customer#000000017 11.34
+Customer#000000019 8919.71
+Customer#000000022 596.98
+Customer#000000023 3337.02
+Customer#000000025 7138.7
+Customer#000000028 1012.18
+Customer#000000029 7623.27
+Customer#000000031 5241.89
+Customer#000000032 3476.53
+Customer#000000034 8594.7
+Customer#000000035 1233.24
+Customer#000000037 -912.75
+Customer#000000038 6350.11
+Customer#000000040 1340.3
+Customer#000000041 275.95
+Customer#000000043 9909.28
+Customer#000000044 7320.94
+Customer#000000046 5749.59
+Customer#000000047 279.58
+Customer#000000049 4578.94
+Customer#000000052 5635.28
+Customer#000000053 4118.64
+Customer#000000055 4577.11
+Customer#000000056 6535.86
+Customer#000000058 6483.46
+Customer#000000059 3463.6
+Customer#000000061 1541.24
+Customer#000000062 600.61
+Customer#000000064 -641.64
+Customer#000000065 8800.16
+Customer#000000067 8171.59
+Customer#000000070 4872.52
+Customer#000000071 -606.19
+Customer#000000073 4293.5
+Customer#000000074 2769.43
+Customer#000000076 5750.33
+Customer#000000079 5126.28
+Customer#000000080 7388.53
+Customer#000000082 9473.34
+Customer#000000083 6468.51
+Customer#000000085 3391.64
+Customer#000000086 3311.32
+Customer#000000088 8036.44
+Customer#000000089 1535.76
+Customer#000000091 4648.14
+Customer#000000092 1187.91
+Customer#000000094 5505.11
+Customer#000000095 5332.38
+Customer#000000097 2169.48
+Customer#000000098 -546.37
+Customer#000000100 9894.89
+Customer#000000101 7475.96
+Customer#000000103 2762.45
+Customer#000000104 -583.38
+Customer#000000106 3293.42
+Customer#000000107 2519.15
+Customer#000000109 -711.1
+Customer#000000110 7467.99
+Customer#000000112 2958.35
+Customer#000000115 7513.92
+Customer#000000116 8408.99
+Customer#000000118 3587.37
+Customer#000000121 6433.32
+Customer#000000122 7870.46
+Customer#000000127 9285.71
+Customer#000000128 -981.96
+Customer#000000130 5078.58
+Customer#000000131 8600.53
+Customer#000000133 2319.67
+Customer#000000134 4613.9
+Customer#000000136 -837.39
+Customer#000000137 7843.3
+Customer#000000139 7902.78
+Customer#000000140 9968.15
+Customer#000000142 2214.81
+Customer#000000143 2191.5
+Customer#000000145 9753.93
+Customer#000000148 2140.6
+Customer#000000149 8964.65
+update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
Customer#000000001 711.56
Customer#000000002 121.65
+Customer#000000005 794.47
Customer#000000007 9561.95
Customer#000000008 6819.74
Customer#000000010 2753.54
Customer#000000011 -272.6
+Customer#000000013 3857.34
+Customer#000000014 5266.3
Customer#000000016 4681.03
Customer#000000017 6.34
Customer#000000019 8914.71
@@ -1202,18 +1290,28 @@ Customer#000000025 7133.7
Customer#000000028 1007.18
Customer#000000029 7618.27
Customer#000000031 5236.89
+Customer#000000032 3471.53
Customer#000000034 8589.7
+Customer#000000035 1228.24
Customer#000000037 -917.75
+Customer#000000038 6345.11
Customer#000000040 1335.3
+Customer#000000041 270.95
Customer#000000043 9904.28
Customer#000000044 7315.94
Customer#000000046 5744.59
Customer#000000047 274.58
Customer#000000049 4573.94
+Customer#000000052 5630.28
Customer#000000053 4113.64
Customer#000000055 4572.11
+Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
Customer#000000061 1536.24
+Customer#000000062 595.61
Customer#000000064 -646.64
+Customer#000000065 8795.16
Customer#000000067 8166.59
Customer#000000070 4867.52
Customer#000000071 -611.19
@@ -1227,22 +1325,29 @@ Customer#000000083 6463.51
Customer#000000085 3386.64
Customer#000000086 3306.32
Customer#000000088 8031.44
+Customer#000000089 1530.76
Customer#000000091 4643.14
Customer#000000092 1182.91
+Customer#000000094 5500.11
Customer#000000095 5327.38
Customer#000000097 2164.48
+Customer#000000098 -551.37
Customer#000000100 9889.89
Customer#000000101 7470.96
Customer#000000103 2757.45
Customer#000000104 -588.38
Customer#000000106 3288.42
+Customer#000000107 2514.15
Customer#000000109 -716.1
Customer#000000110 7462.99
Customer#000000112 2953.35
+Customer#000000115 7508.92
+Customer#000000116 8403.99
Customer#000000118 3582.37
Customer#000000121 6428.32
Customer#000000122 7865.46
Customer#000000127 9280.71
+Customer#000000128 -986.96
Customer#000000130 5073.58
Customer#000000131 8595.53
Customer#000000133 2314.67
@@ -1250,115 +1355,274 @@ Customer#000000134 4608.9
Customer#000000136 -842.39
Customer#000000137 7838.3
Customer#000000139 7897.78
+Customer#000000140 9963.15
Customer#000000142 2209.81
Customer#000000143 2186.5
+Customer#000000145 9748.93
Customer#000000148 2135.6
Customer#000000149 8959.65
-# Materialization SJM
-# ===================
explain
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
+where o_orderDATE between '1992-06-09' and '1993-01-08');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
-1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1
-2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary
-explain format=json
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "nested_loop": [
- {
- "table": {
- "table_name": "<subquery2>",
- "access_type": "ALL",
- "possible_keys": ["distinct_key"],
- "rows": 28,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "having_condition": "count(orders.o_custkey) > 1",
- "temporary_table": {
- "nested_loop": [
- {
- "table": {
- "table_name": "orders",
- "access_type": "range",
- "possible_keys": ["i_o_orderdate"],
- "key": "i_o_orderdate",
- "key_length": "4",
- "used_key_parts": ["o_orderDATE"],
- "rows": 28,
- "filtered": 100,
- "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'"
- }
- }
- ]
- }
- }
- }
- }
- },
- {
- "table": {
- "table_name": "customer",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["c_custkey"],
- "ref": ["<subquery2>.o_custkey"],
- "rows": 1,
- "filtered": 100
- }
- }
- ]
- }
-}
+1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
+where o_orderDATE between '1992-06-09' and '1993-01-08');
c_name c_acctbal
-Customer#000000013 3857.34
-Customer#000000032 3471.53
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
+Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
+Customer#000000023 3332.02
+Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
+Customer#000000034 8589.7
Customer#000000037 -917.75
-Customer#000000118 3582.37
-Customer#000000056 6530.86
-explain
-update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
-1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1
-2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary
-explain format=json
-update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "nested_loop": [
- {
- "table": {
+Customer#000000040 1335.3
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
+Customer#000000053 4113.64
+Customer#000000055 4572.11
+Customer#000000061 1536.24
+Customer#000000064 -646.64
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
+Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000148 2135.6
+Customer#000000149 8959.65
+explain
+update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-06-09' and '1993-01-08');
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED orders range i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 114 Using index condition; Using where
+update customer set c_acctbal = c_acctbal+1 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-06-09' and '1993-01-08');
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-06-09' and '1993-01-08');
+c_name c_acctbal
+Customer#000000001 712.56
+Customer#000000002 122.65
+Customer#000000007 9562.95
+Customer#000000008 6820.74
+Customer#000000010 2754.54
+Customer#000000011 -271.6
+Customer#000000016 4682.03
+Customer#000000017 7.34
+Customer#000000019 8915.71
+Customer#000000022 592.98
+Customer#000000023 3333.02
+Customer#000000025 7134.7
+Customer#000000028 1008.18
+Customer#000000029 7619.27
+Customer#000000031 5237.89
+Customer#000000034 8590.7
+Customer#000000037 -916.75
+Customer#000000040 1336.3
+Customer#000000043 9905.28
+Customer#000000044 7316.94
+Customer#000000046 5745.59
+Customer#000000047 275.58
+Customer#000000049 4574.94
+Customer#000000053 4114.64
+Customer#000000055 4573.11
+Customer#000000061 1537.24
+Customer#000000064 -645.64
+Customer#000000067 8167.59
+Customer#000000070 4868.52
+Customer#000000071 -610.19
+Customer#000000073 4289.5
+Customer#000000074 2765.43
+Customer#000000076 5746.33
+Customer#000000079 5122.28
+Customer#000000080 7384.53
+Customer#000000082 9469.34
+Customer#000000083 6464.51
+Customer#000000085 3387.64
+Customer#000000086 3307.32
+Customer#000000088 8032.44
+Customer#000000091 4644.14
+Customer#000000092 1183.91
+Customer#000000095 5328.38
+Customer#000000097 2165.48
+Customer#000000100 9890.89
+Customer#000000101 7471.96
+Customer#000000103 2758.45
+Customer#000000104 -587.38
+Customer#000000106 3289.42
+Customer#000000109 -715.1
+Customer#000000110 7463.99
+Customer#000000112 2954.35
+Customer#000000118 3583.37
+Customer#000000121 6429.32
+Customer#000000122 7866.46
+Customer#000000127 9281.71
+Customer#000000130 5074.58
+Customer#000000131 8596.53
+Customer#000000133 2315.67
+Customer#000000134 4609.9
+Customer#000000136 -841.39
+Customer#000000137 7839.3
+Customer#000000139 7898.78
+Customer#000000142 2210.81
+Customer#000000143 2187.5
+Customer#000000148 2136.6
+Customer#000000149 8960.65
+update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-06-09' and '1993-01-08');
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-06-09' and '1993-01-08');
+c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
+Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
+Customer#000000023 3332.02
+Customer#000000025 7133.7
+Customer#000000028 1007.18
+Customer#000000029 7618.27
+Customer#000000031 5236.89
+Customer#000000034 8589.7
+Customer#000000037 -917.75
+Customer#000000040 1335.3
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
+Customer#000000053 4113.64
+Customer#000000055 4572.11
+Customer#000000061 1536.24
+Customer#000000064 -646.64
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
+Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000148 2135.6
+Customer#000000149 8959.65
+# Materialization SJM
+# ===================
+explain
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
+1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1
+2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary
+explain format=json
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.085533248,
+ "nested_loop": [
+ {
+ "table": {
"table_name": "<subquery2>",
"access_type": "ALL",
"possible_keys": ["distinct_key"],
+ "loops": 1,
"rows": 28,
+ "cost": 0.03691572,
"filtered": 100,
"materialized": {
"unique": 1,
"query_block": {
"select_id": 2,
+ "cost": 0.053826401,
"having_condition": "count(orders.o_custkey) > 1",
"temporary_table": {
"nested_loop": [
@@ -1370,7 +1634,9 @@ EXPLAIN
"key": "i_o_orderdate",
"key_length": "4",
"used_key_parts": ["o_orderDATE"],
+ "loops": 1,
"rows": 28,
+ "cost": 0.035889016,
"filtered": 100,
"index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'"
}
@@ -1390,28 +1656,15 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["c_custkey"],
"ref": ["<subquery2>.o_custkey"],
+ "loops": 28,
"rows": 1,
+ "cost": 0.048617528,
"filtered": 100
}
}
]
}
}
-update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
-c_name c_acctbal
-Customer#000000013 3852.34
-Customer#000000032 3466.53
-Customer#000000037 -922.75
-Customer#000000118 3577.37
-Customer#000000056 6525.86
-update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08'
- group by o_custkey having count(o_custkey) > 1);
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1992-03-08'
group by o_custkey having count(o_custkey) > 1);
@@ -1422,24 +1675,122 @@ Customer#000000037 -917.75
Customer#000000118 3582.37
Customer#000000056 6530.86
explain
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1993-03-08'
- group by o_custkey having count(o_custkey) > 5);
+update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1
-2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1993-03-08'
- group by o_custkey having count(o_custkey) > 5);
-c_name c_acctbal
-Customer#000000007 9561.95
-Customer#000000016 4681.03
-Customer#000000037 -917.75
-Customer#000000046 5744.59
-Customer#000000091 4643.14
-Customer#000000103 2757.45
-Customer#000000118 3582.37
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 28
+1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 <subquery2>.o_custkey 1
+2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 28 Using index condition; Using temporary
+explain format=json
+update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "cost": 0.085533248,
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "ALL",
+ "possible_keys": ["distinct_key"],
+ "loops": 1,
+ "rows": 28,
+ "cost": 0.03691572,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "cost": 0.053826401,
+ "having_condition": "count(orders.o_custkey) > 1",
+ "temporary_table": {
+ "nested_loop": [
+ {
+ "table": {
+ "table_name": "orders",
+ "access_type": "range",
+ "possible_keys": ["i_o_orderdate"],
+ "key": "i_o_orderdate",
+ "key_length": "4",
+ "used_key_parts": ["o_orderDATE"],
+ "loops": 1,
+ "rows": 28,
+ "cost": 0.035889016,
+ "filtered": 100,
+ "index_condition": "orders.o_orderDATE between '1992-01-09' and '1992-03-08'"
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ {
+ "table": {
+ "table_name": "customer",
+ "access_type": "eq_ref",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["c_custkey"],
+ "ref": ["<subquery2>.o_custkey"],
+ "loops": 28,
+ "rows": 1,
+ "cost": 0.048617528,
+ "filtered": 100
+ }
+ }
+ ]
+ }
+}
+update customer set c_acctbal = c_acctbal-5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+c_name c_acctbal
+Customer#000000013 3852.34
+Customer#000000032 3466.53
+Customer#000000037 -922.75
+Customer#000000118 3577.37
+Customer#000000056 6525.86
+update customer set c_acctbal = c_acctbal+5 where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1992-03-08'
+ group by o_custkey having count(o_custkey) > 1);
+c_name c_acctbal
+Customer#000000013 3857.34
+Customer#000000032 3471.53
+Customer#000000037 -917.75
+Customer#000000118 3582.37
+Customer#000000056 6530.86
+explain
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08'
+ group by o_custkey having count(o_custkey) > 5);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1
+2 MATERIALIZED orders ALL i_o_orderdate NULL NULL NULL 1500 Using where; Using temporary
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08'
+ group by o_custkey having count(o_custkey) > 5);
+c_name c_acctbal
+Customer#000000007 9561.95
+Customer#000000016 4681.03
+Customer#000000037 -917.75
+Customer#000000046 5744.59
+Customer#000000091 4643.14
+Customer#000000103 2757.45
+Customer#000000118 3582.37
Customer#000000133 2314.67
Customer#000000134 4608.9
explain
@@ -1449,7 +1800,7 @@ where o_orderDATE between '1992-01-09' and '1993-03-08'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY customer ALL PRIMARY NULL NULL NULL 150
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.customer.c_custkey 1
-2 MATERIALIZED orders range i_o_orderdate i_o_orderdate 4 NULL 242 Using index condition; Using temporary
+2 MATERIALIZED orders ALL i_o_orderdate NULL NULL NULL 1500 Using where; Using temporary
update customer set c_acctbal = c_acctbal-1 where c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1993-03-08'
group by o_custkey having count(o_custkey) > 5);
@@ -1550,6 +1901,7 @@ o_orderkey o_totalprice
deallocate prepare stmt;
# FirstMatch PS
# =============
+set optimizer_switch='materialization=off';
prepare stmt from "
update customer set c_acctbal = c_acctbal+? where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -1715,125 +2067,386 @@ Customer#000000082 9468.34
Customer#000000124 1842.49
Customer#000000127 9280.71
deallocate prepare stmt;
+set optimizer_switch='materialization=default';
# Materialization PS
# ==================
prepare stmt from "
update customer set c_acctbal = c_acctbal+? where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
";
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7133.7
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
-Customer#000000065 8795.16
-Customer#000000032 3471.53
+Customer#000000014 5266.3
+Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000023 3332.02
+Customer#000000025 7133.7
+Customer#000000028 1007.1799999999998
+Customer#000000029 7618.27
+Customer#000000031 5236.89
+Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
-Customer#000000091 4643.14
-Customer#000000016 4681.03
-Customer#000000098 -551.37
Customer#000000037 -917.75
-Customer#000000136 -842.39
-Customer#000000118 3582.37
-Customer#000000022 591.98
-Customer#000000005 794.47
-Customer#000000109 -716.1
Customer#000000038 6345.11
-Customer#000000076 5745.33
-Customer#000000056 6530.86
Customer#000000040 1335.3
-Customer#000000116 8403.99
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
+Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
+Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
+Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
+Customer#000000116 8403.99
+Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
-Customer#000000017 6.34
-Customer#000000052 5630.28
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
set @a1=7;
execute stmt using @a1;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7140.7
+Customer#000000001 718.56
+Customer#000000002 128.65
+Customer#000000005 801.47
+Customer#000000007 9568.95
+Customer#000000008 6826.74
+Customer#000000010 2760.54
+Customer#000000011 -265.6
Customer#000000013 3864.34
-Customer#000000065 8802.16
-Customer#000000032 3478.53
+Customer#000000014 5273.3
+Customer#000000016 4688.03
+Customer#000000017 13.34
+Customer#000000019 8921.71
+Customer#000000022 598.98
Customer#000000023 3339.02
+Customer#000000025 7140.7
+Customer#000000028 1014.1799999999998
+Customer#000000029 7625.27
+Customer#000000031 5243.89
+Customer#000000032 3478.53
+Customer#000000034 8596.7
Customer#000000035 1235.24
-Customer#000000091 4650.14
-Customer#000000016 4688.03
-Customer#000000098 -544.37
Customer#000000037 -910.75
-Customer#000000136 -835.39
-Customer#000000118 3589.37
-Customer#000000022 598.98
-Customer#000000005 801.47
-Customer#000000109 -709.1
Customer#000000038 6352.11
-Customer#000000076 5752.33
-Customer#000000056 6537.86
Customer#000000040 1342.3
-Customer#000000116 8410.99
+Customer#000000041 277.95
+Customer#000000043 9911.28
+Customer#000000044 7322.94
+Customer#000000046 5751.59
+Customer#000000047 281.58
+Customer#000000049 4580.94
+Customer#000000052 5637.28
+Customer#000000053 4120.64
+Customer#000000055 4579.11
+Customer#000000056 6537.86
+Customer#000000058 6485.46
+Customer#000000059 3465.6
+Customer#000000061 1543.24
+Customer#000000062 602.61
+Customer#000000064 -639.64
+Customer#000000065 8802.16
+Customer#000000067 8173.59
+Customer#000000070 4874.52
+Customer#000000071 -604.19
+Customer#000000073 4295.5
+Customer#000000074 2771.43
+Customer#000000076 5752.33
+Customer#000000079 5128.28
+Customer#000000080 7390.53
+Customer#000000082 9475.34
+Customer#000000083 6470.51
+Customer#000000085 3393.64
+Customer#000000086 3313.32
+Customer#000000088 8038.44
+Customer#000000089 1537.76
+Customer#000000091 4650.14
+Customer#000000092 1189.91
+Customer#000000094 5507.11
+Customer#000000095 5334.38
+Customer#000000097 2171.48
+Customer#000000098 -544.37
+Customer#000000100 9896.89
+Customer#000000101 7477.96
+Customer#000000103 2764.45
+Customer#000000104 -581.38
+Customer#000000106 3295.42
+Customer#000000107 2521.15
+Customer#000000109 -709.1
+Customer#000000110 7469.99
+Customer#000000112 2960.35
Customer#000000115 7515.92
+Customer#000000116 8410.99
+Customer#000000118 3589.37
+Customer#000000121 6435.32
+Customer#000000122 7872.46
+Customer#000000127 9287.71
+Customer#000000128 -979.96
+Customer#000000130 5080.58
+Customer#000000131 8602.53
+Customer#000000133 2321.67
+Customer#000000134 4615.9
+Customer#000000136 -835.39
+Customer#000000137 7845.3
+Customer#000000139 7904.78
Customer#000000140 9970.15
-Customer#000000017 13.34
-Customer#000000052 5637.28
+Customer#000000142 2216.81
+Customer#000000143 2193.5
+Customer#000000145 9755.93
+Customer#000000148 2142.6
+Customer#000000149 8966.65
set @a2=3;
execute stmt using @a2;
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7143.7
+Customer#000000001 721.56
+Customer#000000002 131.65
+Customer#000000005 804.47
+Customer#000000007 9571.95
+Customer#000000008 6829.74
+Customer#000000010 2763.54
+Customer#000000011 -262.6
Customer#000000013 3867.34
-Customer#000000065 8805.16
-Customer#000000032 3481.53
+Customer#000000014 5276.3
+Customer#000000016 4691.03
+Customer#000000017 16.34
+Customer#000000019 8924.71
+Customer#000000022 601.98
Customer#000000023 3342.02
+Customer#000000025 7143.7
+Customer#000000028 1017.1799999999998
+Customer#000000029 7628.27
+Customer#000000031 5246.89
+Customer#000000032 3481.53
+Customer#000000034 8599.7
Customer#000000035 1238.24
-Customer#000000091 4653.14
-Customer#000000016 4691.03
-Customer#000000098 -541.37
Customer#000000037 -907.75
-Customer#000000136 -832.39
-Customer#000000118 3592.37
-Customer#000000022 601.98
-Customer#000000005 804.47
-Customer#000000109 -706.1
Customer#000000038 6355.11
-Customer#000000076 5755.33
-Customer#000000056 6540.86
Customer#000000040 1345.3
-Customer#000000116 8413.99
-Customer#000000115 7518.92
-Customer#000000140 9973.15
-Customer#000000017 16.34
+Customer#000000041 280.95
+Customer#000000043 9914.28
+Customer#000000044 7325.94
+Customer#000000046 5754.59
+Customer#000000047 284.58
+Customer#000000049 4583.94
Customer#000000052 5640.28
-execute stmt using -(@a1+@a2);
-select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
-c_name c_acctbal
-Customer#000000025 7133.7
+Customer#000000053 4123.64
+Customer#000000055 4582.11
+Customer#000000056 6540.86
+Customer#000000058 6488.46
+Customer#000000059 3468.6
+Customer#000000061 1546.24
+Customer#000000062 605.61
+Customer#000000064 -636.64
+Customer#000000065 8805.16
+Customer#000000067 8176.59
+Customer#000000070 4877.52
+Customer#000000071 -601.19
+Customer#000000073 4298.5
+Customer#000000074 2774.43
+Customer#000000076 5755.33
+Customer#000000079 5131.28
+Customer#000000080 7393.53
+Customer#000000082 9478.34
+Customer#000000083 6473.51
+Customer#000000085 3396.64
+Customer#000000086 3316.32
+Customer#000000088 8041.44
+Customer#000000089 1540.76
+Customer#000000091 4653.14
+Customer#000000092 1192.91
+Customer#000000094 5510.11
+Customer#000000095 5337.38
+Customer#000000097 2174.48
+Customer#000000098 -541.37
+Customer#000000100 9899.89
+Customer#000000101 7480.96
+Customer#000000103 2767.45
+Customer#000000104 -578.38
+Customer#000000106 3298.42
+Customer#000000107 2524.15
+Customer#000000109 -706.1
+Customer#000000110 7472.99
+Customer#000000112 2963.35
+Customer#000000115 7518.92
+Customer#000000116 8413.99
+Customer#000000118 3592.37
+Customer#000000121 6438.32
+Customer#000000122 7875.46
+Customer#000000127 9290.71
+Customer#000000128 -976.96
+Customer#000000130 5083.58
+Customer#000000131 8605.53
+Customer#000000133 2324.67
+Customer#000000134 4618.9
+Customer#000000136 -832.39
+Customer#000000137 7848.3
+Customer#000000139 7907.78
+Customer#000000140 9973.15
+Customer#000000142 2219.81
+Customer#000000143 2196.5
+Customer#000000145 9758.93
+Customer#000000148 2145.6
+Customer#000000149 8969.65
+execute stmt using -(@a1+@a2);
+select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
+where o_orderDATE between '1992-01-09' and '1993-03-08');
+c_name c_acctbal
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
-Customer#000000065 8795.16
-Customer#000000032 3471.53
+Customer#000000014 5266.3
+Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000023 3332.02
+Customer#000000025 7133.7
+Customer#000000028 1007.1799999999998
+Customer#000000029 7618.27
+Customer#000000031 5236.89
+Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
-Customer#000000091 4643.14
-Customer#000000016 4681.03
-Customer#000000098 -551.37
Customer#000000037 -917.75
-Customer#000000136 -842.39
-Customer#000000118 3582.37
-Customer#000000022 591.98
-Customer#000000005 794.47
-Customer#000000109 -716.1
Customer#000000038 6345.11
-Customer#000000076 5745.33
-Customer#000000056 6530.86
Customer#000000040 1335.3
-Customer#000000116 8403.99
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
+Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
+Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
+Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
+Customer#000000116 8403.99
+Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
-Customer#000000017 6.34
-Customer#000000052 5630.28
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
deallocate prepare stmt;
# Materialization SJM PS
# ======================
@@ -1949,6 +2562,7 @@ o_orderkey o_totalprice
drop procedure p;
# FirstMatch SP
# =============
+set optimizer_switch='materialization=off';
create procedure p(d int)
update customer set c_acctbal = c_acctbal+d where c_nationkey in (select n_nationkey from nation
where n_regionkey in (1,2))
@@ -2111,122 +2725,383 @@ Customer#000000082 9468.34
Customer#000000124 1842.49
Customer#000000127 9280.71
drop procedure p;
+set optimizer_switch='materialization=default';
# Materialization SP
# ==================
create procedure p(d int)
update customer set c_acctbal = c_acctbal+d where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7133.7
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
-Customer#000000065 8795.16
-Customer#000000032 3471.53
+Customer#000000014 5266.3
+Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000023 3332.02
+Customer#000000025 7133.7
+Customer#000000028 1007.1799999999998
+Customer#000000029 7618.27
+Customer#000000031 5236.89
+Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
-Customer#000000091 4643.14
-Customer#000000016 4681.03
-Customer#000000098 -551.37
Customer#000000037 -917.75
-Customer#000000136 -842.39
-Customer#000000118 3582.37
-Customer#000000022 591.98
-Customer#000000005 794.47
-Customer#000000109 -716.1
Customer#000000038 6345.11
-Customer#000000076 5745.33
-Customer#000000056 6530.86
Customer#000000040 1335.3
-Customer#000000116 8403.99
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
+Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
+Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
+Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
+Customer#000000116 8403.99
+Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
-Customer#000000017 6.34
-Customer#000000052 5630.28
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
call p(3);
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7136.7
+Customer#000000001 714.56
+Customer#000000002 124.65
+Customer#000000005 797.47
+Customer#000000007 9564.95
+Customer#000000008 6822.74
+Customer#000000010 2756.54
+Customer#000000011 -269.6
Customer#000000013 3860.34
-Customer#000000065 8798.16
-Customer#000000032 3474.53
+Customer#000000014 5269.3
+Customer#000000016 4684.03
+Customer#000000017 9.34
+Customer#000000019 8917.71
+Customer#000000022 594.98
Customer#000000023 3335.02
+Customer#000000025 7136.7
+Customer#000000028 1010.1799999999998
+Customer#000000029 7621.27
+Customer#000000031 5239.89
+Customer#000000032 3474.53
+Customer#000000034 8592.7
Customer#000000035 1231.24
-Customer#000000091 4646.14
-Customer#000000016 4684.03
-Customer#000000098 -548.37
Customer#000000037 -914.75
-Customer#000000136 -839.39
-Customer#000000118 3585.37
-Customer#000000022 594.98
-Customer#000000005 797.47
-Customer#000000109 -713.1
Customer#000000038 6348.11
-Customer#000000076 5748.33
-Customer#000000056 6533.86
Customer#000000040 1338.3
-Customer#000000116 8406.99
+Customer#000000041 273.95
+Customer#000000043 9907.28
+Customer#000000044 7318.94
+Customer#000000046 5747.59
+Customer#000000047 277.58
+Customer#000000049 4576.94
+Customer#000000052 5633.28
+Customer#000000053 4116.64
+Customer#000000055 4575.11
+Customer#000000056 6533.86
+Customer#000000058 6481.46
+Customer#000000059 3461.6
+Customer#000000061 1539.24
+Customer#000000062 598.61
+Customer#000000064 -643.64
+Customer#000000065 8798.16
+Customer#000000067 8169.59
+Customer#000000070 4870.52
+Customer#000000071 -608.19
+Customer#000000073 4291.5
+Customer#000000074 2767.43
+Customer#000000076 5748.33
+Customer#000000079 5124.28
+Customer#000000080 7386.53
+Customer#000000082 9471.34
+Customer#000000083 6466.51
+Customer#000000085 3389.64
+Customer#000000086 3309.32
+Customer#000000088 8034.44
+Customer#000000089 1533.76
+Customer#000000091 4646.14
+Customer#000000092 1185.91
+Customer#000000094 5503.11
+Customer#000000095 5330.38
+Customer#000000097 2167.48
+Customer#000000098 -548.37
+Customer#000000100 9892.89
+Customer#000000101 7473.96
+Customer#000000103 2760.45
+Customer#000000104 -585.38
+Customer#000000106 3291.42
+Customer#000000107 2517.15
+Customer#000000109 -713.1
+Customer#000000110 7465.99
+Customer#000000112 2956.35
Customer#000000115 7511.92
+Customer#000000116 8406.99
+Customer#000000118 3585.37
+Customer#000000121 6431.32
+Customer#000000122 7868.46
+Customer#000000127 9283.71
+Customer#000000128 -983.96
+Customer#000000130 5076.58
+Customer#000000131 8598.53
+Customer#000000133 2317.67
+Customer#000000134 4611.9
+Customer#000000136 -839.39
+Customer#000000137 7841.3
+Customer#000000139 7900.78
Customer#000000140 9966.15
-Customer#000000017 9.34
-Customer#000000052 5633.28
+Customer#000000142 2212.81
+Customer#000000143 2189.5
+Customer#000000145 9751.93
+Customer#000000148 2138.6
+Customer#000000149 8962.65
call p(7);
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7143.7
+Customer#000000001 721.56
+Customer#000000002 131.65
+Customer#000000005 804.47
+Customer#000000007 9571.95
+Customer#000000008 6829.74
+Customer#000000010 2763.54
+Customer#000000011 -262.6
Customer#000000013 3867.34
-Customer#000000065 8805.16
-Customer#000000032 3481.53
+Customer#000000014 5276.3
+Customer#000000016 4691.03
+Customer#000000017 16.34
+Customer#000000019 8924.71
+Customer#000000022 601.98
Customer#000000023 3342.02
+Customer#000000025 7143.7
+Customer#000000028 1017.1799999999998
+Customer#000000029 7628.27
+Customer#000000031 5246.89
+Customer#000000032 3481.53
+Customer#000000034 8599.7
Customer#000000035 1238.24
-Customer#000000091 4653.14
-Customer#000000016 4691.03
-Customer#000000098 -541.37
Customer#000000037 -907.75
-Customer#000000136 -832.39
-Customer#000000118 3592.37
-Customer#000000022 601.98
-Customer#000000005 804.47
-Customer#000000109 -706.1
Customer#000000038 6355.11
-Customer#000000076 5755.33
-Customer#000000056 6540.86
Customer#000000040 1345.3
-Customer#000000116 8413.99
+Customer#000000041 280.95
+Customer#000000043 9914.28
+Customer#000000044 7325.94
+Customer#000000046 5754.59
+Customer#000000047 284.58
+Customer#000000049 4583.94
+Customer#000000052 5640.28
+Customer#000000053 4123.64
+Customer#000000055 4582.11
+Customer#000000056 6540.86
+Customer#000000058 6488.46
+Customer#000000059 3468.6
+Customer#000000061 1546.24
+Customer#000000062 605.61
+Customer#000000064 -636.64
+Customer#000000065 8805.16
+Customer#000000067 8176.59
+Customer#000000070 4877.52
+Customer#000000071 -601.19
+Customer#000000073 4298.5
+Customer#000000074 2774.43
+Customer#000000076 5755.33
+Customer#000000079 5131.28
+Customer#000000080 7393.53
+Customer#000000082 9478.34
+Customer#000000083 6473.51
+Customer#000000085 3396.64
+Customer#000000086 3316.32
+Customer#000000088 8041.44
+Customer#000000089 1540.76
+Customer#000000091 4653.14
+Customer#000000092 1192.91
+Customer#000000094 5510.11
+Customer#000000095 5337.38
+Customer#000000097 2174.48
+Customer#000000098 -541.37
+Customer#000000100 9899.89
+Customer#000000101 7480.96
+Customer#000000103 2767.45
+Customer#000000104 -578.38
+Customer#000000106 3298.42
+Customer#000000107 2524.15
+Customer#000000109 -706.1
+Customer#000000110 7472.99
+Customer#000000112 2963.35
Customer#000000115 7518.92
+Customer#000000116 8413.99
+Customer#000000118 3592.37
+Customer#000000121 6438.32
+Customer#000000122 7875.46
+Customer#000000127 9290.71
+Customer#000000128 -976.96
+Customer#000000130 5083.58
+Customer#000000131 8605.53
+Customer#000000133 2324.67
+Customer#000000134 4618.9
+Customer#000000136 -832.39
+Customer#000000137 7848.3
+Customer#000000139 7907.78
Customer#000000140 9973.15
-Customer#000000017 16.34
-Customer#000000052 5640.28
+Customer#000000142 2219.81
+Customer#000000143 2196.5
+Customer#000000145 9758.93
+Customer#000000148 2145.6
+Customer#000000149 8969.65
call p(-(3+7));
select c_name, c_acctbal from customer where c_custkey in (select o_custkey from orders
-where o_orderDATE between '1992-01-09' and '1992-03-08');
+where o_orderDATE between '1992-01-09' and '1993-03-08');
c_name c_acctbal
-Customer#000000025 7133.7
+Customer#000000001 711.56
+Customer#000000002 121.65
+Customer#000000005 794.47
+Customer#000000007 9561.95
+Customer#000000008 6819.74
+Customer#000000010 2753.54
+Customer#000000011 -272.6
Customer#000000013 3857.34
-Customer#000000065 8795.16
-Customer#000000032 3471.53
+Customer#000000014 5266.3
+Customer#000000016 4681.03
+Customer#000000017 6.34
+Customer#000000019 8914.71
+Customer#000000022 591.98
Customer#000000023 3332.02
+Customer#000000025 7133.7
+Customer#000000028 1007.1799999999998
+Customer#000000029 7618.27
+Customer#000000031 5236.89
+Customer#000000032 3471.53
+Customer#000000034 8589.7
Customer#000000035 1228.24
-Customer#000000091 4643.14
-Customer#000000016 4681.03
-Customer#000000098 -551.37
Customer#000000037 -917.75
-Customer#000000136 -842.39
-Customer#000000118 3582.37
-Customer#000000022 591.98
-Customer#000000005 794.47
-Customer#000000109 -716.1
Customer#000000038 6345.11
-Customer#000000076 5745.33
-Customer#000000056 6530.86
Customer#000000040 1335.3
-Customer#000000116 8403.99
+Customer#000000041 270.95
+Customer#000000043 9904.28
+Customer#000000044 7315.94
+Customer#000000046 5744.59
+Customer#000000047 274.58
+Customer#000000049 4573.94
+Customer#000000052 5630.28
+Customer#000000053 4113.64
+Customer#000000055 4572.11
+Customer#000000056 6530.86
+Customer#000000058 6478.46
+Customer#000000059 3458.6
+Customer#000000061 1536.24
+Customer#000000062 595.61
+Customer#000000064 -646.64
+Customer#000000065 8795.16
+Customer#000000067 8166.59
+Customer#000000070 4867.52
+Customer#000000071 -611.19
+Customer#000000073 4288.5
+Customer#000000074 2764.43
+Customer#000000076 5745.33
+Customer#000000079 5121.28
+Customer#000000080 7383.53
+Customer#000000082 9468.34
+Customer#000000083 6463.51
+Customer#000000085 3386.64
+Customer#000000086 3306.32
+Customer#000000088 8031.44
+Customer#000000089 1530.76
+Customer#000000091 4643.14
+Customer#000000092 1182.91
+Customer#000000094 5500.11
+Customer#000000095 5327.38
+Customer#000000097 2164.48
+Customer#000000098 -551.37
+Customer#000000100 9889.89
+Customer#000000101 7470.96
+Customer#000000103 2757.45
+Customer#000000104 -588.38
+Customer#000000106 3288.42
+Customer#000000107 2514.15
+Customer#000000109 -716.1
+Customer#000000110 7462.99
+Customer#000000112 2953.35
Customer#000000115 7508.92
+Customer#000000116 8403.99
+Customer#000000118 3582.37
+Customer#000000121 6428.32
+Customer#000000122 7865.46
+Customer#000000127 9280.71
+Customer#000000128 -986.96
+Customer#000000130 5073.58
+Customer#000000131 8595.53
+Customer#000000133 2314.67
+Customer#000000134 4608.9
+Customer#000000136 -842.39
+Customer#000000137 7838.3
+Customer#000000139 7897.78
Customer#000000140 9963.15
-Customer#000000017 6.34
-Customer#000000052 5630.28
+Customer#000000142 2209.81
+Customer#000000143 2186.5
+Customer#000000145 9748.93
+Customer#000000148 2135.6
+Customer#000000149 8959.65
drop procedure p;
# Materialization SJM SP
# ======================
@@ -2296,7 +3171,7 @@ where c_nationkey in (1,2))
order by o_totalprice limit 500;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY orders range i_o_orderdate i_o_orderdate 4 NULL 108 Using where; Using filesort
-2 DEPENDENT SUBQUERY customer unique_subquery|filter PRIMARY,i_c_nationkey PRIMARY|i_c_nationkey 4|5 func 1 (10%) Using where; Using rowid filter
+2 DEPENDENT SUBQUERY customer unique_subquery PRIMARY,i_c_nationkey PRIMARY 4 func 1 Using where
update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2))
@@ -2336,7 +3211,7 @@ o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY customer range PRIMARY,i_c_nationkey i_c_nationkey 5 NULL 15 Using index condition
-1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 11 (7%) Using where; Using rowid filter
+1 PRIMARY orders ref|filter i_o_orderdate,i_o_custkey i_o_custkey|i_o_orderdate 5|4 dbt3_s001.customer.c_custkey 15 (7%) Using where; Using rowid filter
update orders set o_totalprice = o_totalprice-50 where o_orderDATE between '1992-01-01' and '1992-06-30' and
o_custkey in (select c_custkey from customer
where c_nationkey in (1,2));
diff --git a/mysql-test/main/update_single_to_multi.test b/mysql-test/main/update_single_to_multi.test
index bf89a6c..a215c5a 100644
--- a/mysql-test/main/update_single_to_multi.test
+++ b/mysql-test/main/update_single_to_multi.test
@@ -15,8 +15,9 @@ use dbt3_s001;
--enable_query_log
create index i_n_name on nation(n_name);
-analyze table nation;
-
+analyze table
+ nation, lineitem, customer, orders, part, supplier, partsupp, region
+persistent for all;
--echo # Pullout
--echo # =======
@@ -209,117 +210,148 @@ select c_name, c_acctbal from customer where $c6;
--echo # Materialization
--echo # ===============
+set optimizer_switch='firstmatch=off';
+
let $c7=
+ c_nationkey in (select n_nationkey from nation where
+ n_name in ('JAPAN', 'INDONESIA', 'PERU', 'ARGENTINA'))
+ and
c_custkey in (select o_custkey from orders
- where o_orderDATE between '1992-01-09' and '1992-03-08');
+ where o_orderDATE between "1992-01-09" and "1995-01-08");
eval
explain
select c_name, c_acctbal from customer where $c7;
eval
-explain format=json
-select c_name, c_acctbal from customer where $c7;
-eval
select c_name, c_acctbal from customer where $c7;
eval
explain
-update customer set c_acctbal = c_acctbal+5 where $c7;
+update customer set c_acctbal = c_acctbal+20 where $c7;
eval
-explain format=json
-update customer set c_acctbal = c_acctbal+5 where $c7;
-eval
-update customer set c_acctbal = c_acctbal+5 where $c7;
+update customer set c_acctbal = c_acctbal+20 where $c7;
eval
select c_name, c_acctbal from customer where $c7;
eval
-update customer set c_acctbal = c_acctbal-5 where $c7;
+update customer set c_acctbal = c_acctbal-20 where $c7;
eval
select c_name, c_acctbal from customer where $c7;
+set optimizer_switch='firstmatch=default';
let $c8=
c_custkey in (select o_custkey from orders
- where o_orderDATE between '1992-06-09' and '1993-01-08');
+ where o_orderDATE between '1992-01-09' and '1993-03-08');
eval
explain
select c_name, c_acctbal from customer where $c8;
eval
+explain format=json
+select c_name, c_acctbal from customer where $c8;
+eval
select c_name, c_acctbal from customer where $c8;
eval
explain
-update customer set c_acctbal = c_acctbal+1 where $c8;
+update customer set c_acctbal = c_acctbal+5 where $c8;
eval
-update customer set c_acctbal = c_acctbal+1 where $c8;
+explain format=json
+update customer set c_acctbal = c_acctbal+5 where $c8;
+eval
+update customer set c_acctbal = c_acctbal+5 where $c8;
eval
select c_name, c_acctbal from customer where $c8;
eval
-update customer set c_acctbal = c_acctbal-1 where $c8;
+update customer set c_acctbal = c_acctbal-5 where $c8;
eval
select c_name, c_acctbal from customer where $c8;
+let $c9=
+ c_custkey in (select o_custkey from orders
+ where o_orderDATE between '1992-06-09' and '1993-01-08');
+
+eval
+explain
+select c_name, c_acctbal from customer where $c9;
+eval
+select c_name, c_acctbal from customer where $c9;
+
+eval
+explain
+update customer set c_acctbal = c_acctbal+1 where $c9;
+eval
+update customer set c_acctbal = c_acctbal+1 where $c9;
+eval
+select c_name, c_acctbal from customer where $c9;
+
+eval
+update customer set c_acctbal = c_acctbal-1 where $c9;
+eval
+select c_name, c_acctbal from customer where $c9;
+
+
+
--echo # Materialization SJM
--echo # ===================
-let $c9=
+let $c10=
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1992-03-08'
group by o_custkey having count(o_custkey) > 1);
eval
explain
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
eval
explain format=json
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
eval
explain
-update customer set c_acctbal = c_acctbal-5 where $c9;
+update customer set c_acctbal = c_acctbal-5 where $c10;
eval
explain format=json
-update customer set c_acctbal = c_acctbal-5 where $c9;
+update customer set c_acctbal = c_acctbal-5 where $c10;
eval
-update customer set c_acctbal = c_acctbal-5 where $c9;
+update customer set c_acctbal = c_acctbal-5 where $c10;
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
eval
-update customer set c_acctbal = c_acctbal+5 where $c9;
+update customer set c_acctbal = c_acctbal+5 where $c10;
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
-let $c10=
+let $c11=
c_custkey in (select o_custkey from orders
where o_orderDATE between '1992-01-09' and '1993-03-08'
group by o_custkey having count(o_custkey) > 5);
eval
explain
-select c_name, c_acctbal from customer where $c10;
+select c_name, c_acctbal from customer where $c11;
eval
-select c_name, c_acctbal from customer where $c10;
+select c_name, c_acctbal from customer where $c11;
eval
explain
-update customer set c_acctbal = c_acctbal-1 where $c10;
+update customer set c_acctbal = c_acctbal-1 where $c11;
eval
-update customer set c_acctbal = c_acctbal-1 where $c10;
+update customer set c_acctbal = c_acctbal-1 where $c11;
eval
-select c_name, c_acctbal from customer where $c10;
+select c_name, c_acctbal from customer where $c11;
eval
-update customer set c_acctbal = c_acctbal+1 where $c10;
+update customer set c_acctbal = c_acctbal+1 where $c11;
eval
-select c_name, c_acctbal from customer where $c10;
+select c_name, c_acctbal from customer where $c11;
--echo # Pullout PS
@@ -350,6 +382,8 @@ deallocate prepare stmt;
--echo # FirstMatch PS
--echo # =============
+set optimizer_switch='materialization=off';
+
eval
prepare stmt from "
update customer set c_acctbal = c_acctbal+? where $c5;
@@ -371,28 +405,29 @@ select c_name, c_acctbal from customer where $c5;
deallocate prepare stmt;
+set optimizer_switch='materialization=default';
--echo # Materialization PS
--echo # ==================
eval
prepare stmt from "
-update customer set c_acctbal = c_acctbal+? where $c7;
+update customer set c_acctbal = c_acctbal+? where $c8;
";
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
set @a1=7;
execute stmt using @a1;
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
set @a2=3;
execute stmt using @a2;
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
execute stmt using -(@a1+@a2);
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
deallocate prepare stmt;
@@ -402,22 +437,22 @@ deallocate prepare stmt;
eval
prepare stmt from "
-update customer set c_acctbal = c_acctbal+? where $c9;
+update customer set c_acctbal = c_acctbal+? where $c10;
";
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
set @a1=-2;
execute stmt using @a1;
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
set @a2=-1;
execute stmt using @a2;
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
execute stmt using -(@a1+@a2);
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
deallocate prepare stmt;
@@ -447,6 +482,8 @@ drop procedure p;
--echo # FirstMatch SP
--echo # =============
+set optimizer_switch='materialization=off';
+
eval
create procedure p(d int)
update customer set c_acctbal = c_acctbal+d where $c5;
@@ -465,25 +502,27 @@ select c_name, c_acctbal from customer where $c5;
drop procedure p;
+set optimizer_switch='materialization=default';
+
--echo # Materialization SP
--echo # ==================
eval
create procedure p(d int)
-update customer set c_acctbal = c_acctbal+d where $c7;
+update customer set c_acctbal = c_acctbal+d where $c8;
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
call p(3);
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
call p(7);
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
call p(-(3+7));
eval
-select c_name, c_acctbal from customer where $c7;
+select c_name, c_acctbal from customer where $c8;
drop procedure p;
@@ -493,19 +532,19 @@ drop procedure p;
eval
create procedure p(d int)
-update customer set c_acctbal = c_acctbal+d where $c9;
+update customer set c_acctbal = c_acctbal+d where $c10;
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
call p(-1);
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
call p(-2);
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
call p(1+2);
eval
-select c_name, c_acctbal from customer where $c9;
+select c_name, c_acctbal from customer where $c10;
drop procedure p;
diff --git a/mysql-test/main/update_use_source.result b/mysql-test/main/update_use_source.result
index 3f52741..99d7242 100644
--- a/mysql-test/main/update_use_source.result
+++ b/mysql-test/main/update_use_source.result
@@ -316,7 +316,7 @@ rollback;
#
explain update t1 set c1=0 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 range t1_c2 t1_c2 5 NULL 2 Using where
+1 PRIMARY t1 range t1_c2 t1_c2 5 NULL 2 Using index condition
1 PRIMARY a ref t1_c2 t1_c2 5 test.t1.c2 8 Using index; FirstMatch(t1)
start transaction;
update t1 set c1=c1+10 where exists (select 'X' from t1 a where a.c2 = t1.c2) and c2 >= 3;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index ad55ddb..ba64c00 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -32592,7 +32592,8 @@ bool Sql_cmd_dml::execute_inner(THD *thd)
if (unlikely(thd->is_error()))
goto err;
- join->exec();
+ if (join->exec())
+ goto err;
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
1
0