summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/explain_non_select.result53
-rw-r--r--mysql-test/r/show_explain.result18
-rw-r--r--mysql-test/r/show_explain_non_select.result24
-rw-r--r--mysql-test/t/explain_non_select.test39
-rw-r--r--mysql-test/t/show_explain.test4
-rw-r--r--mysql-test/t/show_explain_non_select.test31
6 files changed, 154 insertions, 15 deletions
diff --git a/mysql-test/r/explain_non_select.result b/mysql-test/r/explain_non_select.result
index aa592f0b198..1c8e444c4b9 100644
--- a/mysql-test/r/explain_non_select.result
+++ b/mysql-test/r/explain_non_select.result
@@ -38,7 +38,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain delete from t1 where a < (select max(a) from t0);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 range a a 5 NULL 1 Using where
-2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Query plan already deleted
+2 SUBQUERY t0 ALL NULL NULL NULL NULL 8
explain delete from t1 where a < (select max(a) from t0 where a < t1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 512 Using where
@@ -51,3 +51,54 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where
1 SIMPLE t1 ref a a 5 test.t0.a 4 Using index
drop table t0, t1;
+# ###################################################################
+# ## EXPLAIN UPDATE tests
+# ###################################################################
+create table t0 (a int) engine=myisam;
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+explain update t0 set a=3 where a=4;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where
+create table t1 (a int, b int, filler char(100), key(a), key(b));
+insert into t1
+select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler'
+from t0 A, t0 B, t0 C;
+explain update t1 set a=a+1 where 3>4;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible where
+explain update t1 set a=a+1 where a=3 and a=4;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible where
+# This should use an index, possible_keys=NULL because there is no WHERE
+explain update t1 set a=a+1 order by a limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 512
+# This should use range, possible_keys={a,b}
+explain update t1 set filler='fooo' where a<20 and b < 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a,b a 5 NULL 1 Using where
+# This should use ALL + filesort
+explain update t1 set filler='fooo' order by a+1 limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 512
+# This should use range + using filesort
+explain update t1 set filler='fooo' where a<20 order by b limit 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a a 5 NULL 1 Using where
+# Try some subqueries:
+explain update t1 set filler='fooo' where a < (select max(a) from t0);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range a a 5 NULL 1 Using where
+2 SUBQUERY t0 ALL NULL NULL NULL NULL 8
+explain update t1 set filler='fooo' where a < (select max(a) from t0 where a < t1.b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 512 Using where
+2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 8 Using where
+#
+# Tests for multi-table UPDATE
+#
+explain update t0, t1 set t1.a=t1.a+1 where t0.a = t1.a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where
+1 SIMPLE t1 ref a a 5 test.t0.a 4 Using index
+drop table t0, t1;
diff --git a/mysql-test/r/show_explain.result b/mysql-test/r/show_explain.result
index 8baf4d40e7c..1152baaf835 100644
--- a/mysql-test/r/show_explain.result
+++ b/mysql-test/r/show_explain.result
@@ -186,9 +186,17 @@ set @show_explain_probe_select_id=2;
set debug_dbug='+d,show_explain_probe_join_exec_start';
update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 ;
show explain for $thr2;
-ERROR HY000: Target is not running an EXPLAINable command
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
+Warnings:
+Note 1003 update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3
show explain for $thr2;
-ERROR HY000: Target is not running an EXPLAINable command
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
+Warnings:
+Note 1003 update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3
drop table t2;
set debug_dbug=@old_debug;
#
@@ -207,7 +215,7 @@ Note 1003 delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Query plan already deleted
+2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3
drop table t2;
@@ -228,13 +236,13 @@ Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Query plan already deleted
+2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Query plan already deleted
+2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
Warnings:
Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
a SUBQ
diff --git a/mysql-test/r/show_explain_non_select.result b/mysql-test/r/show_explain_non_select.result
index 5358981e6f2..0bd1e959405 100644
--- a/mysql-test/r/show_explain_non_select.result
+++ b/mysql-test/r/show_explain_non_select.result
@@ -1,19 +1,27 @@
drop table if exists t0, t1;
+SET @old_debug= @@session.debug;
+set debug_sync='RESET';
create table t0 (a int) engine=myisam;
insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
create table t1 (a int, b int, filler char(100), key(a), key(b));
insert into t1
select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler'
from t0 A, t0 B, t0 C;
-set debug_dbug='d,show_explain_probe_delete_exec_start';
+#
+# Test SHOW EXPLAIN for single-table DELETE
+#
+set debug_dbug='+d,show_explain_probe_delete_exec_start';
delete from t1 where a<10 and b+1>1000;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 1 Using where
Warnings:
Note 1003 delete from t1 where a<10 and b+1>1000
+#
+# Test SHOW EXPLAIN for multi-table DELETE
+#
set @show_explain_probe_select_id=1;
-set debug_dbug='d,show_explain_probe_do_select';
+set debug_dbug='+d,show_explain_probe_do_select';
delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
@@ -21,4 +29,16 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a a 5 test.t0.a 4 Using where
Warnings:
Note 1003 delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000
+#
+# Test SHOW EXPLAIN for single-table UPDATE
+#
+set debug_dbug='+d,show_explain_probe_update_exec_start';
+update t1 set filler='filler-data-2' where a<10 and b+1>1000;
+show explain for $thr2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a a 5 NULL 1 Using where
+Warnings:
+Note 1003 update t1 set filler='filler-data-2' where a<10 and b+1>1000
drop table t0,t1;
+set debug_dbug=@old_debug;
+set debug_sync='RESET';
diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test
index bc3c2bb6c16..66432a8e4a5 100644
--- a/mysql-test/t/explain_non_select.test
+++ b/mysql-test/t/explain_non_select.test
@@ -43,5 +43,44 @@ explain delete from t1 where a < (select max(a) from t0 where a < t1.b);
--echo # Tests for multi-table DELETE
--echo #
explain delete t1 from t0, t1 where t0.a = t1.a;
+drop table t0, t1;
+
+--echo # ###################################################################
+--echo # ## EXPLAIN UPDATE tests
+--echo # ###################################################################
+create table t0 (a int) engine=myisam;
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+
+explain update t0 set a=3 where a=4;
+
+create table t1 (a int, b int, filler char(100), key(a), key(b));
+insert into t1
+select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler'
+from t0 A, t0 B, t0 C;
+
+explain update t1 set a=a+1 where 3>4;
+explain update t1 set a=a+1 where a=3 and a=4;
+
+--echo # This should use an index, possible_keys=NULL because there is no WHERE
+explain update t1 set a=a+1 order by a limit 2;
+
+--echo # This should use range, possible_keys={a,b}
+explain update t1 set filler='fooo' where a<20 and b < 10;
+
+--echo # This should use ALL + filesort
+explain update t1 set filler='fooo' order by a+1 limit 2;
+
+--echo # This should use range + using filesort
+explain update t1 set filler='fooo' where a<20 order by b limit 2;
+
+--echo # Try some subqueries:
+explain update t1 set filler='fooo' where a < (select max(a) from t0);
+explain update t1 set filler='fooo' where a < (select max(a) from t0 where a < t1.b);
+
+--echo #
+--echo # Tests for multi-table UPDATE
+--echo #
+explain update t0, t1 set t1.a=t1.a+1 where t0.a = t1.a;
+
drop table t0, t1;
diff --git a/mysql-test/t/show_explain.test b/mysql-test/t/show_explain.test
index d87bf2f14d4..0694160b151 100644
--- a/mysql-test/t/show_explain.test
+++ b/mysql-test/t/show_explain.test
@@ -238,10 +238,10 @@ set debug_dbug='+d,show_explain_probe_join_exec_start';
send update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 ;
connection default;
--source include/wait_condition.inc
---error ER_TARGET_NOT_EXPLAINABLE
+#--error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
--source include/wait_condition.inc
---error ER_TARGET_NOT_EXPLAINABLE
+#--error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
connection con1;
reap;
diff --git a/mysql-test/t/show_explain_non_select.test b/mysql-test/t/show_explain_non_select.test
index da788779626..f71affd8a6e 100644
--- a/mysql-test/t/show_explain_non_select.test
+++ b/mysql-test/t/show_explain_non_select.test
@@ -9,6 +9,9 @@
drop table if exists t0, t1;
--enable_warnings
+SET @old_debug= @@session.debug;
+set debug_sync='RESET';
+
#
# Setup two threads and their ids
#
@@ -31,11 +34,11 @@ from t0 A, t0 B, t0 C;
let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
-#
-# Test SHOW EXPLAIN for single-table DELETEs
-#
+--echo #
+--echo # Test SHOW EXPLAIN for single-table DELETE
+--echo #
connection con2;
-set debug_dbug='d,show_explain_probe_delete_exec_start';
+set debug_dbug='+d,show_explain_probe_delete_exec_start';
send delete from t1 where a<10 and b+1>1000;
connection default;
@@ -44,8 +47,11 @@ evalp show explain for $thr2;
connection con2;
reap;
+--echo #
+--echo # Test SHOW EXPLAIN for multi-table DELETE
+--echo #
set @show_explain_probe_select_id=1;
-set debug_dbug='d,show_explain_probe_do_select';
+set debug_dbug='+d,show_explain_probe_do_select';
send delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000;
connection default;
--source include/wait_condition.inc
@@ -53,5 +59,20 @@ evalp show explain for $thr2;
connection con2;
reap;
+--echo #
+--echo # Test SHOW EXPLAIN for single-table UPDATE
+--echo #
+connection con2;
+set debug_dbug='+d,show_explain_probe_update_exec_start';
+send update t1 set filler='filler-data-2' where a<10 and b+1>1000;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con2;
+reap;
drop table t0,t1;
+
+set debug_dbug=@old_debug;
+set debug_sync='RESET';