init push
This commit is contained in:
@ -0,0 +1,210 @@
|
||||
drop database if exists union_db;
|
||||
create database union_db;
|
||||
use union_db;
|
||||
create table t1(c1 int primary key, c2 int, c3 varchar(10));
|
||||
create table t2(c1 int primary key, c2 int, c3 varchar(10));
|
||||
insert into t1 values
|
||||
(11,11,'l'),
|
||||
(19,19,'t'),
|
||||
(18,18,'s'),
|
||||
(17,17,'r'),
|
||||
(16,16,'q'),
|
||||
(5,5,'e'),
|
||||
(4,4,'d'),
|
||||
(3,3,'c'),
|
||||
(2,2,'b'),
|
||||
(10,10,'k');
|
||||
insert into t2 values
|
||||
(1,1,'a'),
|
||||
(9,9,'i'),
|
||||
(8,8,'h'),
|
||||
(7,7,'g'),
|
||||
(6,6,'f'),
|
||||
(15,15,'p'),
|
||||
(14,14,'o'),
|
||||
(13,13,'n'),
|
||||
(12,12,'m'),
|
||||
(20,20,'u');
|
||||
### test different limit ###
|
||||
(select c2 from t1) union all (select c2 from t2) limit 1;
|
||||
c2
|
||||
2
|
||||
(select c2 from t1) union all (select c2 from t2) limit 5;
|
||||
c2
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
10
|
||||
select found_rows();
|
||||
found_rows()
|
||||
10
|
||||
(select c2 from t1) union all (select c2 from t2) limit 10;
|
||||
c2
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
10
|
||||
11
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
(select c2 from t1) union all (select c2 from t2) limit 15;
|
||||
c2
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
10
|
||||
11
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
1
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
(select c2 from t1 limit 2) union all (select c2 from t2) limit 15;
|
||||
c2
|
||||
2
|
||||
3
|
||||
1
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
20
|
||||
(select c2 from t1) union all (select c2 from t2) limit 15;
|
||||
c2
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
10
|
||||
11
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
1
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
(select c2 from t1 limit 2) union all (select c2 from t2 limit 2) limit 15;
|
||||
c2
|
||||
2
|
||||
3
|
||||
1
|
||||
6
|
||||
### test order by limit ###
|
||||
(select c2, c3 from t1) union all (select c2, c3 from t2) order by c3 limit 5;
|
||||
c2 c3
|
||||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
select found_rows();
|
||||
found_rows()
|
||||
10
|
||||
(select c2, c3 from t1) union all (select c2, c3 from t2) order by c2 limit 15;
|
||||
c2 c3
|
||||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
6 f
|
||||
7 g
|
||||
8 h
|
||||
9 i
|
||||
10 k
|
||||
11 l
|
||||
12 m
|
||||
13 n
|
||||
14 o
|
||||
15 p
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
(select c2, c3 from t1) union all (select c2, c3 from t2) order by c3, c2 limit 5;
|
||||
c2 c3
|
||||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
(select c2, c3 from t1) union all (select c2, c3 from t2) order by c2, c3 limit 15;
|
||||
c2 c3
|
||||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
6 f
|
||||
7 g
|
||||
8 h
|
||||
9 i
|
||||
10 k
|
||||
11 l
|
||||
12 m
|
||||
13 n
|
||||
14 o
|
||||
15 p
|
||||
(select c2, c3 from t1 order by c3) union all (select c2, c3 from t2) order by c2 limit 15;
|
||||
c2 c3
|
||||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
6 f
|
||||
7 g
|
||||
8 h
|
||||
9 i
|
||||
10 k
|
||||
11 l
|
||||
12 m
|
||||
13 n
|
||||
14 o
|
||||
15 p
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
(select c2, c3 from t1) union all (select c2, c3 from t2 order by c2) order by c3, c2 limit 5;
|
||||
c2 c3
|
||||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
### test for found_rows() ###
|
||||
(select SQL_CALC_FOUND_ROWS c2 from t1) union all (select c2 from t2) limit 5;
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
(select SQL_CALC_FOUND_ROWS c2 from t1) union all (select c2 from t2) limit 15;
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
(select SQL_CALC_FOUND_ROWS c2, c3 from t1) union all (select c2, c3 from t2) order by c3 limit 5;
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
(select SQL_CALC_FOUND_ROWS c2, c3 from t1) union all (select c2, c3 from t2) order by c2 limit 15;
|
||||
select found_rows();
|
||||
found_rows()
|
||||
20
|
||||
drop database union_db;
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,505 @@
|
||||
DROP DATABASE IF EXISTS DB_PREDICATE_DEDUCE;
|
||||
CREATE DATABASE DB_PREDICATE_DEDUCE;
|
||||
USE DB_PREDICATE_DEDUCE;
|
||||
create table t1(c1 int, c2 int);
|
||||
create table t2(c1 int , c2 int, c3 int, c4 int);
|
||||
create table t3(c1 bigint, c2 varchar(64), c3 datetime);
|
||||
create table is_t1(c1 int);
|
||||
create table is_t2(c1 int, c2 int);
|
||||
create table is_t3(c1 bigint, c2 varchar(64), c3 datetime);
|
||||
insert/*trace*/into t3 values(20101010000000, '020101010000000', '2010-10-10 00:00:00');
|
||||
insert/*trace*/into t1 values(NULL, NULL);
|
||||
insert/*trace*/into t2 values(NULL, NULL, NULL, NULL);
|
||||
= basic test =
|
||||
|
||||
== basic compare: case 1
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 = 2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 = 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set c1 = c2 + 1 where a.c1 = a.c2 and a.c1 = 2;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 = 2;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 = 2;
|
||||
rollback;
|
||||
|
||||
== basic compare: case 2
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 > 2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 > 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 > 2;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 > 2;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 > 2;
|
||||
rollback;
|
||||
|
||||
== basic compare: case 3
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 >= 2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 >= 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 >= 2;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 >= 2;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 >= 2;
|
||||
rollback;
|
||||
|
||||
== basic compare: case 4
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 < 2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 < 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 < 2;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 < 2;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 < 2;
|
||||
rollback;
|
||||
|
||||
== basic compare: case 5
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 <= 2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 <= 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 <= 2;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 <= 2;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 <= 2;
|
||||
rollback;
|
||||
|
||||
== basic compare: case 6
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 like '2%';
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 like '2%';
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 like '2%';
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 like '2%';
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 like '2%';
|
||||
rollback;
|
||||
|
||||
== basic compare: case 7
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 between 2 and 3;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 between 2 and 3;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 between 2 and 3;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 between 2 and 3;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 between 2 and 3;
|
||||
rollback;
|
||||
|
||||
== basic compare: case 7
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 in (2, 3);
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 in (2, 3);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 in (2, 3);
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 in (2, 3);
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 in (2, 3);
|
||||
rollback;
|
||||
************************** deduce on function *******************************
|
||||
|
||||
== deduce on function: case 1
|
||||
select /*+no_rewrite*/* from t1 a where round(a.c1) = round(a.c2) and round(a.c1) = 1;
|
||||
c1 c2
|
||||
select * from t1 a where round(a.c1) = round(a.c2) and round(a.c1) = 1;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where round(a.c1) = round(a.c2) and round(a.c1) = 1;
|
||||
delete from t1 a where round(a.c1) = round(a.c2) and round(a.c1) = 1;
|
||||
insert into is_t2 select * from t1 a where round(a.c1) = round(a.c2) and round(a.c1) = 1;
|
||||
rollback;
|
||||
|
||||
== deduce on function: case 2
|
||||
select /*+no_rewrite*/* from t1 a where round(a.c1) = a.c2 and round(a.c1) = 1;
|
||||
c1 c2
|
||||
select * from t1 a where round(a.c1) = a.c2 and round(a.c1) = 1;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where round(a.c1) = a.c2 and round(a.c1) = 1;
|
||||
delete from t1 a where round(a.c1) = a.c2 and round(a.c1) = 1;
|
||||
insert into is_t2 select * from t1 a where round(a.c1) = a.c2 and round(a.c1) = 1;
|
||||
rollback;
|
||||
***************************** subquery *********************************
|
||||
|
||||
== subquery:case 1
|
||||
select /*+no_rewrite*/* from t1 a where exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
c1 c2
|
||||
select * from t1 a where exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
delete from t1 a where exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
insert into is_t2 select * from t1 a where exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
rollback;
|
||||
|
||||
== subquery:case 2
|
||||
select /*+no_rewrite*/* from t1 a where exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
c1 c2
|
||||
select * from t1 a where exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
delete from t1 a where exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
insert into is_t2 select * from t1 a where exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
rollback;
|
||||
|
||||
== subquery:case 3
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 in (select c1 from t2 b where b.c1 = 2);
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 in (select c1 from t2 b where b.c1 = 2);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 in (select c1 from t2 b where b.c1 = 2);
|
||||
delete from t1 a where a.c1 in (select c1 from t2 b where b.c1 = 2);
|
||||
insert into is_t2 select * from t1 a where a.c1 in (select c1 from t2 b where b.c1 = 2);
|
||||
rollback;
|
||||
***************************** type check *******************************
|
||||
|
||||
== type check: case 1
|
||||
select /*+no_rewrite*/* from t3 where c1=c2 and c1=cast('2010-10-10 00:00:00' as datetime);
|
||||
c1 c2 c3
|
||||
20101010000000 020101010000000 2010-10-10 00:00:00
|
||||
select * from t3 where c1=c2 and c1=cast('2010-10-10 00:00:00' as datetime);
|
||||
c1 c2 c3
|
||||
20101010000000 020101010000000 2010-10-10 00:00:00
|
||||
start transaction;
|
||||
update t3 set c1 = 1 where c1=c2 and c1=cast('2010-10-10 00:00:00' as datetime);
|
||||
rollback;
|
||||
****************************** remove redundant predicates *************
|
||||
|
||||
== remove redundant predicates: case 1
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 = a.c2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 = a.c2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 = a.c2;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 = a.c2;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 = a.c2;
|
||||
rollback;
|
||||
|
||||
== remove redundant predicates: case 2
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c2 = a.c1;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c2 = a.c1;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c2 = a.c1;
|
||||
delete from t1 a where a.c1 = a.c2 and a.c2 = a.c1;
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c2 = a.c1;
|
||||
rollback;
|
||||
|
||||
== remove redundant predicates: case 3
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 >= a.c2 and a.c1 >= a.c2;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 >= a.c2 and a.c1 >= a.c2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 >= a.c2 and a.c1 >= a.c2;
|
||||
delete from t1 a where a.c1 >= a.c2 and a.c1 >= a.c2;
|
||||
insert into is_t2 select * from t1 a where a.c1 >= a.c2 and a.c1 >= a.c2;
|
||||
rollback;
|
||||
|
||||
== remove redundant predicates: case 4
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 >= a.c2 and a.c2 <= a.c1;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 >= a.c2 and a.c2 <= a.c1;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 >= a.c2 and a.c2 <= a.c1;
|
||||
delete from t1 a where a.c1 >= a.c2 and a.c2 <= a.c1;
|
||||
insert into is_t2 select * from t1 a where a.c1 >= a.c2 and a.c2 <= a.c1;
|
||||
rollback;
|
||||
|
||||
== remove redundant predicates: case 5
|
||||
select /*+no_rewrite*/* from t1 a where (a.c1 between 1 and 2) and (a.c1 between 1 and 2);
|
||||
c1 c2
|
||||
select * from t1 a where (a.c1 between 1 and 2) and (a.c1 between 1 and 2);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where (a.c1 between 1 and 2) and (a.c1 between 1 and 2);
|
||||
delete from t1 a where (a.c1 between 1 and 2) and (a.c1 between 1 and 2);
|
||||
insert into is_t2 select * from t1 a where (a.c1 between 1 and 2) and (a.c1 between 1 and 2);
|
||||
rollback;
|
||||
|
||||
== remove redundant predicates: case 6
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 in (2, 3) and a.c1 in (2, 3);
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 in (2, 3) and a.c1 in (2, 3);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 in (2, 3) and a.c1 in (2, 3);
|
||||
delete from t1 a where a.c1 in (2, 3) and a.c1 in (2, 3);
|
||||
insert into is_t2 select * from t1 a where a.c1 in (2, 3) and a.c1 in (2, 3);
|
||||
rollback;
|
||||
|
||||
== remove redundant predicates: case 7
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 not in (2, 3) and a.c1 not in (2, 3);
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 not in (2, 3) and a.c1 not in (2, 3);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 not in (2, 3) and a.c1 not in (2, 3);
|
||||
delete from t1 a where a.c1 not in (2, 3) and a.c1 not in (2, 3);
|
||||
insert into is_t2 select * from t1 a where a.c1 not in (2, 3) and a.c1 not in (2, 3);
|
||||
rollback;
|
||||
************************* can not deduce ******************
|
||||
|
||||
== can not deduce: case 1
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 not like '2%';
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 not like '2%';
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 not like '2%';
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 not like '2%';
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 not like '2%';
|
||||
rollback;
|
||||
|
||||
== can not deduce: case 2
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 = a.c2 and a.c1 not in (2, 3);
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 = a.c2 and a.c1 not in (2, 3);
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 = a.c2 and a.c1 not in (2, 3);
|
||||
delete from t1 a where a.c1 = a.c2 and a.c1 not in (2, 3);
|
||||
insert into is_t2 select * from t1 a where a.c1 = a.c2 and a.c1 not in (2, 3);
|
||||
rollback;
|
||||
************************* 不能推导 anti semi join ***************
|
||||
|
||||
== 不能推导 anti semi join:case 1
|
||||
select /*+no_rewrite*/* from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
c1 c2
|
||||
NULL NULL
|
||||
select * from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
c1 c2
|
||||
NULL NULL
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where not exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
delete from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
insert into is_t2 select * from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1 and b.c1 = 1);
|
||||
rollback;
|
||||
|
||||
== 能推导 anti semi join:case 2
|
||||
select /*+no_rewrite*/* from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
c1 c2
|
||||
select * from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where not exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
delete from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
insert into is_t2 select * from t1 a where not exists (select 1 from t2 b where a.c1 = b.c1) and a.c1 = 2;
|
||||
rollback;
|
||||
|
||||
== 不能推导 anti semi join:case 3
|
||||
select /*+no_rewrite*/* from t1 a where a.c1 not in (select c1 from t2 b) and a.c1 = 1;
|
||||
c1 c2
|
||||
select * from t1 a where a.c1 not in (select c1 from t2 b) and a.c1 = 1;
|
||||
c1 c2
|
||||
start transaction;
|
||||
update t1 a set a.c1 = a.c2 + 1 where a.c1 not in (select c1 from t2 b) and a.c1 = 1;
|
||||
delete from t1 a where a.c1 not in (select c1 from t2 b) and a.c1 = 1;
|
||||
insert into is_t2 select * from t1 a where a.c1 not in (select c1 from t2 b) and a.c1 = 1;
|
||||
rollback;
|
||||
************************* 不能推导 anti semi join ***************
|
||||
|
||||
select /*+ NO_REWRITE */ * from t1 a, t2 b where a.c1 = b.c1 and b.c1 is not null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
select * from t1 a, t2 b where a.c1 = b.c1 and b.c1 is not null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
|
||||
select /*+ NO_REWRITE */ * from t1 a, t2 b where a.c1 = b.c1 and b.c1 is not null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
select * from t1 a, t2 b where a.c1 = b.c1 and b.c1 is not null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
|
||||
select /*+ NO_REWRITE */ * from t1 a, t2 b where a.c1 = b.c1 and b.c1 is null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
select * from t1 a, t2 b where a.c1 = b.c1 and b.c1 is null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
|
||||
select /*+ NO_REWRITE */ * from t1 a, t2 b where a.c1 = b.c1 and b.c1 <=> null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
select * from t1 a, t2 b where a.c1 = b.c1 and b.c1 <=> null;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
|
||||
select /*+ NO_REWRITE */ * from t1 a, t2 b where a.c1 = b.c1 and b.c1 <=> 1;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
select * from t1 a, t2 b where a.c1 = b.c1 and b.c1 <=> 1;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
|
||||
select /*+ NO_REWRITE */ * from t1 a, t2 b where a.c1 <=> b.c1 and b.c1 <=> 1;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
select * from t1 a, t2 b where a.c1 <=> b.c1 and b.c1 <=> 1;
|
||||
c1 c2 c1 c2 c3 c4
|
||||
drop table if exists tt1, tt2, tt3;
|
||||
create table tt1 (c1 int primary key, c2 varchar(10));
|
||||
create table tt2 (c1 int primary key, c2 varchar(10));
|
||||
create table tt3 (c1 int primary key, c2 varchar(10));
|
||||
select /*+use_merge(tt1 tt2)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2
|
||||
1 a1 NULL NULL
|
||||
select /*+no_rewrite, use_merge(tt1 tt2)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2
|
||||
1 a1 NULL NULL
|
||||
select /*+use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 left join tt3 on tt1.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
1 a1 NULL NULL NULL NULL
|
||||
select /*+no_rewrite, use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 left join tt3 on tt1.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
1 a1 NULL NULL NULL NULL
|
||||
select /*+use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 left join tt3 on tt2.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
1 a1 NULL NULL NULL NULL
|
||||
select /*+no_rewrite, use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 left join tt3 on tt2.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
1 a1 NULL NULL NULL NULL
|
||||
select /*+use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 right join tt3 on tt1.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
select /*+no_rewrite, use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 right join tt3 on tt1.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
select /*+use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 right join tt3 on tt2.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
select /*+no_rewrite, use_merge(tt1 tt2 tt3)*/ * from tt1 left join tt2 on tt1.c1 = tt2.c1 right join tt3 on tt2.c1 = tt3.c1 where tt1.c1 = 1;
|
||||
c1 c2 c1 c2 c1 c2
|
||||
drop table if exists cghldinf, puzdjypf, pujydypf;
|
||||
CREATE TABLE `cghldinf` (
|
||||
`HLDGDDM` char(10) NOT NULL,
|
||||
`HLDZXWH` char(5) NOT NULL,
|
||||
`HLDTGDM` decimal(9, 0) NOT NULL,
|
||||
`HLDKMLB` char(2) NOT NULL,
|
||||
PRIMARY KEY (`HLDTGDM`, `HLDGDDM`),
|
||||
KEY `HLDINDEX` (`HLDKMLB`) LOCAL
|
||||
) partition by key (hldgddm) partitions 13;
|
||||
CREATE TABLE `puzdjypf` (
|
||||
`PZJZQZH` char(20) NOT NULL,
|
||||
`PZJZDJYDY` char(6) NOT NULL,
|
||||
`PZJSXRQ` decimal(8,0) NOT NULL,
|
||||
PRIMARY KEY (`PZJZQZH`)
|
||||
) partition by key (pzjzqzh) partitions 13;
|
||||
CREATE TABLE `pujydypf` (
|
||||
`PJYSCDM` char(2) NOT NULL,
|
||||
`PJYJYDY` char(6) NOT NULL,
|
||||
`PJYJYDYLB` char(3) NOT NULL,
|
||||
`PJYQSBH` char(8) NOT NULL
|
||||
) partition by key (pjyjydy) partitions 2;
|
||||
select /*+use_merge(t1 t2), leading(t1 t2 t3)*/ t1.hldgddm, t2.pzjzqzh, t2.pzjzdjydy, t3.pjyjydy, t3.pjyscdm from cghldinf t1 left join puzdjypf t2 on t2.pzjzqzh = t1.hldgddm left join pujydypf t3 on t2.pzjzdjydy = t3.pjyjydy and t3.pjyscdm = '01' where hldgddm = 'A100013208';
|
||||
hldgddm pzjzqzh pzjzdjydy pjyjydy pjyscdm
|
||||
A100013208 A100013208 20605 NULL NULL
|
||||
A100013208 A100013208 20605 NULL NULL
|
||||
select /*+no_rewrite, use_merge(t1 t2), leading(t1 t2 t3)*/ t1.hldgddm, t2.pzjzqzh, t2.pzjzdjydy, t3.pjyjydy, t3.pjyscdm from cghldinf t1 left join puzdjypf t2 on t2.pzjzqzh = t1.hldgddm left join pujydypf t3 on t2.pzjzdjydy = t3.pjyjydy and t3.pjyscdm = '01' where hldgddm = 'A100013208';
|
||||
hldgddm pzjzqzh pzjzdjydy pjyjydy pjyscdm
|
||||
A100013208 A100013208 20605 NULL NULL
|
||||
A100013208 A100013208 20605 NULL NULL
|
||||
drop table if exists t1, t2;
|
||||
create table t1 (c1 int, c2 int, primary key(c1));
|
||||
create table t2 (c1 int, c2 int, primary key(c2));
|
||||
explain extended_noaddr select count(*) from t1 A, t2 B where A.c1 >= 5630905 and A.c1 < 5631105 and A.c1 = B.c2 and A.c2 = B.c2;
|
||||
Query Plan
|
||||
==========================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
------------------------------------------
|
||||
|0 |SCALAR GROUP BY | |1 |4476|
|
||||
|1 | NESTED-LOOP JOIN| |3 |4475|
|
||||
|2 | TABLE SCAN |A |3 |4383|
|
||||
|3 | TABLE GET |B |1 |36 |
|
||||
==========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([T_FUN_COUNT(*)]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT(*)])
|
||||
1 - output([1]), filter(nil),
|
||||
conds(nil), nl_params_([A.c1]), batch_join=true
|
||||
2 - output([A.c1]), filter([A.c1 = A.c2], [A.c2 < 5631105]),
|
||||
access([A.c1], [A.c2]), partitions(p0),
|
||||
is_index_back=false, filter_before_indexback[false,false],
|
||||
range_key([A.c1]), range[5630905 ; 5631105),
|
||||
range_cond([A.c1 >= 5630905], [A.c1 < 5631105])
|
||||
3 - output([1]), filter(nil),
|
||||
access([B.c2]), partitions(p0),
|
||||
is_index_back=false,
|
||||
range_key([B.c2]), range(MIN ; MAX),
|
||||
range_cond([B.c2 < 5631105], [B.c2 >= 5630905], [? = B.c2])
|
||||
|
||||
drop table t1, t2;
|
||||
create table t1 (c1 int, c2 int, index (c1));
|
||||
create table t2 (c1 int, c2 int, index (c2));
|
||||
explain extended_noaddr select count(*) from t1 A, t2 B where A.c1 >= 5630905 and A.c1 < 5631105 and A.c1 = B.c2 and A.c2 = B.c2;
|
||||
Query Plan
|
||||
============================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
--------------------------------------------
|
||||
|0 |SCALAR GROUP BY | |1 |31312|
|
||||
|1 | NESTED-LOOP JOIN| |123 |31289|
|
||||
|2 | TABLE SCAN |A(c1)|3 |31096|
|
||||
|3 | TABLE SCAN |B(c2)|50 |45 |
|
||||
============================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([T_FUN_COUNT(*)]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT(*)])
|
||||
1 - output([1]), filter(nil),
|
||||
conds(nil), nl_params_([A.c1]), batch_join=true
|
||||
2 - output([A.c1]), filter([A.c1 = A.c2], [A.c2 < 5631105]),
|
||||
access([A.c1], [A.c2]), partitions(p0),
|
||||
is_index_back=true, filter_before_indexback[false,false],
|
||||
range_key([A.c1], [A.__pk_increment]), range(5630905,MIN ; 5631105,MIN),
|
||||
range_cond([A.c1 >= 5630905], [A.c1 < 5631105])
|
||||
3 - output([1]), filter(nil),
|
||||
access([B.c2]), partitions(p0),
|
||||
is_index_back=false,
|
||||
range_key([B.c2], [B.__pk_increment]), range(MIN ; MAX),
|
||||
range_cond([B.c2 < 5631105], [B.c2 >= 5630905], [? = B.c2])
|
||||
|
||||
drop table t1, t2;
|
||||
create table t1 (c1 int, c2 int) partition by hash(c1) partitions 4;
|
||||
create table t2 (c1 int, c2 int) partition by hash(c2) partitions 4;
|
||||
explain extended_noaddr select count(*) from t1 A, t2 B where A.c1 >= 5630905 and A.c1 < 5631105 and A.c1 = B.c2 and A.c2 = B.c2;
|
||||
Query Plan
|
||||
=======================================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
-------------------------------------------------------
|
||||
|0 |SCALAR GROUP BY | |1 |21331|
|
||||
|1 | PX COORDINATOR | |1 |20956|
|
||||
|2 | EXCHANGE OUT DISTR |:EX10000|1 |20956|
|
||||
|3 | MERGE GROUP BY | |1 |20956|
|
||||
|4 | PX PARTITION ITERATOR| |1961 |20582|
|
||||
|5 | NESTED-LOOP JOIN | |1961 |20582|
|
||||
|6 | TABLE SCAN |A |10 |17866|
|
||||
|7 | TABLE SCAN |B |198 |144 |
|
||||
=======================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([T_FUN_COUNT_SUM(T_FUN_COUNT(*))]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT_SUM(T_FUN_COUNT(*))])
|
||||
1 - output([T_FUN_COUNT(*)]), filter(nil)
|
||||
2 - output([T_FUN_COUNT(*)]), filter(nil), dop=1
|
||||
3 - output([T_FUN_COUNT(*)]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT(*)])
|
||||
4 - output([1]), filter(nil),
|
||||
partition wise, force partition granule, asc.
|
||||
5 - output([1]), filter(nil),
|
||||
conds(nil), nl_params_([A.c1]), batch_join=true
|
||||
6 - output([A.c1]), filter([A.c1 = A.c2], [A.c2 < 5631105]),
|
||||
access([A.c1], [A.c2]), partitions(p[0-3]),
|
||||
is_index_back=false, filter_before_indexback[false,false],
|
||||
range_key([A.c1], [A.__pk_increment]), range(5630905,MIN ; 5631105,MIN),
|
||||
range_cond([A.c1 >= 5630905], [A.c1 < 5631105])
|
||||
7 - output([1]), filter(nil),
|
||||
access([B.c2]), partitions(p[0-3]),
|
||||
is_index_back=false,
|
||||
range_key([B.c2], [B.__pk_increment]), range(MIN ; MAX),
|
||||
range_cond([B.c2 < 5631105], [B.c2 >= 5630905], [? = B.c2])
|
||||
|
||||
drop table if exists t1, t2, t3;
|
||||
drop table if exists tt1, tt2, tt3;
|
||||
drop table if exists cghldinf, puzdjypf, pujydypf;
|
||||
USE DB_PREDICATE_DEDUCE;
|
||||
drop database DB_PREDICATE_DEDUCE;
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user