mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
52cfa54c1d
Single table UPDATE/DELETE - Correctly print type=SIMPLE vs type=PRIMARY - Handle UPDATE/DELETE of mergeable VIEWs: we get the VIEW's select as the first subquery. (MySQL 5.6 doesn't print it because it finds that the subquery is not attached to any select)
104 lines
4.9 KiB
Text
104 lines
4.9 KiB
Text
drop table if exists t0, t1;
|
|
create table t0 (a int) engine=myisam;
|
|
insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
|
|
#
|
|
# Tests for single-table DELETE
|
|
#
|
|
explain select * from t0 where a=3;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where
|
|
explain delete from t0 where a=3;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where
|
|
# DELETE without WHERE is a special case:
|
|
explain delete from t0;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Deleting all rows
|
|
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;
|
|
# This should use an index, possible_keys=NULL because there is no WHERE
|
|
explain delete from t1 order by a limit 2;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index NULL a NULL NULL 512
|
|
# This should use range, possible_keys={a,b}
|
|
explain delete from t1 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 delete from t1 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 Using filesort
|
|
# This should use range + using filesort
|
|
explain delete from t1 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; Using filesort
|
|
# Try some subqueries:
|
|
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 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
|
|
2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 8 Using where
|
|
#
|
|
# Tests for multi-table DELETE
|
|
#
|
|
explain delete t1 from t0, t1 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;
|
|
# ###################################################################
|
|
# ## 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;
|