2016-12-19 17:32:45 -05:00
call mtr.add_suppression("Sort aborted.*");
2012-03-11 14:39:20 +02:00
set @save_join_cache_level = @@join_cache_level;
create table t1 (c1 char(2));
create table t2 (c2 char(2));
insert into t1 values ('bb'), ('cc'), ('aa'), ('dd');
insert into t2 values ('bb'), ('cc'), ('dd'), ('ff');
create table t1i (c1 char(2) key);
create table t2i (c2 char(2) key);
insert into t1i values ('bb'), ('cc'), ('aa'), ('dd');
insert into t2i values ('bb'), ('cc'), ('dd'), ('ff');
=========================================================================
Simple joins
=========================================================================
Simple nested loops join without blocking
set @@join_cache_level=0;
explain
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 2;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1i, t2i where c1 = c2 LIMIT ROWS EXAMINED 4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1i index PRIMARY PRIMARY 2 NULL 4 Using index
1 SIMPLE t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index
select * from t1i, t2i where c1 = c2 LIMIT ROWS EXAMINED 4;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (4). The query result may be incomplete
2012-03-11 14:39:20 +02:00
Blocked nested loops join, empty result set because of blocking
set @@join_cache_level=1;
explain
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 6;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 6;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 7 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1i, t2i where c1 = c2 LIMIT ROWS EXAMINED 6;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1i index PRIMARY PRIMARY 2 NULL 4 Using index
2018-05-31 15:51:59 +05:30
1 SIMPLE t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index
2012-03-11 14:39:20 +02:00
select * from t1i, t2i where c1 = c2 LIMIT ROWS EXAMINED 6;
c1 c2
bb bb
2018-05-31 15:51:59 +05:30
cc cc
2012-03-11 14:39:20 +02:00
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 7 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
set @@join_cache_level=6;
explain
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where
1 SIMPLE t2 hash_ALL NULL #hash#$hj 3 test.t1.c1 4 Using where; Using join buffer (flat, BNLH join)
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 3;
c1 c2
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 4 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1i, t2i where c1 = c2 LIMIT ROWS EXAMINED 6;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1i index PRIMARY PRIMARY 2 NULL 4 Using index
2018-05-31 15:51:59 +05:30
1 SIMPLE t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index
2012-03-11 14:39:20 +02:00
select * from t1i, t2i where c1 = c2 LIMIT ROWS EXAMINED 6;
c1 c2
bb bb
2018-05-31 15:51:59 +05:30
cc cc
2012-03-11 14:39:20 +02:00
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 7 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
Mix LIMIT ROWS EXAMINED with LIMIT
set @@join_cache_level=0;
explain
select * from t1, t2 where c1 < c2 LIMIT 1 ROWS EXAMINED 4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1, t2 where c1 < c2 LIMIT 1 ROWS EXAMINED 4;
c1 c2
bb cc
explain
select * from t1, t2 where c1 < c2 LIMIT 1,1 ROWS EXAMINED 4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1, t2 where c1 < c2 LIMIT 1,1 ROWS EXAMINED 4;
c1 c2
bb dd
Empty table optimized away during constant optimization
create table t0 (c0 int);
explain
select * from t0 LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
2017-12-01 12:34:37 +02:00
1 SIMPLE t0 system NULL NULL NULL NULL 0 Const row not found
2012-03-11 14:39:20 +02:00
explain
select * from t0 LIMIT ROWS EXAMINED 1;
id select_type table type possible_keys key key_len ref rows Extra
2017-12-01 12:34:37 +02:00
1 SIMPLE t0 system NULL NULL NULL NULL 0 Const row not found
2012-03-11 14:39:20 +02:00
select * from t0 LIMIT ROWS EXAMINED 1;
c0
drop table t0;
create table t0 (c0 char(2) primary key);
insert into t0 values ('bb'), ('cc'), ('aa');
explain
select * from t0 where c0 = 'bb' LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 const PRIMARY PRIMARY 2 const 1 Using index
select * from t0 where c0 = 'bb' LIMIT ROWS EXAMINED 0;
c0
bb
explain
select * from t0, t1 where c0 = 'bb' and c1 > c0 LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 const PRIMARY PRIMARY 2 const 1 Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where
select * from t0, t1 where c0 = 'bb' and c1 > c0 LIMIT ROWS EXAMINED 0;
c0 c1
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
set @@join_cache_level = @save_join_cache_level;
drop table t0;
=========================================================================
LIMIT ROWS EXAMINED with parameter argument
=========================================================================
set @@join_cache_level=0;
set @l = 2;
Prepared statement parameter
prepare st1 from "select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED ?";
execute st1 using @l;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2012-03-11 14:39:20 +02:00
deallocate prepare st1;
User variable (not supported for LIMIT in MariaDB 5.3/MySQL 5.1)
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED @l;
2012-03-12 00:45:18 +02:00
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@l' at line 1
Stored procedure parameter
create procedure test_limit_rows(l int)
begin
2012-03-11 14:39:20 +02:00
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED l;
2012-03-12 00:45:18 +02:00
end|
call test_limit_rows(3);
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 4 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
2012-03-12 00:45:18 +02:00
drop procedure test_limit_rows;
2012-03-11 14:39:20 +02:00
set @@join_cache_level = @save_join_cache_level;
=========================================================================
UNIONs (with several LIMIT ROWS EXAMINED clauses)
=========================================================================
(select * from t1, t2 where c1 = c2)
UNION
(select * from t1, t2 where c1 < c2) LIMIT ROWS EXAMINED 6;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 8 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
(select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 0)
UNION
(select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 6);
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 8 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 0
UNION
select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 6;
2016-05-10 11:48:01 +04:00
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION
select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 6' at line 2
2012-03-11 14:39:20 +02:00
(select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 0)
UNION
(select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 6;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 8 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
(select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 0)
UNION
(select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 0)
LIMIT 1 ROWS EXAMINED 6;
c1 c2
bb bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 8 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
(select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 0)
UNION
(select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 0)
LIMIT 2 ROWS EXAMINED 10;
c1 c2
bb bb
cc cc
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (10). The query result may be incomplete
2012-03-11 14:39:20 +02:00
=========================================================================
Subqueries (with several LIMIT ROWS EXAMINED clauses)
=========================================================================
Subqueries, semi-join
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11);
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 11;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 11;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1i
where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 6;
id select_type table type possible_keys key key_len ref rows Extra
2020-02-28 12:59:30 +02:00
1 PRIMARY t1i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index
2018-05-31 15:51:59 +05:30
1 PRIMARY t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index
2012-03-11 14:39:20 +02:00
select * from t1i
where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 6;
c1
bb
2018-05-31 15:51:59 +05:30
cc
2012-03-11 14:39:20 +02:00
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 7 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
Subqueries with IN-TO-EXISTS
set @@optimizer_switch='semijoin=off,in_to_exists=on,materialization=off';
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 4);
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (4). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 4;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 4;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (4). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 4;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 4;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 5 rows, which exceeds LIMIT ROWS EXAMINED (4). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1i
where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 9;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1i index NULL PRIMARY 2 NULL 4 Using where; Using index
2 DEPENDENT SUBQUERY t2i unique_subquery PRIMARY PRIMARY 2 func 1 Using index; Using where
select * from t1i
where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 9;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (9). The query result may be incomplete
2012-03-11 14:39:20 +02:00
Same as above, without subquery cache
set @@optimizer_switch='subquery_cache=off';
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 2);
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from t1
where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 2;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 2;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from t1i
where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 5;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 7 rows, which exceeds LIMIT ROWS EXAMINED (5). The query result may be incomplete
2012-03-11 14:39:20 +02:00
Subqueries with materialization
set @@optimizer_switch='semijoin=off,in_to_exists=off,materialization=on,subquery_cache=on';
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 13);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 13);
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 14 rows, which exceeds LIMIT ROWS EXAMINED (13). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ') LIMIT ROWS EXAMINED 13;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ') LIMIT ROWS EXAMINED 13;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 14 rows, which exceeds LIMIT ROWS EXAMINED (13). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 13;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 13;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 14 rows, which exceeds LIMIT ROWS EXAMINED (13). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select * from t1i
where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1i index NULL PRIMARY 2 NULL 4 Using where; Using index
2020-02-28 12:59:30 +02:00
2 MATERIALIZED t2i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index
2012-03-11 14:39:20 +02:00
select * from t1i
where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 18 rows, which exceeds LIMIT ROWS EXAMINED (17). The query result may be incomplete
2012-03-11 14:39:20 +02:00
set @@optimizer_switch='default';
=========================================================================
Views and derived tables
=========================================================================
create view v1 as
select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 13);
2012-03-12 00:45:18 +02:00
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT ROWS EXAMINED inside views'
2012-03-11 14:39:20 +02:00
create view v1 as
select * from t1 where c1 IN (select * from t2 where c2 > ' ');
select * from v1;
c1
bb
cc
dd
select * from v1 LIMIT ROWS EXAMINED 17;
c1
bb
cc
dd
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 18 rows, which exceeds LIMIT ROWS EXAMINED (17). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from v1 LIMIT ROWS EXAMINED 16;
c1
bb
cc
Warnings:
2017-05-23 11:09:47 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 17 rows, which exceeds LIMIT ROWS EXAMINED (16). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from v1 LIMIT ROWS EXAMINED 11;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete
2012-03-11 14:39:20 +02:00
drop view v1;
explain
select *
from (select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp
LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra
2017-05-17 15:42:36 +03:00
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 2 func 1
2012-03-11 14:39:20 +02:00
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select *
from (select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp
LIMIT ROWS EXAMINED 11;
c1
bb
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete
2012-03-11 14:39:20 +02:00
=========================================================================
Aggregation
=========================================================================
create table t3 (c1 char(2), c2 int);
insert into t3 values
('aa', 1), ('aa', 2),
('bb', 3), ('bb', 4), ('bb', 5);
explain
select c1, sum(c2) from t3 group by c1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
select c1, sum(c2) from t3 group by c1;
c1 sum(c2)
aa 3
bb 12
explain
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0;
c1 sum(c2)
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 1;
2016-02-09 12:35:59 -08:00
c1 sum(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (1). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 20;
c1 sum(c2)
aa 3
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 21;
c1 sum(c2)
aa 3
bb 12
create table t3i (c1 char(2), c2 int);
create index it3i on t3i(c1);
create index it3j on t3i(c2,c1);
insert into t3i values
('aa', 1), ('aa', 2),
('bb', 3), ('bb', 4), ('bb', 5);
explain
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3i index NULL it3j 8 NULL 5 Using index; Using temporary; Using filesort
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0;
c1 sum(c2)
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 1;
2016-02-09 12:35:59 -08:00
c1 sum(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (1). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 20;
c1 sum(c2)
aa 3
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 21;
c1 sum(c2)
aa 3
bb 12
Aggregation without grouping
explain
select min(c2) from t3 LIMIT ROWS EXAMINED 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5
select min(c2) from t3 LIMIT ROWS EXAMINED 5;
min(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 6 rows, which exceeds LIMIT ROWS EXAMINED (5). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select max(c2) from t3 LIMIT ROWS EXAMINED 6;
max(c2)
5
select max(c2) from t3 LIMIT ROWS EXAMINED 0;
max(c2)
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
explain
select max(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using where
select max(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 5;
max(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 6 rows, which exceeds LIMIT ROWS EXAMINED (5). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select max(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 6;
max(c2)
NULL
select max(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 0;
max(c2)
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
explain
select count(c2) from t3 LIMIT ROWS EXAMINED 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5
select count(c2) from t3 LIMIT ROWS EXAMINED 5;
count(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 6 rows, which exceeds LIMIT ROWS EXAMINED (5). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select count(c2) from t3 LIMIT ROWS EXAMINED 6;
count(c2)
5
select count(c2) from t3 LIMIT ROWS EXAMINED 0;
count(c2)
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
explain
select count(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using where
select count(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 5;
count(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 6 rows, which exceeds LIMIT ROWS EXAMINED (5). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select count(c2) from t3 where c2 > 10 LIMIT ROWS EXAMINED 6;
count(c2)
0
explain
select sum(c2) from t3 LIMIT ROWS EXAMINED 5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5
select sum(c2) from t3 LIMIT ROWS EXAMINED 5;
sum(c2)
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 6 rows, which exceeds LIMIT ROWS EXAMINED (5). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select sum(c2) from t3 LIMIT ROWS EXAMINED 6;
sum(c2)
15
The query result is found during optimization, LIMIT ROWS EXAMINED has no effect.
explain
select max(c1) from t3i LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
select max(c1) from t3i LIMIT ROWS EXAMINED 0;
max(c1)
bb
create table t3_empty like t3;
explain
select max(c1) from t3_empty LIMIT ROWS EXAMINED 0;
id select_type table type possible_keys key key_len ref rows Extra
2017-12-01 12:34:37 +02:00
1 SIMPLE t3_empty system NULL NULL NULL NULL 0 Const row not found
2012-03-11 14:39:20 +02:00
select max(c1) from t3_empty LIMIT ROWS EXAMINED 0;
max(c1)
NULL
drop table t3_empty;
=========================================================================
Sorting
=========================================================================
explain
select c1, c2 from t3 order by c2, c1 LIMIT ROWS EXAMINED 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using filesort
select c1, c2 from t3 order by c2, c1 LIMIT ROWS EXAMINED 2;
2012-03-12 00:45:18 +02:00
ERROR HY000: Sort aborted:
2012-03-11 14:39:20 +02:00
explain
select c1, c2 from t3i order by c2, c1 LIMIT ROWS EXAMINED 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3i index NULL it3j 8 NULL 5 Using index
select c1, c2 from t3i order by c2, c1 LIMIT ROWS EXAMINED 2;
c1 c2
aa 1
aa 2
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2012-03-11 14:39:20 +02:00
explain
select c1, c2 from t3i order by c2, c1 desc LIMIT ROWS EXAMINED 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3i index NULL it3j 8 NULL 5 Using index; Using filesort
select c1, c2 from t3i order by c2, c1 desc LIMIT ROWS EXAMINED 2;
2012-03-12 00:45:18 +02:00
ERROR HY000: Sort aborted:
2012-03-11 14:39:20 +02:00
drop table t3,t3i;
=========================================================================
INSERT/DELETE/UPDATE
=========================================================================
INSERT ... SELECT
CREATE TABLE t4 (a int);
INSERT INTO t4 values (1), (2);
2017-02-08 15:28:00 -05:00
INSERT IGNORE INTO t4 SELECT a + 2 FROM t4 LIMIT ROWS EXAMINED 0;
2012-03-11 14:39:20 +02:00
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
select * from t4;
a
1
2
INSERT INTO t4 SELECT a + 2 FROM t4 LIMIT ROWS EXAMINED 6;
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 8 rows, which exceeds LIMIT ROWS EXAMINED (6). The query result may be incomplete
2012-03-11 14:39:20 +02:00
select * from t4;
a
1
2
3
drop table t4;
DELETE - LIMIT ROWS EXAMINED not supported
CREATE TABLE t4 (a int);
INSERT INTO t4 values (1), (2);
DELETE FROM t4 WHERE t4.a > 0 LIMIT ROWS EXAMINED 0;
2012-03-12 00:45:18 +02:00
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXAMINED 0' at line 1
2012-03-11 14:39:20 +02:00
DELETE FROM t4 WHERE t4.a > 0 LIMIT 0 ROWS EXAMINED 0;
2012-03-12 00:45:18 +02:00
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXAMINED 0' at line 1
2012-03-11 14:39:20 +02:00
drop table t4;
UPDATE - LIMIT ROWS EXAMINED not supported
CREATE TABLE t4 (a int);
INSERT INTO t4 values (1), (2);
update t4 set a=a+10 LIMIT ROWS EXAMINED 0;
2012-03-12 00:45:18 +02:00
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXAMINED 0' at line 1
2012-03-11 14:39:20 +02:00
update t4 set a=a+10 LIMIT 0 ROWS EXAMINED 0;
2012-03-12 00:45:18 +02:00
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXAMINED 0' at line 1
2012-03-11 14:39:20 +02:00
drop table t4;
drop table t1,t2,t1i,t2i;
=========================================================================
Test cases for bugs
=========================================================================
MDEV-115
SET @@optimizer_switch='in_to_exists=on,outer_join_with_cache=on';
CREATE TABLE t1 ( a VARCHAR(3) ) ENGINE=MyISAM;
2016-02-09 12:35:59 -08:00
INSERT INTO t1 VALUES ('USA'),('CAN');
2012-03-11 14:39:20 +02:00
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (3899),(3914),(3888);
CREATE TABLE t3 ( c VARCHAR(33), d INT );
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)
2012-03-12 00:45:18 +02:00
HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
2012-03-11 14:39:20 +02:00
id select_type table type possible_keys key key_len ref rows Extra
2016-02-09 12:35:59 -08:00
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)
2012-03-11 14:39:20 +02:00
2 SUBQUERY t3 ALL NULL NULL NULL NULL 3
2012-08-28 16:03:22 +04:00
2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
2012-03-11 14:39:20 +02:00
SELECT DISTINCT a AS field1 FROM t1, t2
WHERE EXISTS (SELECT c FROM t3 LEFT JOIN t2 ON b = d)
2012-03-12 00:45:18 +02:00
HAVING field1 > 'aaa' LIMIT ROWS EXAMINED 20;
2012-03-11 14:39:20 +02:00
field1
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
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
2016-02-09 12:35:59 -08:00
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
2012-03-11 14:39:20 +02:00
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 14;
a
2016-02-09 12:35:59 -08:00
USA
2012-03-11 14:39:20 +02:00
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 15 rows, which exceeds LIMIT ROWS EXAMINED (14). The query result may be incomplete
2012-03-11 14:39:20 +02:00
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 15;
a
USA
2016-02-09 12:35:59 -08:00
CAN
2012-03-11 14:39:20 +02:00
Warnings:
2016-10-03 18:49:44 +03:00
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
2012-03-11 14:39:20 +02:00
SELECT DISTINCT a FROM t1, t2 HAVING a > ' ' LIMIT ROWS EXAMINED 16;
a
USA
2016-02-09 12:35:59 -08:00
CAN
2012-03-11 14:39:20 +02:00
drop table t1,t2,t3;
set @@optimizer_switch='default';
MDEV-153
CREATE TABLE t1 ( a TIME, b DATETIME, KEY(a), KEY(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES
('21:22:34.025509', '2002-02-13 17:30:06.013935'),
('10:50:38.059966', '2008-09-27 00:34:58.026613'),
('00:21:38.058143', '2007-05-28 00:00:00');
CREATE TABLE t2 ( c INT, d TIME, e DATETIME, f VARCHAR(1), KEY(c) ) ENGINE=MyISAM;
INSERT INTO t2 VALUES
(0, '11:03:22.062907', '2007-06-02 11:16:01.053212', 'a'),
(0, '08:14:05.001407', '1900-01-01 00:00:00', 'm'),
(5, '19:03:16.024974', '1900-01-01 00:00:00', 'f'),
(1, '07:23:34.034234', '2000-11-26 05:01:11.054228', 'z'),
(6, '12:29:32.019411', '2006-02-13 00:00:00', 'f'),
(6, '06:07:10.010496', '2007-06-08 04:35:26.020373', 'a'),
(7, '22:55:09.020772', '2005-04-27 00:00:00', 'i');
EXPLAIN
SELECT a AS field1, alias2.d AS field2, alias2.f AS field3, alias2.e AS field4, b AS field5
FROM t1, t2 AS alias2, t2 AS alias3
WHERE alias3.c IN ( SELECT 1 UNION SELECT 6 )
GROUP BY field1, field2, field3, field4, field5
LIMIT ROWS EXAMINED 120;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort
1 PRIMARY alias2 ALL NULL NULL NULL NULL 7 Using join buffer (flat, BNL join)
1 PRIMARY alias3 index NULL c 5 NULL 7 Using where; Using index; Using join buffer (incremental, BNL join)
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
FLUSH STATUS;
SELECT a AS field1, alias2.d AS field2, alias2.f AS field3, alias2.e AS field4, b AS field5
FROM t1, t2 AS alias2, t2 AS alias3
WHERE alias3.c IN ( SELECT 1 UNION SELECT 6 )
GROUP BY field1, field2, field3, field4, field5
LIMIT ROWS EXAMINED 120;
2017-05-06 14:00:19 +02:00
field1 field2 field3 field4 field5
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 121 rows, which exceeds LIMIT ROWS EXAMINED (120). The query result may be incomplete
2012-03-11 14:39:20 +02:00
SHOW STATUS LIKE 'Handler_read%';
Variable_name Value
MDEV-11640 gcol.gcol_select_myisam fails in buildbot on Power
JOIN_CACHE's were initialized in check_join_cache_usage()
from make_join_readinfo(). After that make_join_readinfo() was looking
whether it's possible to use keyread. Later, after make_join_readinfo(),
optimizer decided whether to use filesort. And even later, at the
execution time, from join_read_first(), keyread was actually enabled.
The problem is, that if a query uses a vcol, base columns that it
depends on are automatically added to the read_set - because they're
needed to calculate the vcol. But if we're doing keyread, vcol is taken
from the index, not calculated, and base columns do not need to be
in the read set (even should not be - as they aren't getting values).
The bug was that JOIN_CACHE used read_set with base columns,
they were not read because of keyread, so it was caching garbage.
So read_set is only known after the keyread was decided. And after the
filesort was decided, as filesort doesn't use keyread. But
check_join_cache_usage() needs to be done in make_join_readinfo(),
as the code below depends on these checks,
Fix: keep JOIN_CACHE checks where they were, but move initialization
down to the very end of JOIN::optimize_inner. If keyread was enabled,
update the read_set to include only columns that are part of the index.
Copy the keyread logic from join_read_first() to happen at optimize time.
2017-02-06 23:52:47 +01:00
Handler_read_first 1
2017-05-06 14:00:19 +02:00
Handler_read_key 4
2012-03-12 00:45:18 +02:00
Handler_read_last 0
2017-05-06 14:00:19 +02:00
Handler_read_next 4
2012-03-11 14:39:20 +02:00
Handler_read_prev 0
2016-08-21 20:18:39 +03:00
Handler_read_retry 0
2012-03-11 14:39:20 +02:00
Handler_read_rnd 0
Handler_read_rnd_deleted 0
2017-05-06 14:00:19 +02:00
Handler_read_rnd_next 46
2012-03-11 14:39:20 +02:00
SHOW STATUS LIKE 'Handler_tmp%';
Variable_name Value
2017-03-14 11:52:00 +01:00
Handler_tmp_delete 0
2012-03-11 14:39:20 +02:00
Handler_tmp_update 0
2017-05-06 14:00:19 +02:00
Handler_tmp_write 66
2012-03-11 14:39:20 +02:00
FLUSH STATUS;
SELECT a AS field1, alias2.d AS field2, alias2.f AS field3, alias2.e AS field4, b AS field5
FROM t1, t2 AS alias2, t2 AS alias3
WHERE alias3.c IN ( SELECT 1 UNION SELECT 6 )
GROUP BY field1, field2, field3, field4, field5
2013-10-18 11:45:25 +03:00
LIMIT ROWS EXAMINED 124;
2012-03-11 14:39:20 +02:00
field1 field2 field3 field4 field5
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 125 rows, which exceeds LIMIT ROWS EXAMINED (124). The query result may be incomplete
2017-05-06 14:00:19 +02:00
Warning 1931 Query execution was interrupted. The query examined at least 127 rows, which exceeds LIMIT ROWS EXAMINED (124). The query result may be incomplete
2012-03-11 14:39:20 +02:00
SHOW STATUS LIKE 'Handler_read%';
Variable_name Value
MDEV-11640 gcol.gcol_select_myisam fails in buildbot on Power
JOIN_CACHE's were initialized in check_join_cache_usage()
from make_join_readinfo(). After that make_join_readinfo() was looking
whether it's possible to use keyread. Later, after make_join_readinfo(),
optimizer decided whether to use filesort. And even later, at the
execution time, from join_read_first(), keyread was actually enabled.
The problem is, that if a query uses a vcol, base columns that it
depends on are automatically added to the read_set - because they're
needed to calculate the vcol. But if we're doing keyread, vcol is taken
from the index, not calculated, and base columns do not need to be
in the read set (even should not be - as they aren't getting values).
The bug was that JOIN_CACHE used read_set with base columns,
they were not read because of keyread, so it was caching garbage.
So read_set is only known after the keyread was decided. And after the
filesort was decided, as filesort doesn't use keyread. But
check_join_cache_usage() needs to be done in make_join_readinfo(),
as the code below depends on these checks,
Fix: keep JOIN_CACHE checks where they were, but move initialization
down to the very end of JOIN::optimize_inner. If keyread was enabled,
update the read_set to include only columns that are part of the index.
Copy the keyread logic from join_read_first() to happen at optimize time.
2017-02-06 23:52:47 +01:00
Handler_read_first 1
2017-05-06 14:00:19 +02:00
Handler_read_key 4
2012-03-12 00:45:18 +02:00
Handler_read_last 0
2017-05-06 14:00:19 +02:00
Handler_read_next 4
2012-03-11 14:39:20 +02:00
Handler_read_prev 0
2016-08-21 20:18:39 +03:00
Handler_read_retry 0
2017-05-06 14:00:19 +02:00
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 48
2012-03-11 14:39:20 +02:00
SHOW STATUS LIKE 'Handler_tmp%';
Variable_name Value
2017-03-14 11:52:00 +01:00
Handler_tmp_delete 0
2012-03-11 14:39:20 +02:00
Handler_tmp_update 0
2013-10-18 11:45:25 +03:00
Handler_tmp_write 70
2012-03-11 14:39:20 +02:00
drop table t1, t2;
MDEV-161 LIMIT_ROWS EXAMINED: query with the limit and NOT EXISTS, without GROUP BY or aggregate,
returns rows, while the same query without the limit returns empty set
CREATE TABLE t1 ( a INT, b INT );
INSERT INTO t1 VALUES (3911,17),(3847,33),(3857,26);
CREATE TABLE t2 ( c VARCHAR(16) );
INSERT INTO t2 VALUES ('English'),('French'),('German');
CREATE TABLE t3 ( d INT, e VARCHAR(32) );
INSERT INTO t3 VALUES (3813,'United States'),(3814,'United States');
SELECT * FROM t1 AS alias1, t2 AS alias2
WHERE NOT EXISTS (
SELECT * FROM t1 LEFT OUTER JOIN t3
ON (d = a)
WHERE b <= alias1.b OR e != alias2.c
);
a b c
SELECT * FROM t1 AS alias1, t2 AS alias2
WHERE NOT EXISTS (
SELECT * FROM t1 LEFT OUTER JOIN t3
ON (d = a)
WHERE b <= alias1.b OR e != alias2.c
) LIMIT ROWS EXAMINED 20;
a b c
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 25 rows, which exceeds LIMIT ROWS EXAMINED (20). The query result may be incomplete
2012-03-11 14:39:20 +02:00
drop table t1, t2, t3;
MDEV-174: LIMIT ROWS EXAMINED: Assertion `0' failed in net_end_statement(THD*)
with subquery in SELECT, constant table, aggregate function
CREATE TABLE t1 ( a INT );
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);
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:
2018-05-31 15:51:59 +05:30
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
2012-03-11 14:39:20 +02:00
drop table t1, t2;
MDEV-178: LIMIT ROWS EXAMINED: Assertion `0' failed in net_end_statement(THD*) on the
2nd PS execution, with DISTINCT, FROM subquery or view in SELECT, JOIN in nested subquery
CREATE TABLE t1 ( a INT );
INSERT INTO t1 VALUES (2),(3),(150);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (2),(17),(3),(6);
CREATE VIEW v AS
SELECT DISTINCT * FROM t1 WHERE a > (SELECT COUNT(*) FROM t1, t2 WHERE a = b);
PREPARE ps FROM 'SELECT * FROM v LIMIT ROWS EXAMINED 21';
EXECUTE ps;
a
3
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 22 rows, which exceeds LIMIT ROWS EXAMINED (21). The query result may be incomplete
2012-03-11 14:39:20 +02:00
EXECUTE ps;
a
3
Warnings:
2016-10-03 18:49:44 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 22 rows, which exceeds LIMIT ROWS EXAMINED (21). The query result may be incomplete
2012-03-11 14:39:20 +02:00
drop view v;
drop table t1, t2;
2019-05-03 09:46:00 +05:30
#
2020-07-27 02:51:33 +05:30
# 10.1 Test
#
# MDEV-17729: Assertion `! is_set() || m_can_overwrite_status'
# failed in Diagnostics_area::set_error_status
#
set @old_mode= @@sql_mode;
CREATE TABLE t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,k INT, c CHAR(20));
INSERT INTO t1 (k,c) VALUES(0,'0'), (0,'0'),(0,'0'),(0,'0'),(0,'0'),(0,'0'),(0,'0');
SET @@sql_mode='STRICT_TRANS_TABLES';
INSERT INTO t1 (c) SELECT k FROM t1 LIMIT ROWS EXAMINED 2;
Warnings:
2020-10-21 14:02:04 +03:00
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
2020-07-27 02:51:33 +05:30
SET @@sql_mode=@old_mode;
DROP TABLE t1;
2020-10-22 13:27:18 +03:00
#
2019-05-03 09:46:00 +05:30
# MDEV-18117: Crash with Explain extended when using limit rows examined
#
create table t1 (c1 char(2));
create table t2 (c2 char(2));
insert into t1 values ('bb'), ('cc'), ('aa'), ('dd');
insert into t2 values ('bb'), ('cc'), ('dd'), ('ff');
explain extended
select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`c2` = `test`.`t1`.`c1`
drop table t1,t2;
2020-10-22 13:27:18 +03:00
# End of 10.4 tests