move test folder

This commit is contained in:
wangzelin.wzl
2022-08-12 19:29:16 +08:00
parent 29e0cb7475
commit d5269307a9
419 changed files with 275972 additions and 77007 deletions

View File

@ -0,0 +1,80 @@
drop table if exists t1,t2,t3,t4,t5;
CREATE TABLE t1 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 4;
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (2,2,2);
INSERT INTO t1 VALUES (3,3,3);
create table t2 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 5;
INSERT INTO t2 VALUES (1,1,1);
INSERT INTO t2 VALUES (2,2,2);
INSERT INTO t2 VALUES (3,3,3);
create table t3 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 6;
INSERT INTO t3 VALUES (1,1,1);
INSERT INTO t3 VALUES (2,2,2);
INSERT INTO t3 VALUES (3,3,3);
create table t4 (
c1 int primary key,
c2 int, c3 int
);
INSERT INTO t4 VALUES (1,1,1);
INSERT INTO t4 VALUES (2,2,2);
INSERT INTO t4 VALUES (3,3,3);
create table t5 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 8;
INSERT INTO t5 VALUES (1,1,1);
select * from t1 order by c1;
c1 c2 c3
1 1 1
2 2 2
3 3 3
select * from t1 order by c1,(select c1 from t2 limit 1);
c1 c2 c3
1 1 1
2 2 2
3 3 3
select * from t1 order by c1,(select c1 from t2 where t1.c1=t2.c1);
c1 c2 c3
1 1 1
2 2 2
3 3 3
select * from t1 order by c1,(select c1 from t4 where t1.c1=t4.c1);
c1 c2 c3
1 1 1
2 2 2
3 3 3
select * from t1 order by c1,(select c1 from t2 where t1.c1=t2.c1 order by c1,(select c1 from t3 where t1.c1=t3.c1));
c1 c2 c3
1 1 1
2 2 2
3 3 3
select * from t1 order by c1,(select c1 from t2);
ERROR 21000: Subquery returns more than 1 row
select * from t1 order by c1,(select c1 from t2 limit 2);
ERROR 21000: Subquery returns more than 1 row
select * from t1 order by c1,(select c1 from t2 where t1.c1<t2.c1);
ERROR 21000: Subquery returns more than 1 row
select * from t1 order by c1,(select c1 from t2 where 1=t2.c1 order by c1,(select c1 from t3));
ERROR 21000: Subquery returns more than 1 row
select * from t1 order by c1,(select c1 from t5 order by c1,(select c1 from t3));
ERROR 21000: Subquery returns more than 1 row
(select * from t1 order by c1,(select c1 from t5 order by c1,(select c1 from t3))) intersect (select * from t1 order by c1,(select c1 from t5 order by c1,(select c1 from t3)));
c1 c2 c3
1 1 1
2 2 2
3 3 3
(select * from t1 order by c1,(select c1 from t5 order by c1)) intersect (select * from t1 order by c1,(select c1 from t5 order by c1));
c1 c2 c3
1 1 1
2 2 2
3 3 3
DROP TABLE t1,t2,t3,t4,t5;

View File

@ -0,0 +1,249 @@
drop table if exists t0, t1, t2, t3;
drop view if exists v1, v2, v3, v_t2, view_b, view_c;
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (
a int,
b int
) ;
insert into t1 values (1,1),(1,1),(2,2);
create table t2 (
a int,
b int,
key(b)
) ;
insert into t2 select a, a/2 from t0;
select * from t1;
a b
1 1
1 1
2 2
select * from t2;
a b
0 0
1 1
2 1
3 2
4 2
5 3
6 3
7 4
8 4
9 5
explain select * from t2 where b in (select a from t1);
Query Plan
=============================================
|ID|OPERATOR |NAME|EST. ROWS|COST|
---------------------------------------------
|0 |HASH RIGHT SEMI JOIN| |4 |83 |
|1 | TABLE SCAN |t1 |3 |37 |
|2 | TABLE SCAN |t2 |10 |38 |
=============================================
Outputs & filters:
-------------------------------------
0 - output([t2.a], [t2.b]), filter(nil),
equal_conds([t2.b = t1.a]), other_conds(nil)
1 - output([t1.a]), filter(nil),
access([t1.a]), partitions(p0)
2 - output([t2.b], [t2.a]), filter(nil),
access([t2.b], [t2.a]), partitions(p0)
select * from t2 where b in (select a from t1);
a b
1 1
2 1
3 2
4 2
create table t3 (
a int,
b int,
key(b),
pk1 char(50), pk2 char(50), pk3 char(50),
primary key(pk1, pk2, pk3)
) ;
insert into t3 select a,a, a,a,a from t0;
explain select * from t3 where b in (select a from t1);
Query Plan
=============================================
|ID|OPERATOR |NAME|EST. ROWS|COST|
---------------------------------------------
|0 |HASH RIGHT SEMI JOIN| |4 |83 |
|1 | TABLE SCAN |t1 |3 |37 |
|2 | TABLE SCAN |t3 |10 |39 |
=============================================
Outputs & filters:
-------------------------------------
0 - output([t3.a], [t3.b], [t3.pk1], [t3.pk2], [t3.pk3]), filter(nil),
equal_conds([t3.b = t1.a]), other_conds(nil)
1 - output([t1.a]), filter(nil),
access([t1.a]), partitions(p0)
2 - output([t3.b], [t3.a], [t3.pk1], [t3.pk2], [t3.pk3]), filter(nil),
access([t3.b], [t3.a], [t3.pk1], [t3.pk2], [t3.pk3]), partitions(p0)
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
2 2 2 2 2
drop table t3;
create table t3 (
a int,
b int,
key(b),
pk1 char(100), pk2 char(100),
primary key(pk1, pk2)
) ;
insert into t3 select
A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a
from t0 A, t0 B where B.a <5;
explain select * from t3 where b in (select a from t0);
Query Plan
=============================================
|ID|OPERATOR |NAME|EST. ROWS|COST|
---------------------------------------------
|0 |HASH RIGHT SEMI JOIN| |10 |118 |
|1 | TABLE SCAN |t0 |10 |38 |
|2 | TABLE SCAN |t3 |50 |48 |
=============================================
Outputs & filters:
-------------------------------------
0 - output([t3.a], [t3.b], [t3.pk1], [t3.pk2]), filter(nil),
equal_conds([t3.b = t0.a]), other_conds(nil)
1 - output([t0.a]), filter(nil),
access([t0.a]), partitions(p0)
2 - output([t3.b], [t3.a], [t3.pk1], [t3.pk2]), filter(nil),
access([t3.b], [t3.a], [t3.pk1], [t3.pk2]), partitions(p0)
select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
a b pk1 pk2
0 0 0 0
1 1 1 1
10 10 10 10
11 11 11 11
12 12 12 12
13 13 13 13
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7
8 8 8 8
9 9 9 9
explain select * from t1 where a in (select b from t2);
Query Plan
=========================================
|ID|OPERATOR |NAME |EST. ROWS|COST|
-----------------------------------------
|0 |MERGE SEMI JOIN| |3 |81 |
|1 | SORT | |3 |39 |
|2 | TABLE SCAN |t1 |3 |37 |
|3 | TABLE SCAN |t2(b)|10 |38 |
=========================================
Outputs & filters:
-------------------------------------
0 - output([t1.a], [t1.b]), filter(nil),
equal_conds([t1.a = t2.b]), other_conds(nil)
1 - output([t1.a], [t1.b]), filter(nil), sort_keys([t1.a, ASC])
2 - output([t1.a], [t1.b]), filter(nil),
access([t1.a], [t1.b]), partitions(p0)
3 - output([t2.b]), filter(nil),
access([t2.b]), partitions(p0)
select * from t1;
a b
1 1
1 1
2 2
select * from t1 where a in (select b from t2);
a b
1 1
1 1
2 2
drop table t0, t1, t2, t3;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a char(50), b char(50), c char(50), primary key (a,b,c)) ;
insert into t2 select concat(a, repeat('X',48)),repeat('B',50),repeat('B',50) from t1;
insert into t2 select concat(a, repeat('Y',48)),repeat('B',50),repeat('B',50) from t1;
alter table t2 add filler1 int;
insert into t1 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
select * from t2 where filler1 in ( select a from t1);
a b c filler1
drop table t1, t2;
BUG#42740: crash in optimize_semijoin_nests
create table t1 (c6 timestamp,key (c6)) ;
create table t2 (c2 double) ;
drop table t1, t2;
#
# BUG#42742: crash in setup_sj_materialization, Copy_field::set
#
create table t3 ( c1 year) ;
insert into t3 values (2135),(2142);
create table t2 (c1 binary,c2 binary,c6 timestamp) ;
# The following must not crash, EXPLAIN should show one SJ strategy, not a mix:
explain select 1 from t2 where
c2 in (select 1 from t3, t2) and
c1 in (select convert(c6,char(1)) from t2);
Query Plan
==========================================================
|ID|OPERATOR |NAME |EST. ROWS|COST |
----------------------------------------------------------
|0 |HASH SEMI JOIN | |3 |235035|
|1 | HASH JOIN | |500 |99905 |
|2 | SUBPLAN SCAN |VIEW1|1 |74 |
|3 | LIMIT | |1 |74 |
|4 | NESTED-LOOP JOIN CARTESIAN| |1 |73 |
|5 | TABLE SCAN |t2 |1 |36 |
|6 | MATERIAL | |2 |37 |
|7 | TABLE SCAN |t3 |2 |37 |
|8 | TABLE SCAN |t2 |100000 |64066 |
|9 | TABLE SCAN |t2 |100000 |61860 |
==========================================================
Outputs & filters:
-------------------------------------
0 - output([1]), filter(nil),
equal_conds([cast(t2.c1, VARCHAR(1048576)) = cast(cast(t2.c6, CHAR(1)), VARCHAR(1048576))]), other_conds(nil)
1 - output([cast(t2.c1, VARCHAR(1048576))]), filter(nil),
equal_conds([cast(t2.c2, DECIMAL(-1, -1)) = VIEW1.1]), other_conds(nil)
2 - output([VIEW1.1]), filter(nil),
access([VIEW1.1])
3 - output([?]), filter(nil), limit(1), offset(nil)
4 - output([1]), filter(nil),
conds(nil), nl_params_(nil)
5 - output([1]), filter(nil),
access([t2.__pk_increment]), partitions(p0)
6 - output([1]), filter(nil)
7 - output([1]), filter(nil),
access([t3.__pk_increment]), partitions(p0)
8 - output([t2.c1], [cast(t2.c2, DECIMAL(-1, -1))]), filter(nil),
access([t2.c2], [t2.c1]), partitions(p0)
9 - output([cast(cast(t2.c6, CHAR(1)), VARCHAR(1048576))]), filter(nil),
access([t2.c6]), partitions(p0)
drop table t2, t3;
#
# BUG#57431: subquery returns wrong result (semijoin=on) with pred AND
#
CREATE TABLE t1 (
i INT
) ;
INSERT INTO t1 VALUES (2),(4);
CREATE TABLE t2 (
i INT,
vc VARCHAR(1)
) ;
INSERT INTO t2 VALUES (8,NULL);
SELECT i
FROM t1
WHERE i IN (SELECT innr.i
FROM t2 LEFT JOIN t2 innr ON innr.vc)
AND i = 2;
i
DROP TABLE t1, t2;

View File

@ -0,0 +1,77 @@
--disable_query_log
set @@session.explicit_defaults_for_timestamp=off;
--enable_query_log
#owner: ryan.ly
#owner group: SQL1
# tags: optimizer
#tags: optimizer
#description: subquery in order by clause
#
--disable_warnings
drop table if exists t1,t2,t3,t4,t5;
--enable_warnings
CREATE TABLE t1 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 4;
INSERT INTO t1 VALUES (1,1,1);
INSERT INTO t1 VALUES (2,2,2);
INSERT INTO t1 VALUES (3,3,3);
create table t2 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 5;
INSERT INTO t2 VALUES (1,1,1);
INSERT INTO t2 VALUES (2,2,2);
INSERT INTO t2 VALUES (3,3,3);
create table t3 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 6;
INSERT INTO t3 VALUES (1,1,1);
INSERT INTO t3 VALUES (2,2,2);
INSERT INTO t3 VALUES (3,3,3);
create table t4 (
c1 int primary key,
c2 int, c3 int
);
INSERT INTO t4 VALUES (1,1,1);
INSERT INTO t4 VALUES (2,2,2);
INSERT INTO t4 VALUES (3,3,3);
create table t5 (
c1 int primary key,
c2 int, c3 int
) partition by hash(c1) partitions 8;
INSERT INTO t5 VALUES (1,1,1);
select * from t1 order by c1;
select * from t1 order by c1,(select c1 from t2 limit 1);
select * from t1 order by c1,(select c1 from t2 where t1.c1=t2.c1);
select * from t1 order by c1,(select c1 from t4 where t1.c1=t4.c1);
select * from t1 order by c1,(select c1 from t2 where t1.c1=t2.c1 order by c1,(select c1 from t3 where t1.c1=t3.c1));
--error 1242
select * from t1 order by c1,(select c1 from t2);
--error 1242
select * from t1 order by c1,(select c1 from t2 limit 2);
--error 1242
select * from t1 order by c1,(select c1 from t2 where t1.c1<t2.c1);
--error 1242
select * from t1 order by c1,(select c1 from t2 where 1=t2.c1 order by c1,(select c1 from t3));
--error 1242
select * from t1 order by c1,(select c1 from t5 order by c1,(select c1 from t3));
(select * from t1 order by c1,(select c1 from t5 order by c1,(select c1 from t3))) intersect (select * from t1 order by c1,(select c1 from t5 order by c1,(select c1 from t3)));
(select * from t1 order by c1,(select c1 from t5 order by c1)) intersect (select * from t1 order by c1,(select c1 from t5 order by c1));
DROP TABLE t1,t2,t3,t4,t5;

View File

@ -0,0 +1,162 @@
--disable_query_log
set @@session.explicit_defaults_for_timestamp=off;
--enable_query_log
# owner: guoping.wgp
# owner group: sql4
# tags: optimizer
# description: 从mysql中迁移过来的基础subquery_sj_innodb.test测试集
--disable_warnings
drop table if exists t0, t1, t2, t3;
drop view if exists v1, v2, v3, v_t2, view_b, view_c;
--enable_warnings
#
# DuplicateElimination strategy test
#
-- disable_query_log
-- disable_result_log
#SET GLOBAL innodb_stats_persistent=0;
-- enable_result_log
-- enable_query_log
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
# First test simple cases: I20 order, no join buffering.
create table t1 (
a int,
b int
) ;
insert into t1 values (1,1),(1,1),(2,2);
create table t2 (
a int,
b int,
key(b)
) ;
insert into t2 select a, a/2 from t0;
sleep 1;
select * from t1;
select * from t2;
explain select * from t2 where b in (select a from t1);
select * from t2 where b in (select a from t1);
# Try an InnoDB table with very long rowid
create table t3 (
a int,
b int,
key(b),
pk1 char(50), pk2 char(50), pk3 char(50),
primary key(pk1, pk2, pk3)
) ;
insert into t3 select a,a, a,a,a from t0;
sleep 1;
explain select * from t3 where b in (select a from t1);
select * from t3 where b in (select a from t1);
# Test overflow to MyISAM:
#set @save_max_heap_table_size= @@max_heap_table_size;
#set max_heap_table_size=16384;
#set @save_join_buffer_size = @@join_buffer_size;
#set join_buffer_size= 8192;
drop table t3;
create table t3 (
a int,
b int,
key(b),
pk1 char(100), pk2 char(100),
primary key(pk1, pk2)
) ;
insert into t3 select
A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a
from t0 A, t0 B where B.a <5;
sleep 1;
--replace_column 9 #
explain select * from t3 where b in (select a from t0);
--sorted_result
select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
#set join_buffer_size= @save_join_buffer_size;
#set max_heap_table_size= @save_max_heap_table_size;
# O2I join orders, with shortcutting:
explain select * from t1 where a in (select b from t2);
select * from t1;
select * from t1 where a in (select b from t2);
drop table t0, t1, t2, t3;
# (no need for anything in range/index_merge/DS-MRR)
#
# BUG#34799: crash or/and memory overrun with dependant subquery and some joins
#
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a char(50), b char(50), c char(50), primary key (a,b,c)) ;
insert into t2 select concat(a, repeat('X',48)),repeat('B',50),repeat('B',50) from t1;
insert into t2 select concat(a, repeat('Y',48)),repeat('B',50),repeat('B',50) from t1;
alter table t2 add filler1 int;
insert into t1 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
sleep 1;
#set @save_join_buffer_size=@@join_buffer_size;
--disable_warnings
#set join_buffer_size=1;
--enable_warnings
select * from t2 where filler1 in ( select a from t1);
#set join_buffer_size=default;
drop table t1, t2;
--echo
--echo BUG#42740: crash in optimize_semijoin_nests
--echo
create table t1 (c6 timestamp,key (c6)) ;
create table t2 (c2 double) ;
#explain select 1 from t2 where c2 = any (select log10(null) from t1 where c6 <null) ;
drop table t1, t2;
--echo #
--echo # BUG#42742: crash in setup_sj_materialization, Copy_field::set
--echo #
create table t3 ( c1 year) ;
insert into t3 values (2135),(2142);
create table t2 (c1 binary,c2 binary,c6 timestamp) ;
-- echo # The following must not crash, EXPLAIN should show one SJ strategy, not a mix:
explain select 1 from t2 where
c2 in (select 1 from t3, t2) and
c1 in (select convert(c6,char(1)) from t2);
drop table t2, t3;
--echo #
--echo # BUG#57431: subquery returns wrong result (semijoin=on) with pred AND
--echo #
CREATE TABLE t1 (
i INT
) ;
INSERT INTO t1 VALUES (2),(4);
CREATE TABLE t2 (
i INT,
vc VARCHAR(1)
) ;
INSERT INTO t2 VALUES (8,NULL);
SELECT i
FROM t1
WHERE i IN (SELECT innr.i
FROM t2 LEFT JOIN t2 innr ON innr.vc)
AND i = 2;
DROP TABLE t1, t2;
-- disable_query_log
-- disable_result_log
#SET GLOBAL innodb_stats_persistent=default;
-- enable_result_log
-- enable_query_log