1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

[SHOW] EXPLAIN UPDATE/DELETE, code re-structuring

- Merge with current 10.0-base
This commit is contained in:
Sergey Petrunya
2013-08-24 12:20:51 +04:00
52 changed files with 2738 additions and 556 deletions

View File

@@ -0,0 +1,86 @@
#
# MariaDB tests for EXPLAIN UPDATE/DELETE.
#
--disable_warnings
drop table if exists t0, t1;
--enable_warnings
create table t0 (a int) engine=myisam;
insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
--echo #
--echo # Tests for single-table DELETE
--echo #
explain select * from t0 where a=3;
explain delete from t0 where a=3;
--echo # DELETE without WHERE is a special case:
explain delete from t0;
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;
--echo # This should use an index, possible_keys=NULL because there is no WHERE
explain delete from t1 order by a limit 2;
--echo # This should use range, possible_keys={a,b}
explain delete from t1 where a<20 and b < 10;
--echo # This should use ALL + filesort
explain delete from t1 order by a+1 limit 2;
--echo # This should use range + using filesort
explain delete from t1 where a<20 order by b limit 2;
--echo # Try some subqueries:
explain delete from t1 where a < (select max(a) from t0);
explain delete from t1 where a < (select max(a) from t0 where a < t1.b);
--echo #
--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;

View File

@@ -202,7 +202,6 @@ set debug_dbug='+d,show_explain_probe_join_exec_end';
send select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1;
connection default;
--source include/wait_condition.inc
--error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
connection con1;
reap;
@@ -238,10 +237,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;
@@ -249,7 +248,7 @@ drop table t2;
set debug_dbug=@old_debug;
--echo #
--echo # Attempt SHOW EXPLAIN for a DELETE
--echo # Attempt SHOW EXPLAIN for a DELETE (UPD: now works)
--echo #
create table t2 as select a as a, a as dummy from t0 limit 2;
set @show_explain_probe_select_id=2;
@@ -257,10 +256,10 @@ set debug_dbug='+d,show_explain_probe_join_exec_start';
send delete from t2 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;
@@ -349,7 +348,7 @@ connection default;
--source include/wait_condition.inc
--echo # FIXED by "conservative assumptions about when QEP is available" fix:
--echo # NOTE: current code will not show "Using join buffer":
--error ER_TARGET_NOT_EXPLAINABLE
#--error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
connection con1;
reap;
@@ -428,7 +427,7 @@ set debug_dbug='+d,show_explain_probe_join_exec_end';
send select * from t0 where 1>10;
connection default;
--source include/wait_condition.inc
--error ER_TARGET_NOT_EXPLAINABLE
#--error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
connection con1;
reap;
@@ -444,7 +443,7 @@ set debug_dbug='+d,show_explain_probe_join_exec_end';
send select * from t0,t3 where t3.a=112233;
connection default;
--source include/wait_condition.inc
--error ER_TARGET_NOT_EXPLAINABLE
# --error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
connection con1;
reap;
@@ -540,7 +539,7 @@ send
SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`);
connection default;
--source include/wait_condition.inc
--error ER_TARGET_NOT_EXPLAINABLE
# --error ER_TARGET_NOT_EXPLAINABLE
evalp show explain for $thr2;
connection con1;
reap;

View File

@@ -0,0 +1,78 @@
#
# SHOW EXPLAIN tests for non-select subqueries
#
#--source include/have_debug.inc
#--source include/have_innodb.inc
#--source include/not_embedded.inc
--disable_warnings
drop table if exists t0, t1;
--enable_warnings
SET @old_debug= @@session.debug;
set debug_sync='RESET';
#
# Setup two threads and their ids
#
let $thr1=`select connection_id()`;
connect (con2, localhost, root,,);
connection con2;
let $thr2=`select connection_id()`;
connection default;
#
# Create tables
#
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;
let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
--echo #
--echo # Test SHOW EXPLAIN for single-table DELETE
--echo #
connection con2;
set debug_dbug='+d,show_explain_probe_delete_exec_start';
send delete from t1 where a<10 and b+1>1000;
connection default;
--source include/wait_condition.inc
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';
send delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000;
connection default;
--source include/wait_condition.inc
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';