move test folder
This commit is contained in:
File diff suppressed because it is too large
Load Diff
1696
tools/deploy/mysql_test/test_suite/join/r/mysql/join_merge.result
Normal file
1696
tools/deploy/mysql_test/test_suite/join/r/mysql/join_merge.result
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,120 @@
|
||||
result_format: 4
|
||||
explain_protocol: 2
|
||||
drop table if exists t1,t2;
|
||||
create table t1 (id int primary key, i2 int);
|
||||
create table t2 (id int primary key, i2 int);
|
||||
insert/*trace*/ into t1(id) values (75);
|
||||
insert/*trace*/ into t1(id) values (79);
|
||||
insert/*trace*/ into t1(id) values (78);
|
||||
insert/*trace*/ into t1(id) values (77);
|
||||
insert/*trace*/ into t1(id) values (104);
|
||||
insert/*trace*/ into t1(id) values (103);
|
||||
insert/*trace*/ into t1(id) values (102);
|
||||
insert/*trace*/ into t1(id) values (101);
|
||||
insert/*trace*/ into t1(id) values (105);
|
||||
insert/*trace*/ into t1(id) values (106);
|
||||
insert/*trace*/ into t1(id) values (107);
|
||||
insert/*trace*/ into t2(id) values (107),(75),(1000);
|
||||
EXPLAIN select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id>200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |t1 |1 |36 |
|
||||
|2 | TABLE GET |t2 |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.id], [t2.id]), filter(nil),
|
||||
conds(nil), nl_params_([t1.id])
|
||||
1 - output([t1.id]), filter(nil),
|
||||
access([t1.id]), partitions(p0)
|
||||
2 - output([t2.id]), filter(nil),
|
||||
access([t2.id]), partitions(p0)
|
||||
|
||||
select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id>200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id>200 and t1.id<200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |t1 |1 |36 |
|
||||
|2 | TABLE GET |t2 |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.id], [t2.id]), filter(nil),
|
||||
conds(nil), nl_params_([t1.id])
|
||||
1 - output([t1.id]), filter(nil),
|
||||
access([t1.id]), partitions(p0)
|
||||
2 - output([t2.id]), filter(nil),
|
||||
access([t2.id]), partitions(p0)
|
||||
|
||||
select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id>200 and t1.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select a.id , b.id from t1 a, t2 b where a.id = b.id and a.id>200 and a.id<200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |a |1 |36 |
|
||||
|2 | TABLE GET |b |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([a.id], [b.id]), filter(nil),
|
||||
conds(nil), nl_params_([a.id])
|
||||
1 - output([a.id]), filter(nil),
|
||||
access([a.id]), partitions(p0)
|
||||
2 - output([b.id]), filter(nil),
|
||||
access([b.id]), partitions(p0)
|
||||
|
||||
select a.id , b.id from t1 a, t2 b where a.id = b.id and a.id>200 and a.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select a.id, b.id from t1 a, t2 b where a.id = a.id and a.id>200 and a.id<200;
|
||||
Query Plan
|
||||
===================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
---------------------------------------------------
|
||||
|0 |NESTED-LOOP JOIN CARTESIAN| |3 |75 |
|
||||
|1 | TABLE SCAN |b |3 |37 |
|
||||
|2 | MATERIAL | |1 |37 |
|
||||
|3 | TABLE SCAN |a |1 |36 |
|
||||
===================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([a.id], [b.id]), filter(nil),
|
||||
conds(nil), nl_params_(nil)
|
||||
1 - output([b.id]), filter(nil),
|
||||
access([b.id]), partitions(p0)
|
||||
2 - output([a.id]), filter(nil)
|
||||
3 - output([a.id]), filter([a.id = a.id]),
|
||||
access([a.id]), partitions(p0)
|
||||
|
||||
select a.id, b.id from t1 a, t2 b where a.id = a.id and a.id>200 and a.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
drop table t1, t2;
|
||||
@ -0,0 +1,121 @@
|
||||
result_format: 4
|
||||
explain_protocol: 2
|
||||
drop table if exists t1,t2;
|
||||
create table t1 (id int primary key, i2 int);
|
||||
create table t2 (id int primary key, i2 int);
|
||||
insert/*trace*/ into t1(id) values (75);
|
||||
insert/*trace*/ into t1(id) values (79);
|
||||
insert/*trace*/ into t1(id) values (78);
|
||||
insert/*trace*/ into t1(id) values (77);
|
||||
insert/*trace*/ into t1(id) values (104);
|
||||
insert/*trace*/ into t1(id) values (103);
|
||||
insert/*trace*/ into t1(id) values (102);
|
||||
insert/*trace*/ into t1(id) values (101);
|
||||
insert/*trace*/ into t1(id) values (105);
|
||||
insert/*trace*/ into t1(id) values (106);
|
||||
insert/*trace*/ into t1(id) values (107);
|
||||
insert/*trace*/ into t2(id) values (107),(75),(1000);
|
||||
|
||||
|
||||
EXPLAIN select t1.id, t2.id from t1 join t2 on t2.id = t1.id and t1.id>200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |t1 |1 |36 |
|
||||
|2 | TABLE GET |t2 |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.id], [t2.id]), filter(nil),
|
||||
conds(nil), nl_params_([t1.id])
|
||||
1 - output([t1.id]), filter(nil),
|
||||
access([t1.id]), partitions(p0)
|
||||
2 - output([t2.id]), filter(nil),
|
||||
access([t2.id]), partitions(p0)
|
||||
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id and t1.id>200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select t1.id, t2.id from t1 join t2 on t2.id = t1.id and t1.id>200 and t1.id<200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |t1 |1 |36 |
|
||||
|2 | TABLE GET |t2 |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.id], [t2.id]), filter(nil),
|
||||
conds(nil), nl_params_([t1.id])
|
||||
1 - output([t1.id]), filter(nil),
|
||||
access([t1.id]), partitions(p0)
|
||||
2 - output([t2.id]), filter(nil),
|
||||
access([t2.id]), partitions(p0)
|
||||
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id and t1.id>200 and t1.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select a.id , b.id from t1 a join t2 b on a.id = b.id and a.id>200 and a.id<200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |a |1 |36 |
|
||||
|2 | TABLE GET |b |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([a.id], [b.id]), filter(nil),
|
||||
conds(nil), nl_params_([a.id])
|
||||
1 - output([a.id]), filter(nil),
|
||||
access([a.id]), partitions(p0)
|
||||
2 - output([b.id]), filter(nil),
|
||||
access([b.id]), partitions(p0)
|
||||
|
||||
select a.id , b.id from t1 a join t2 b on a.id = b.id and a.id>200 and a.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select a.id, b.id from t1 a join t2 b on a.id = a.id and a.id>200 and a.id<200;
|
||||
Query Plan
|
||||
===================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
---------------------------------------------------
|
||||
|0 |NESTED-LOOP JOIN CARTESIAN| |3 |75 |
|
||||
|1 | TABLE SCAN |b |3 |37 |
|
||||
|2 | MATERIAL | |1 |37 |
|
||||
|3 | TABLE SCAN |a |1 |36 |
|
||||
===================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([a.id], [b.id]), filter(nil),
|
||||
conds(nil), nl_params_(nil)
|
||||
1 - output([b.id]), filter(nil),
|
||||
access([b.id]), partitions(p0)
|
||||
2 - output([a.id]), filter(nil)
|
||||
3 - output([a.id]), filter([a.id = a.id]),
|
||||
access([a.id]), partitions(p0)
|
||||
|
||||
select a.id, b.id from t1 a join t2 b on a.id = a.id and a.id>200 and a.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
drop table t1, t2;
|
||||
@ -0,0 +1,121 @@
|
||||
result_format: 4
|
||||
explain_protocol: 2
|
||||
drop table if exists t1,t2;
|
||||
create table t1 (id int primary key, i2 int);
|
||||
create table t2 (id int primary key, i2 int);
|
||||
insert/*trace*/ into t1(id) values (75);
|
||||
insert/*trace*/ into t1(id) values (79);
|
||||
insert/*trace*/ into t1(id) values (78);
|
||||
insert/*trace*/ into t1(id) values (77);
|
||||
insert/*trace*/ into t1(id) values (104);
|
||||
insert/*trace*/ into t1(id) values (103);
|
||||
insert/*trace*/ into t1(id) values (102);
|
||||
insert/*trace*/ into t1(id) values (101);
|
||||
insert/*trace*/ into t1(id) values (105);
|
||||
insert/*trace*/ into t1(id) values (106);
|
||||
insert/*trace*/ into t1(id) values (107);
|
||||
insert/*trace*/ into t2(id) values (107),(75),(1000);
|
||||
|
||||
|
||||
EXPLAIN select t1.id, t2.id from t1 join t2 on t2.id = t1.id where t1.id>200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |t1 |1 |36 |
|
||||
|2 | TABLE GET |t2 |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.id], [t2.id]), filter(nil),
|
||||
conds(nil), nl_params_([t1.id])
|
||||
1 - output([t1.id]), filter(nil),
|
||||
access([t1.id]), partitions(p0)
|
||||
2 - output([t2.id]), filter(nil),
|
||||
access([t2.id]), partitions(p0)
|
||||
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id where t1.id>200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select t1.id, t2.id from t1 join t2 on t2.id = t1.id where t1.id>200 and t1.id<200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |t1 |1 |36 |
|
||||
|2 | TABLE GET |t2 |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.id], [t2.id]), filter(nil),
|
||||
conds(nil), nl_params_([t1.id])
|
||||
1 - output([t1.id]), filter(nil),
|
||||
access([t1.id]), partitions(p0)
|
||||
2 - output([t2.id]), filter(nil),
|
||||
access([t2.id]), partitions(p0)
|
||||
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id where t1.id>200 and t1.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select a.id , b.id from t1 a join t2 b on a.id = b.id where a.id>200 and a.id<200;
|
||||
Query Plan
|
||||
=========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------------
|
||||
|0 |NESTED-LOOP JOIN| |1 |73 |
|
||||
|1 | TABLE SCAN |a |1 |36 |
|
||||
|2 | TABLE GET |b |1 |36 |
|
||||
=========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([a.id], [b.id]), filter(nil),
|
||||
conds(nil), nl_params_([a.id])
|
||||
1 - output([a.id]), filter(nil),
|
||||
access([a.id]), partitions(p0)
|
||||
2 - output([b.id]), filter(nil),
|
||||
access([b.id]), partitions(p0)
|
||||
|
||||
select a.id , b.id from t1 a join t2 b on a.id = b.id where a.id>200 and a.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
|
||||
EXPLAIN select a.id , b.id from t1 a join t2 b on a.id = a.id where a.id>200 and a.id<200;
|
||||
Query Plan
|
||||
===================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
---------------------------------------------------
|
||||
|0 |NESTED-LOOP JOIN CARTESIAN| |3 |75 |
|
||||
|1 | TABLE SCAN |b |3 |37 |
|
||||
|2 | MATERIAL | |1 |37 |
|
||||
|3 | TABLE SCAN |a |1 |36 |
|
||||
===================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([a.id], [b.id]), filter(nil),
|
||||
conds(nil), nl_params_(nil)
|
||||
1 - output([b.id]), filter(nil),
|
||||
access([b.id]), partitions(p0)
|
||||
2 - output([a.id]), filter(nil)
|
||||
3 - output([a.id]), filter([a.id = a.id]),
|
||||
access([a.id]), partitions(p0)
|
||||
|
||||
select a.id , b.id from t1 a join t2 b on a.id = a.id where a.id>200 and a.id<200;
|
||||
+----+----+
|
||||
| id | id |
|
||||
+----+----+
|
||||
+----+----+
|
||||
drop table t1, t2;
|
||||
289
tools/deploy/mysql_test/test_suite/join/t/anti_semi_join.test
Normal file
289
tools/deploy/mysql_test/test_suite/join/t/anti_semi_join.test
Normal file
@ -0,0 +1,289 @@
|
||||
#owner: xiaoyi.xy
|
||||
#owner group: sql1
|
||||
# tags: optimizer
|
||||
##
|
||||
## Test Name: anti_join.test
|
||||
## Date: 2017-12-28
|
||||
|
||||
--disable_query_log
|
||||
set @@session.explicit_defaults_for_timestamp=off;
|
||||
--enable_query_log
|
||||
|
||||
--result_format 4
|
||||
--explain_protocol 2
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists xy_t1, xy_t2;
|
||||
--enable_warnings
|
||||
|
||||
create table xy_t1(c1 int, c2 int);
|
||||
create table xy_t2(c1 int, c2 int);
|
||||
--sleep 3
|
||||
|
||||
insert/*insert trace*/ into xy_t1 values(0, 0), (1,1), (2,2), (5,5), (5,5), (6,7), (6,6), (7,7);
|
||||
insert/*insert trace*/ into xy_t2 values(1,1), (3,3), (5,5), (5,5), (6,6);
|
||||
|
||||
--echo
|
||||
--echo # ************** 测试anti仅含equal condition的情况 *******
|
||||
select /*+ USE_NL(xy_t1, xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1);
|
||||
--echo
|
||||
select /*+ USE_MERGE(xy_t1, xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1);
|
||||
--echo
|
||||
select /*+ USE_HASH(xy_t1, xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1);
|
||||
--echo # ************* end *******************
|
||||
|
||||
--echo
|
||||
--echo # ************** 测试anti含other condition的情况 *******
|
||||
select /*+ USE_NL(xy_t1, xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_MERGE(xy_t1, xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_HASH(xy_t1, xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo # ************** end *********
|
||||
|
||||
--echo
|
||||
--echo # ************** 测试semi仅含equal condition的情况 *******
|
||||
select /*+ USE_NL(xy_t1, xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1);
|
||||
--echo
|
||||
select /*+ USE_MERGE(xy_t1, xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1);
|
||||
--echo
|
||||
select /*+ USE_HASH(xy_t1, xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1);
|
||||
--echo # ************* end *******************
|
||||
|
||||
--echo
|
||||
--echo # ************** 测试semi join含other condition的情况 *******
|
||||
select /*+ USE_NL(xy_t1, xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_MERGE(xy_t1, xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_HASH(xy_t1, xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo # ************** end *********
|
||||
|
||||
--echo
|
||||
--echo # ************** 测试上层算子需要投影的情况 ********
|
||||
select /*+ USE_NL(xy_t1, xy_t2)*/ c1, c2, c1, c2 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_MERGE(xy_t1, xy_t2)*/ c1, c2, c1, c2 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_HASH(xy_t1, xy_t2)*/ c1, c2, c1, c2 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_NL(xy_t1, xy_t2)*/ c1, c2, c1, c2 from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_MERGE(xy_t1, xy_t2)*/ c1, c2, c1, c2 from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo
|
||||
select /*+ USE_HASH(xy_t1, xy_t2)*/ c1, c2, c1, c2 from xy_t1 where exists (select 1 from xy_t2 where xy_t1.c1 = xy_t2.c1 and xy_t1.c2 > xy_t2.c2);
|
||||
--echo # ************** end ********
|
||||
|
||||
drop table xy_t1, xy_t2;
|
||||
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists xy_x_t, xy_y_t;
|
||||
--enable_warnings
|
||||
create table xy_x_t(x1 int, x2 varchar(100));
|
||||
create table xy_y_t(y1 int, y2 varchar(100));
|
||||
--sleep 3
|
||||
insert/*insert trace*/ into xy_x_t values(NULL,"VECPQ"),(NULL,"bdarkyzh"),(NULL,"it"),(NULL,"tgn"),(NULL,"had"),(NULL,"b"),(NULL,"g"),(NULL,"it's"),(NULL,"r"),(NULL,"KSZCK"),(NULL,"s"),(NULL,"UJRXI"),(NULL,"HLKDP"),(NULL,"about"),(NULL,"ROITX"),(NULL,"OEJAP"),(NULL,"u"),(NULL,"egisjnib"),(NULL,"ozkegisjn"),(NULL,"oh"),(NULL,"lrlmds"),(NULL,"r"),(NULL,"a"),(NULL,"here"),(NULL,"ihrad"),(NULL,"good"),(-2139029504,"eyqjoq"),(-2061369344,"GSUGA"),(-1882128384,"there"),(-1552613376,"d"),(-1511981056,"and"),(-1504706560,"and"),(-1259929600,"o"),(-973340672,"at"),(-918945792,"DNMFW"),(-778960896,"r"),(-753336320,"PKGAE"),(-593821696,"UGSPN"),(-457179136,"got"),(-314638336,"will"),(-233701376,"o"),(-104202240,"SUEUH"),(0,"yzh"),(0,"i"),(1,"TQOYB"),(1,"FFHTJ"),(2,"it's"),(2,"ezcuilyxac"),(2,"VZLUW"),(2,"want"),(2,"think"),(3,"prsazev"),(3,"get"),(3,"out"),(4,"a"),(4,"PVYPZ"),(4,"k"),(4,"bpqswbeyqj"),(4,"isjn"),(4,"that's"),(4,"well"),(5,"arkyz"),(5,"w"),(5,"with"),(5,"just"),(5,"PFBCU"),(6,"uyslpcybda"),(6,"co"),(6,"u"),(6,"j"),(6,"g"),(7,"cybdark"),(7,"BKWPE"),(8,"lmdsl"),(8,"NNIGT"),(8,"of"),(9,"etu"),(9,"TBMEI"),(9,"QPPLC"),(9,"mdsl"),(27262976,"n"),(162267136,"to"),(199884800,"y"),(334364672,"h"),(597295104,"did"),(748814336,"rhljip"),(769916928,"OQKEV"),(839778304,"USTRY"),(947585024,"hey"),(1210777600,"want"),(1232601088,"azev"),(1250689024,"a"),(1329463296,"QAMOL"),(1573126144,"zcuilyx"),(1594753024,"yeah"),(1730215936,"PMUMX"),(1925709824,"g"),(2048262144,"b"),(2082275328,"k"),(2131492864,"was");
|
||||
insert/*insert trace*/ into xy_y_t values(NULL,"mmkfu"),(NULL,"c"),(NULL,"know"),(NULL,"ZYTQH"),(NULL,"j"),(NULL,"y"),(NULL,"what"),(NULL,"SXXNL"),(NULL,"b"),(NULL,"NFZFZ"),(-1992359936,"not"),(-1711210496,"uoorvy"),(-1150287872,"BKNFS"),(-926613504,"was"),(-858128384,"y"),(-549126144,"v"),(-537198592,"now"),(-491651072,"t"),(-66125824,"here"),(0,"XCYGJ"),(1,"YGHBI"),(2,"g"),(6,"kfuoorvyvn"),(7,"EGBLS"),(9,"jsnsdfm"),(1584463872,"face");
|
||||
|
||||
--echo
|
||||
select /*+use_hash(xy_x_t xy_y_t)*/ * from xy_x_t where x1 in (select y1 from xy_y_t where y2 < xy_x_t.x2);
|
||||
select /*+use_merge(xy_x_t xy_y_t)*/ * from xy_x_t where x1 in (select y1 from xy_y_t where y2 < xy_x_t.x2);
|
||||
select /*+use_nl(xy_x_t xy_y_t)*/ * from xy_x_t where x1 in (select y1 from xy_y_t where y2 < xy_x_t.x2);
|
||||
--echo
|
||||
|
||||
drop table xy_x_t, xy_y_t;
|
||||
create table xy_x_t(x1 int not null, x2 varchar(100) not null);
|
||||
create table xy_y_t(y1 int not null, y2 varchar(100) not null);
|
||||
--sleep 3
|
||||
insert/*insert trace*/ into xy_x_t values(-2139029504,"eyqjoq"),(-2061369344,"GSUGA"),(-1882128384,"there"),(-1552613376,"d"),(-1511981056,"and"),(-1504706560,"and"),(-1259929600,"o"),(-973340672,"at"),(-918945792,"DNMFW"),(-778960896,"r"),(-753336320,"PKGAE"),(-593821696,"UGSPN"),(-457179136,"got"),(-314638336,"will"),(-233701376,"o"),(-104202240,"SUEUH"),(0,"yzh"),(0,"i"),(1,"TQOYB"),(1,"FFHTJ"),(2,"it's"),(2,"ezcuilyxac"),(2,"VZLUW"),(2,"want"),(2,"think"),(3,"prsazev"),(3,"get"),(3,"out"),(4,"a"),(4,"PVYPZ"),(4,"k"),(4,"bpqswbeyqj"),(4,"isjn"),(4,"that's"),(4,"well"),(5,"arkyz"),(5,"w"),(5,"with"),(5,"just"),(5,"PFBCU"),(6,"uyslpcybda"),(6,"co"),(6,"u"),(6,"j"),(6,"g"),(7,"cybdark"),(7,"BKWPE"),(8,"lmdsl"),(8,"NNIGT"),(8,"of"),(9,"etu"),(9,"TBMEI"),(9,"QPPLC"),(9,"mdsl"),(27262976,"n"),(162267136,"to"),(199884800,"y"),(334364672,"h"),(597295104,"did"),(748814336,"rhljip"),(769916928,"OQKEV"),(839778304,"USTRY"),(947585024,"hey"),(1210777600,"want"),(1232601088,"azev"),(1250689024,"a"),(1329463296,"QAMOL"),(1573126144,"zcuilyx"),(1594753024,"yeah"),(1730215936,"PMUMX"),(1925709824,"g"),(2048262144,"b"),(2082275328,"k"),(2131492864,"was");
|
||||
insert/*insert trace*/ into xy_y_t values(-1992359936,"not"),(-1711210496,"uoorvy"),(-1150287872,"BKNFS"),(-926613504,"was"),(-858128384,"y"),(-549126144,"v"),(-537198592,"now"),(-491651072,"t"),(-66125824,"here"),(0,"XCYGJ"),(1,"YGHBI"),(2,"g"),(6,"kfuoorvyvn"),(7,"EGBLS"),(9,"jsnsdfm"),(1584463872,"face");
|
||||
|
||||
select /*+use_hash(xy_x_t xy_y_t)*/ * from xy_x_t where x1 not in (select y1 from xy_y_t where y2 < xy_x_t.x2);
|
||||
select /*+use_merge(xy_x_t xy_y_t)*/ * from xy_x_t where x1 not in (select y1 from xy_y_t where y2 < xy_x_t.x2);
|
||||
select /*+use_nl(xy_x_t xy_y_t)*/ * from xy_x_t where x1 not in (select y1 from xy_y_t where y2 < xy_x_t.x2);
|
||||
|
||||
drop table xy_x_t, xy_y_t;
|
||||
|
||||
|
||||
### ********************* test right semi/anti join
|
||||
--disable_warnings
|
||||
drop table if exists xy_t1, xy_t2, xy_t3, xy_t4;
|
||||
--enable_warnings
|
||||
create table xy_t1(c1 int, c2 int, key idx_c2(c2, c1));
|
||||
create table xy_t2(c1 int, c2 int, key idx_c2(c2, c1));
|
||||
create table xy_t3(c1 int, c2 int, key idx_c2(c2, c1));
|
||||
create table xy_t4(c1 int, c2 int, key idx_c2(c2, c1));
|
||||
--sleep 3
|
||||
|
||||
insert/*insert trace*/ into xy_t1 values(0, 0), (1,1), (2, null),(2,2), (5,5), (5,5), (5,7),(6,7), (6,6), (6, null),(7,7), (7, 0), (8,0), (8,8), (8, 5), (9, 0), (9, 7), (10,10), (null, 1), (1,1), (3,3), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (0, 0), (1,1), (2, null),(2,2), (5,5), (5,5), (5,7),(6,7), (6,6), (6, null),(7,7), (7, 0), (8,0), (8,8), (8, 5), (9, 0), (9, 7), (10,10), (null, 1), (1,1), (3,3), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (0, 0), (1,1), (2, null),(2,2), (5,5), (5,5), (5,7),(6,7), (6,6), (6, null),(7,7), (7, 0), (8,0), (8,8), (8, 5), (9, 0), (9, 7), (10,10), (null, 1), (1,1), (3,3), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (0, 0), (1,1), (2, null),(2,2), (5,5), (5,5), (5,7),(6,7), (6,6), (6, null),(7,7), (7, 0), (8,0), (8,8), (8, 5), (9, 0), (9, 7), (10,10), (null, 1), (1,1), (3,3), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1), (20,1);
|
||||
insert/*insert trace*/ into xy_t2 values(null, 1), (1,1), (3,3), (5,5), (5,6), (5,4), (6,6), (9,9);
|
||||
insert/*insert trace*/ into xy_t3 values(1,1), (3,3), (5,5), (5,6), (5,4), (6,6), (9,9), (5,7),(6,7), (6,6), (6, null),(7,7);
|
||||
insert/*insert trace*/ into xy_t4 values(1,1), (3,3);
|
||||
|
||||
--echo
|
||||
--echo ***************** RIGHT HASH SEMI 最优
|
||||
select * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ no_rewrite */ * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
|
||||
--echo
|
||||
--echo ***************** HASH SEMI 最优
|
||||
select * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_nl(xy_t2 xy_t1)*/ * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_hash(xy_t2 xy_t1)*/ * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_merge(xy_t2 xy_t1)*/ * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
|
||||
--echo
|
||||
--echo **************** NL SEMI 最优
|
||||
select * from xy_t4 where exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
select /*+ use_nl(xy_t4 xy_t1)*/ * from xy_t4 where exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
select /*+ use_hash(xy_t4 xy_t1)*/ * from xy_t4 where exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
select /*+ use_merge(xy_t4 xy_t1)*/ * from xy_t4 where exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
|
||||
|
||||
--echo
|
||||
--echo **************** MERGE SEMI 最优
|
||||
select * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
select /*+ use_nl(xy_t2 xy_t1)*/ * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
select /*+ use_hash(xy_t2 xy_t1)*/ * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
select /*+ use_merge(xy_t2 xy_t1)*/ * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
|
||||
|
||||
--echo
|
||||
--echo ***************** RIGHT HASH ANTI 最优
|
||||
select * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ no_rewrite */ * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
|
||||
--echo
|
||||
--echo ***************** HASH ANTI 最优
|
||||
select * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_nl(xy_t2 xy_t1)*/ * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_hash(xy_t2 xy_t1)*/ * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select /*+ use_merge(xy_t2 xy_t1)*/ * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
|
||||
--echo
|
||||
--echo **************** NL ANTI 最优
|
||||
select * from xy_t4 where not exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
select /*+ use_nl(xy_t4 xy_t1)*/ * from xy_t4 where not exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
select /*+ use_hash(xy_t4 xy_t1)*/ * from xy_t4 where not exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
select /*+ use_merge(xy_t4 xy_t1)*/ * from xy_t4 where not exists (select 1 from xy_t1 where xy_t4.c1 = xy_t1.c2);
|
||||
|
||||
--echo
|
||||
--echo **************** MERGE ANTI 最优
|
||||
select * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
select /*+ use_nl(xy_t2 xy_t1)*/ * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
select /*+ use_hash(xy_t2 xy_t1)*/ * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
select /*+ use_merge(xy_t2 xy_t1)*/ * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c2 = xy_t1.c2);
|
||||
|
||||
--echo
|
||||
--echo *************** 测试3表情况
|
||||
select sum(c1), sum(c2) from xy_t1 where exists (select 1 from xy_t3 where c1 = xy_t1.c1) and exists (select 1 from xy_t2 where c1 = xy_t1.c1);
|
||||
select /*+ use_hash(xy_t3, xy_t1) use_hash(xy_t2, xy_t1)*/ sum(c1), sum(c2) from xy_t1 where exists (select 1 from xy_t3 where c1 = xy_t1.c1) and exists (select 1 from xy_t2 where c1 = xy_t1.c1);
|
||||
select /*+ no_rewrite*/ sum(c1), sum(c2) from xy_t1 where exists (select 1 from xy_t3 where c1 = xy_t1.c1) and exists (select 1 from xy_t2 where c1 = xy_t1.c1);
|
||||
|
||||
--echo
|
||||
select sum(c1), sum(c2) from xy_t1 where not exists (select 1 from xy_t3 where c2 = xy_t1.c2) and exists (select 1 from xy_t2 where c2 = xy_t1.c2);
|
||||
select /*+ no_rewrite*/ sum(c1), sum(c2) from xy_t1 where not exists (select 1 from xy_t3 where c2 = xy_t1.c2) and exists (select 1 from xy_t2 where c2 = xy_t1.c2);
|
||||
|
||||
--echo
|
||||
--echo *************** 测试limit下压 HASH RIGHT SEMI加limit后情况, limit 小时, SEMI代价会小, limit 太大后代价不影响
|
||||
select * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1) limit 3;
|
||||
select * from xy_t1 where exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1) limit 1000;
|
||||
|
||||
--echo
|
||||
--echo *************** 测试limit下压 HASH LEFT SEMI加limit后情况, limit不影响SEMI代价
|
||||
select * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1) limit 3;
|
||||
select * from xy_t2 where exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1) limit 1000;
|
||||
|
||||
|
||||
--echo
|
||||
--echo *************** 测试limit下压 HASH RIGHT ANTI加limit后情况, limit 小时, ANTI代价会小, limit 太大后代价不影响
|
||||
select * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1);
|
||||
select * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1) limit 3;
|
||||
select * from xy_t1 where not exists (select 1 from xy_t2 where xy_t2.c1 = xy_t1.c1) limit 1000;
|
||||
|
||||
--echo
|
||||
--echo *************** 测试limit下压 HASH LEFT ANTI加limit后情况, limit 不影响ANTI代价
|
||||
select * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1);
|
||||
select * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1) limit 3;
|
||||
select * from xy_t2 where not exists (select 1 from xy_t1 where xy_t2.c1 = xy_t1.c1) limit 1000;
|
||||
|
||||
drop table xy_t1, xy_t2, xy_t3;
|
||||
|
||||
--echo
|
||||
--echo ************** 测试SEMI/ANTI 含unique order的场景
|
||||
create table xy_t1(c1 int primary key, c2 int, c3 int);
|
||||
create table xy_t2(c1 int primary key, c2 int, c3 int);
|
||||
--sleep 3
|
||||
insert/*insert trace*/ into xy_t1 values(0, 0, 0), (1,1, 1), (2,2, 2), (3,5, 5), (5,5, 5), (6,7,7), (7,6, 6), (8, 7,8);
|
||||
insert/*insert trace*/ into xy_t2 values(1,1, 1), (3,3,3), (4,5,5), (5,5, 5), (6,6,7);
|
||||
|
||||
--echo
|
||||
--echo //两边都无序hash right
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c2, c3 from xy_t1 where c2 in (select c2 from xy_t2 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c2, c3 from xy_t1 where c2 in (select c2 from xy_t2 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c2, c3 from xy_t1 where c2 in (select c2 from xy_t2 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ no_rewrite*/ c2, c3 from xy_t1 where c2 in (select c2 from xy_t2 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo //两边都无序hash left
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c2, c3 from xy_t2 where c2 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c2, c3 from xy_t2 where c2 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c2, c3 from xy_t2 where c2 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ no_rewrite*/ c2, c3 from xy_t2 where c2 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo //两边唯一有序, 改写为inner join
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where c1 in (select c1 from xy_t1 where xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where c1 in (select c1 from xy_t1 where xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
# bug: https://work.aone.alibaba-inc.com/issue/27311279
|
||||
# select /*+ use_nl(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where c1 in (select c1 from xy_t1 where xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
select /*+ no_rewrite*/ c1, c2 from xy_t2 where c1 in (select c1 from xy_t1 where xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo // 一边唯一有序
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where c1 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where c1 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where c1 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ no_rewrite*/ c1, c2 from xy_t2 where c1 in (select c2 from xy_t1 where xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo //两边都无序hash right
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c2, c3 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c2, c3 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c2, c3 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ no_rewrite*/ c2, c3 from xy_t1 where not exists (select 1 from xy_t2 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo //两边都无序hash left
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c2, c3 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c2, c3 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c2, c3 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ no_rewrite*/ c2, c3 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c2 = xy_t2.c2 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo // 两边唯一有序
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c1 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c1 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c1 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
select /*+ no_rewrite*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c1 and xy_t1.c3 < xy_t2.c3) order by 1,2;
|
||||
|
||||
--echo
|
||||
--echo //一边唯一有序
|
||||
select /*+ use_hash(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c2 and xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
select /*+ use_merge(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c2 and xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
select /*+ use_nl(xy_t1 xy_t2)*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c2 and xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
select /*+ no_rewrite*/ c1, c2 from xy_t2 where not exists (select 1 from xy_t1 where xy_t1.c1 = xy_t2.c2 and xy_t1.c2 < xy_t2.c2) order by 1,2;
|
||||
|
||||
drop table xy_t1, xy_t2;
|
||||
|
||||
|
||||
|
||||
295
tools/deploy/mysql_test/test_suite/join/t/join_merge.test
Normal file
295
tools/deploy/mysql_test/test_suite/join/t/join_merge.test
Normal file
@ -0,0 +1,295 @@
|
||||
--disable_query_log
|
||||
set @@session.explicit_defaults_for_timestamp=off;
|
||||
--enable_query_log
|
||||
# owner: yibo.tyf
|
||||
# owner group: SQL3
|
||||
# tags: optimizer
|
||||
# description:
|
||||
# 1. test desc for merge join.
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists aa;
|
||||
drop table if exists bb;
|
||||
drop table if exists cc;
|
||||
--enable_warnings
|
||||
create table aa(a1 int primary key auto_increment, a2 int, a3 int);
|
||||
create table bb(b1 int primary key auto_increment, b2 int, b3 int);
|
||||
create table cc(c1 int primary key auto_increment, c2 int, c3 int);
|
||||
#single layer merge join.
|
||||
delete from aa;
|
||||
insert into aa(a2, a3) values (10, 15), (10, 14), (10, 12), (11, 13), (12, 12), (12, 10);
|
||||
delete from bb;
|
||||
insert into bb(b2, b3) values (10, 14), (11, 14), (11, 13), (12, 11), (12, 10);
|
||||
--sleep 1
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
delete from aa;
|
||||
insert into aa(a2, a3) values (10, 15), (10, 14), (10, 12), (11, 13), (12, 12), (12, 10);
|
||||
delete from bb;
|
||||
insert into bb(b2, b3) values (10, 14), (11, 14), (11, 13), (12, 11), (12, 10);
|
||||
--sleep 1
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
#double layers merge join.
|
||||
delete from cc;
|
||||
insert into cc(c2, c3) values (10, 15), (10, 14), (10, 12), (12, 10);
|
||||
--sleep 1
|
||||
select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and b2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
explain select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and b2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and a2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
explain select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and a2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
--disable_warnings
|
||||
drop table if exists tt1,tt2;
|
||||
--enable_warnings
|
||||
CREATE TABLE `tt1` (
|
||||
`a` int(11) NOT NULL,
|
||||
`b` int(11) DEFAULT NULL,
|
||||
`c` varchar(20) DEFAULT NULL,
|
||||
`d` datetime NOT NULL,
|
||||
PRIMARY KEY (`a`)
|
||||
);
|
||||
CREATE TABLE `tt2` (
|
||||
`a` int(11) NOT NULL,
|
||||
`b` int(11) DEFAULT NULL,
|
||||
`c` varchar(20) DEFAULT NULL,
|
||||
`d` datetime NOT NULL,
|
||||
PRIMARY KEY (`a`)
|
||||
);
|
||||
explain basic select /*+ use_merge(tt1, tt2) */ * from tt1,tt2 where tt1.a=tt2.a order by tt1.d desc;
|
||||
explain basic select /*+ use_merge(tt1, tt2) */ * from tt1,tt2 where tt1.a=tt2.a order by tt1.a desc;
|
||||
explain basic select /*+ use_merge(tt1, tt2) */ * from tt1,tt2 where tt1.a=tt2.a order by tt1.c desc;
|
||||
--disable_warnings
|
||||
drop table if exists tt1,tt2;
|
||||
--enable_warnings
|
||||
--disable_warnings
|
||||
|
||||
--echo == test partitioned table merge join ==
|
||||
--disable_warnings
|
||||
drop table if exists aa;
|
||||
drop table if exists bb;
|
||||
drop table if exists cc;
|
||||
--enable_warnings
|
||||
create table aa(a1 int, a2 int, a3 int) partition by hash(a1) partitions 5;
|
||||
create table bb(b1 int, b2 int, b3 int) partition by hash(b1) partitions 5;
|
||||
create table cc(c1 int, c2 int, c3 int) partition by hash(c1) partitions 5;
|
||||
#single layer merge join.
|
||||
delete from aa;
|
||||
insert into aa values (1, 10, 15), (2, 10, 14), (3, 10, 12), (4, 11, 13), (5, 12, 12), (6, 12, 10);
|
||||
delete from bb;
|
||||
insert into bb values (1, 10, 14), (2, 11, 14), (3, 11, 13), (4, 12, 11), (5, 12, 10);
|
||||
--sleep 1
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
delete from aa;
|
||||
insert into aa values (1, 10, 15), (2, 10, 14), (3, 10, 12), (4, 11, 13), (5, 12, 12), (6, 12, 10);
|
||||
delete from bb;
|
||||
insert into bb values (1, 10, 14), (2, 11, 14), (3, 11, 13), (4, 12, 11), (5, 12, 10);
|
||||
--sleep 1
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2, a3 desc;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3;
|
||||
select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
explain select /*+ use_merge(aa, bb) */ a2, b3 from aa, bb where a2 = b2 and a3 = b3 order by a2 desc, a3 desc;
|
||||
#double layers merge join.
|
||||
delete from cc;
|
||||
insert into cc values (1, 10, 15), (2, 10, 14), (3, 10, 12), (4, 12, 10);
|
||||
--sleep 1
|
||||
select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and b2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
explain select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and b2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and a2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
explain select /*+ leading(aa bb cc) use_merge(aa, bb, cc) */ c2, a3 from aa, bb, cc where a2 = b2 and a3 = b3 and a2 = c2 and b3 = c3 order by c2, c3 desc;
|
||||
--disable_warnings
|
||||
drop table if exists tt1,tt2;
|
||||
--enable_warnings
|
||||
CREATE TABLE `tt1` (
|
||||
`a` int(11) NOT NULL,
|
||||
`b` int(11) DEFAULT NULL,
|
||||
`c` varchar(20) DEFAULT NULL,
|
||||
`d` datetime NOT NULL,
|
||||
PRIMARY KEY (`a`)
|
||||
) partition by hash(a) partitions 5;
|
||||
CREATE TABLE `tt2` (
|
||||
`a` int(11) NOT NULL,
|
||||
`b` int(11) DEFAULT NULL,
|
||||
`c` varchar(20) DEFAULT NULL,
|
||||
`d` datetime NOT NULL,
|
||||
PRIMARY KEY (`a`)
|
||||
) partition by hash(a) partitions 5;
|
||||
explain basic select /*+ use_merge(tt1, tt2) */ * from tt1,tt2 where tt1.a=tt2.a order by tt1.d desc;
|
||||
explain basic select /*+ use_merge(tt1, tt2) */ * from tt1,tt2 where tt1.a=tt2.a order by tt1.a desc;
|
||||
explain basic select /*+ use_merge(tt1, tt2) */ * from tt1,tt2 where tt1.a=tt2.a order by tt1.c desc;
|
||||
--disable_warnings
|
||||
drop table if exists tt1,tt2;
|
||||
--enable_warnings
|
||||
--disable_warnings
|
||||
drop table if exists aa;
|
||||
drop table if exists bb;
|
||||
drop table if exists cc;
|
||||
--enable_warnings
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t_r4_01_20;
|
||||
--enable_warnings
|
||||
|
||||
create table t_r4_01_20(a int, b int, c datetime, primary key (a,b))
|
||||
partition by range columns(a)
|
||||
(
|
||||
partition p6 values less than (6),
|
||||
partition p11 values less than (11),
|
||||
partition p16 values less than (16),
|
||||
partition pm values less than (MAXVALUE)
|
||||
);
|
||||
insert into t_r4_01_20 values ( 1, 1, 20161101), ( 2, 2, 20161102), ( 3, 3, 20161103), ( 4, 4, 20161104),
|
||||
( 5, 5, 20161105), ( 6, 6, 20161106), ( 7, 7, 20161107), ( 8, 8, 20161108),
|
||||
( 9, 9, 20161109), (10, 10, 20161110), (11, 11, 20161111), (12, 12, 20161112),
|
||||
(13, 13, 20161113), (14, 14, 20161114), (15, 15, 20161115), (16, 16, 20161116),
|
||||
(17, 17, 20161117), (18, 18, 20161118), (19, 19, 20161119), (20, 20, 20161120);
|
||||
--sleep 1
|
||||
|
||||
|
||||
select /*+use_merge(t1 t2)*/ t1.a, t2.a from t_r4_01_20 t1 inner join t_r4_01_20 t2 on t1.a = t2.a order by t1.a desc, t2.a desc;
|
||||
explain basic select /*+use_merge(t1 t2)*/ t1.a, t2.a from t_r4_01_20 t1 inner join t_r4_01_20 t2 on t1.a = t2.a order by t1.a desc, t2.a desc;
|
||||
|
||||
explain select /*+use_merge(t1 t2)*/ t1.a, t2.a from t_r4_01_20 t1 inner join t_r4_01_20 t2 on t1.a = t2.a order by t1.a asc, t2.a asc;
|
||||
select /*+use_merge(t1 t2)*/ t1.a, t2.a from t_r4_01_20 t1 inner join t_r4_01_20 t2 on t1.a = t2.a order by t1.a asc, t2.a asc;
|
||||
--disable_warnings
|
||||
drop table if exists t_r4_01_20;
|
||||
--enable_warnings
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t2, t7;
|
||||
--enable_warnings
|
||||
create table t2(a int, b varchar(20), c decimal(20,10));
|
||||
create table t7(a int(10), b varchar(10), c char(20), d decimal(20,10));
|
||||
insert into t2 values(1, "222", 3.33),(2,"222",3.33),(2,"333",2.22),(3,"3333",1.11), (5, "555", 5.55), (6, "6666", 5.5),(1, '1', 1), (1, '2', 2), (2, '2.00', 2.00001), (3, '3.0', 3.00001), (4, "A", 4.33), (5, "B", 5), (6, "AB", 6);
|
||||
insert into t7 values(65, '222', '333', 5), (65, '444', '5.550', 1), (66, '3.0', '555', 3.00001), (66, '2', 'B', 2), (67, 'A', '1', 1);
|
||||
--sleep 1
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t8, t9;
|
||||
--enable_warnings
|
||||
create table t8(a int primary key, b int, c int, index idx(b,c));
|
||||
create table t9(a int primary key, b int, c int, index idx(b,c));
|
||||
--disable_query_log
|
||||
insert into t8 values (1, 2, 1);
|
||||
insert into t8 values (2, 2, 2);
|
||||
insert into t8 values (3, 2, 3);
|
||||
insert into t8 values (4, 4, 1);
|
||||
insert into t8 values (5, 4, 2);
|
||||
insert into t8 values (6, 4, 3);
|
||||
|
||||
insert into t9 values (1, 2, 1);
|
||||
insert into t9 values (2, 2, 2);
|
||||
insert into t9 values (3, 2, 3);
|
||||
insert into t9 values (4, 3, 1);
|
||||
insert into t9 values (5, 4, 1);
|
||||
insert into t9 values (6, 4, 2);
|
||||
insert into t9 values (7, 4, 3);
|
||||
--sleep 1
|
||||
--enable_query_log
|
||||
|
||||
--echo
|
||||
--echo ************ 测试full join
|
||||
explain select /*+use_merge(t2,t7)*/* from t2 full join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_merge(t2,t7)*/* from t2 full join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
--echo
|
||||
explain select /*+use_hash(t2,t7)*/* from t2 full join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_hash(t2,t7)*/* from t2 full join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
--echo
|
||||
explain select /*+use_nl(t2,t7)*/* from t2 full join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_nl(t2,t7)*/* from t2 full join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
|
||||
--echo ************ 测试right join
|
||||
--echo
|
||||
explain select /*+use_merge(t2,t7)*/* from t2 right join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_merge(t2,t7)*/* from t2 right join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
--echo
|
||||
explain select /*+use_hash(t2,t7)*/* from t2 right join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_hash(t2,t7)*/* from t2 right join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
--echo
|
||||
explain select /*+use_nl(t2,t7)*/* from t2 right join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_nl(t2,t7)*/* from t2 right join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
|
||||
explain select /*+leading(t8, t9)*/ t8.b,t8.c,t9.b,t9.c from t8 right join t9 on t8.b = t9.b;
|
||||
select /*+leading(t8, t9)*/ t8.b,t8.c,t9.b,t9.c from t8 right join t9 on t8.b = t9.b;
|
||||
|
||||
--echo ************ 测试left join
|
||||
--echo
|
||||
explain select /*+use_merge(t2,t7)*/* from t2 left join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_merge(t2,t7)*/* from t2 left join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
--echo
|
||||
explain select /*+use_hash(t2,t7)*/* from t2 left join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_hash(t2,t7)*/* from t2 left join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
--echo
|
||||
explain select /*+use_nl(t2,t7)*/* from t2 left join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
select /*+use_nl(t2,t7)*/* from t2 left join t7 on t2.b = t7.a and t2.c = t7.d order by t2.a,t2.b,t7.a,t7.b;
|
||||
|
||||
|
||||
|
||||
--echo ********** join condition 必须和 ordering 排序一致
|
||||
explain select /*+use_merge(t8 t9)*/ * from t8 join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
select /*+use_merge(t8 t9)*/ * from t8 join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
|
||||
explain select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
|
||||
explain select /*+use_merge(t8 t9)*/ * from t8 left join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
select /*+use_merge(t8 t9)*/ * from t8 left join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
|
||||
explain select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 left join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 left join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
|
||||
explain select /*+use_merge(t8 t9)*/ * from t8 right join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
select /*+use_merge(t8 t9)*/ * from t8 right join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
|
||||
explain select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 right join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 right join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
|
||||
explain select /*+use_merge(t8 t9)*/ * from t8 right join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
select /*+use_merge(t8 t9)*/ * from t8 right join t9 on t8.c = t9.c and t8.b = t9.b;
|
||||
|
||||
explain select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 full join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
select /*+index(t8 idx), index(t9 idx), use_merge(t8 t9)*/ * from t8 full join t9 on t8.a = t9.b and t8.b = t9.a;
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists BB,CC;
|
||||
--enable_warnings
|
||||
CREATE TABLE BB ( col_varchar_key varchar (1), col_varchar_10 varchar(10), col_varchar varchar (1), col_int_key int, col_varchar_10_key varchar(10), col_varchar_20_key varchar(20), col_int int, col_varchar_20 varchar(20), pk int, /*Indices*/ key idx3(pk, col_varchar_key ), key idx1(pk, col_int_key ), key idx5(pk, col_varchar_10_key ), key idx7(pk, col_varchar_20_key ), primary key (pk) );
|
||||
|
||||
|
||||
CREATE TABLE CC ( col_varchar_key varchar (1), col_varchar_20_key varchar(20), col_varchar_20 varchar(20), col_int_key int, col_int int, pk int, col_varchar_10 varchar(10), col_varchar_10_key varchar(10), col_varchar varchar (1), /*Indices*/ key idx3(pk, col_varchar_key ), key idx7(pk, col_varchar_20_key ), key idx1(pk, col_int_key ), primary key (pk) , key idx5(pk, col_varchar_10_key )) ;
|
||||
|
||||
--disable_query_log
|
||||
INSERT INTO BB VALUES ('d', 'n', NULL, NULL, 'm', 'p', 2, 'v', 1) , (NULL, 'i', 'w', 6, 'n', 'r', 9, 'f', 2) , ('k', NULL, 'a', 8, 'p', NULL, NULL, 'j', 3) , (NULL, NULL, NULL, 4, 'b', 'b', 4, 'o', 4) , ('b', 'u', 'z', 7, 'k', 'e', 9, 'z', 5) , ('n', 'm', 's', 5, NULL, 'p', 6, 'y', 6) , ('f', 'e', 'f', 9, 'o', 'i', 9, 't', 7) , ('a', 'u', 's', NULL, 'l', 'g', 6, 'k', 8) , ('s', 'd', NULL, 1, 'r', 'g', NULL, 'j', 9) , ('y', NULL, 'j', 8, 'u', 'v', 7, 'b', 10) , ('w', 'i', NULL, 1, 'v', NULL, 1, NULL, 11) , ('t', NULL, NULL, 6, 'v', 'b', 3, NULL, 12) , ('m', 'i', 'd', 6, 'l', NULL, 3, 't', 13) , ('m', 'l', 'z', 6, 'a', 'b', NULL, 'b', 14) , ('d', 'y', 'c', 9, NULL, 'e', 7, 'g', 15) , ('e', 'm', 'w', 4, 'c', 'u', 6, 'a', 16) , ('a', NULL, 'j', 8, 'd', 'z', NULL, 's', 17) , ('h', 'u', NULL, 5, 't', 'p', 4, NULL, 18) , ('p', 'l', 'u', 8, 'e', 's', 6, 'm', 19) , ('l', 'l', 'h', 1, 'b', 'i', 8, 'z', 20) , ('i', 'f', NULL, NULL, 'g', 'e', NULL, 'p', 21) , ('l', 'w', 'p', 9, 'g', 'b', 4, 'k', 22) , ('j', 'd', 'l', 4, 'x', 'z', NULL, 'u', 23) , ('t', 'a', 'y', 8, 'o', 'e', 8, 'a', 24) , (NULL, 'a', 'a', 0, NULL, 'd', 9, 'm', 25) , (NULL, 'b', NULL, 3, 'i', 'r', NULL, 'i', 26) , ('s', 'v', NULL, 4, 'w', NULL, NULL, 'p', 27) , ('m', 'x', 'y', 0, 'n', 'i', 6, 'k', 28) ;
|
||||
|
||||
INSERT INTO CC VALUES ('x', 'r', 'v', 7, 8, 1, 't', 'j', 't') , (NULL, 'b', 'z', 2, 9, 2, 'p', 'u', 'y') , (NULL, 'q', 'e', 6, NULL, 3, 'u', 's', 'j') , ('d', NULL, 'n', 4, 3, 4, 'n', NULL, 'm') , ('y', 'u', 'b', 8, NULL, 5, 'z', NULL, 't') , ('p', 'f', 'm', 7, 1, 6, NULL, 'k', 'w') , ('m', 'w', 'f', 2, 9, 7, 't', 'w', 'g') , ('w', 'n', 'm', 3, 8, 8, NULL, 't', 'z') , ('o', 'g', 'i', 5, 0, 9, 't', 'a', NULL) , ('m', 'v', 'm', NULL, 7, 10, NULL, 'h', NULL) , ('u', 'm', 'j', 3, 4, 11, 'f', NULL, 'q') , ('h', 'y', NULL, 7, 4, 12, 'k', 't', NULL) , (NULL, 'h', 'g', NULL, 6, 13, 'v', 'd', 'u') , (NULL, NULL, NULL, 4, 5, 14, NULL, 'v', 'm') , ('f', 'x', 'm', 4, 8, 15, 'd', NULL, NULL) , ('s', 'f', 'x', 0, 2, 16, 'l', NULL, 'f') , ('t', 'o', 's', NULL, 8, 17, 'r', NULL, 'r') , ('h', 's', NULL, NULL, 3, 18, 'd', 'r', 'k') , ('u', 'w', 'r', 7, NULL, 19, 'w', NULL, 'c') , ('i', 'o', NULL, 8, 0, 20, 'n', 'i', 'y') , (NULL, NULL, NULL, 9, NULL, 21, 'm', NULL, 'm') , ('p', 'g', 'k', 9, NULL, 22, 'g', 'x', 'v') , (NULL, 'q', NULL, NULL, 2, 23, 'f', 'g', 's') , (NULL, NULL, 'p', 9, 0, 24, 'e', NULL, 'v') , (NULL, 'q', 'm', 3, 9, 25, 'w', 'i', 'm') , ('e', NULL, 'e', 5, NULL, 26, NULL, 'k', 'f') , ('i', 'm', 'n', 0, 4, 27, 'g', NULL, 'a') , ('r', 'g', 'o', 2, NULL, 28, 'c', NULL, 'u') , ('y', NULL, 'o', 2, NULL, 29, 'h', 'n', 'o') ;
|
||||
--enable_query_log
|
||||
|
||||
explain SELECT /*+no_rewrite,leading(table1 table2),use_merge(table1 table2)*/ table1 . col_varchar_10_key AS field1 FROM BB AS table1, CC AS table2 WHERE table1 . `col_int_key` = table2 . `pk` and table2 . `col_int_key` = table1 . `pk` ORDER BY table1 . col_int_key DESC;
|
||||
|
||||
SELECT /*+no_rewrite,leading(table1 table2),use_merge(table1 table2)*/ table1 . col_varchar_10_key AS field1 FROM BB AS table1, CC AS table2 WHERE table1 . `col_int_key` = table2 . `pk` and table2 . `col_int_key` = table1 . `pk` ORDER BY table1 . col_int_key DESC;
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t2, t7, t8, t9, BB, CC;
|
||||
--enable_warnings
|
||||
@ -0,0 +1,36 @@
|
||||
--disable_query_log
|
||||
set @@session.explicit_defaults_for_timestamp=off;
|
||||
--enable_query_log
|
||||
# owner: xiaoyi.xy
|
||||
# owner group: SQL3
|
||||
# tags: optimizer
|
||||
# description: OUR GOAL: Make all this simple and effective!
|
||||
--result_format 4
|
||||
--explain_protocol 2
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2;
|
||||
--enable_warnings
|
||||
create table t1 (id int primary key, i2 int);
|
||||
create table t2 (id int primary key, i2 int);
|
||||
insert/*trace*/ into t1(id) values (75);
|
||||
insert/*trace*/ into t1(id) values (79);
|
||||
insert/*trace*/ into t1(id) values (78);
|
||||
insert/*trace*/ into t1(id) values (77);
|
||||
insert/*trace*/ into t1(id) values (104);
|
||||
insert/*trace*/ into t1(id) values (103);
|
||||
insert/*trace*/ into t1(id) values (102);
|
||||
insert/*trace*/ into t1(id) values (101);
|
||||
insert/*trace*/ into t1(id) values (105);
|
||||
insert/*trace*/ into t1(id) values (106);
|
||||
insert/*trace*/ into t1(id) values (107);
|
||||
insert/*trace*/ into t2(id) values (107),(75),(1000);
|
||||
select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id>200;
|
||||
--echo
|
||||
select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id>200 and t1.id<200;
|
||||
--echo
|
||||
select a.id , b.id from t1 a, t2 b where a.id = b.id and a.id>200 and a.id<200;
|
||||
--echo
|
||||
select a.id, b.id from t1 a, t2 b where a.id = a.id and a.id>200 and a.id<200;
|
||||
|
||||
drop table t1, t2;
|
||||
@ -0,0 +1,37 @@
|
||||
--disable_query_log
|
||||
set @@session.explicit_defaults_for_timestamp=off;
|
||||
--enable_query_log
|
||||
# owner: xiaoyi.xy
|
||||
# owner group: SQL3
|
||||
# tags: optimizer
|
||||
# description: OUR GOAL: Make all this simple and effective!
|
||||
--result_format 4
|
||||
--explain_protocol 2
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2;
|
||||
--enable_warnings
|
||||
create table t1 (id int primary key, i2 int);
|
||||
create table t2 (id int primary key, i2 int);
|
||||
insert/*trace*/ into t1(id) values (75);
|
||||
insert/*trace*/ into t1(id) values (79);
|
||||
insert/*trace*/ into t1(id) values (78);
|
||||
insert/*trace*/ into t1(id) values (77);
|
||||
insert/*trace*/ into t1(id) values (104);
|
||||
insert/*trace*/ into t1(id) values (103);
|
||||
insert/*trace*/ into t1(id) values (102);
|
||||
insert/*trace*/ into t1(id) values (101);
|
||||
insert/*trace*/ into t1(id) values (105);
|
||||
insert/*trace*/ into t1(id) values (106);
|
||||
insert/*trace*/ into t1(id) values (107);
|
||||
insert/*trace*/ into t2(id) values (107),(75),(1000);
|
||||
|
||||
--echo
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id and t1.id>200;
|
||||
--echo
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id and t1.id>200 and t1.id<200;
|
||||
--echo
|
||||
select a.id , b.id from t1 a join t2 b on a.id = b.id and a.id>200 and a.id<200;
|
||||
--echo
|
||||
select a.id, b.id from t1 a join t2 b on a.id = a.id and a.id>200 and a.id<200;
|
||||
drop table t1, t2;
|
||||
@ -0,0 +1,37 @@
|
||||
--disable_query_log
|
||||
set @@session.explicit_defaults_for_timestamp=off;
|
||||
--enable_query_log
|
||||
# owner: xiaoyi.xy
|
||||
# owner group: SQL3
|
||||
# tags: optimizer
|
||||
# description: OUR GOAL: Make all this simple and effective!
|
||||
--result_format 4
|
||||
--explain_protocol 2
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2;
|
||||
--enable_warnings
|
||||
create table t1 (id int primary key, i2 int);
|
||||
create table t2 (id int primary key, i2 int);
|
||||
insert/*trace*/ into t1(id) values (75);
|
||||
insert/*trace*/ into t1(id) values (79);
|
||||
insert/*trace*/ into t1(id) values (78);
|
||||
insert/*trace*/ into t1(id) values (77);
|
||||
insert/*trace*/ into t1(id) values (104);
|
||||
insert/*trace*/ into t1(id) values (103);
|
||||
insert/*trace*/ into t1(id) values (102);
|
||||
insert/*trace*/ into t1(id) values (101);
|
||||
insert/*trace*/ into t1(id) values (105);
|
||||
insert/*trace*/ into t1(id) values (106);
|
||||
insert/*trace*/ into t1(id) values (107);
|
||||
insert/*trace*/ into t2(id) values (107),(75),(1000);
|
||||
|
||||
--echo
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id where t1.id>200;
|
||||
--echo
|
||||
select t1.id, t2.id from t1 join t2 on t2.id = t1.id where t1.id>200 and t1.id<200;
|
||||
--echo
|
||||
select a.id , b.id from t1 a join t2 b on a.id = b.id where a.id>200 and a.id<200;
|
||||
--echo
|
||||
select a.id , b.id from t1 a join t2 b on a.id = a.id where a.id>200 and a.id<200;
|
||||
drop table t1, t2;
|
||||
Reference in New Issue
Block a user