Files
tidb/cmd/explaintest/r/subquery.result
2021-06-06 00:34:27 +08:00

49 lines
3.1 KiB
Plaintext

drop table if exists t1;
drop table if exists t2;
create table t1(a bigint, b bigint);
create table t2(a bigint, b bigint);
set session tidb_hashagg_partial_concurrency = 1;
set session tidb_hashagg_final_concurrency = 1;
explain format = 'brief' select * from t1 where t1.a in (select t1.b + t2.b from t2);
id estRows task access object operator info
HashJoin 8000.00 root CARTESIAN semi join, other cond:eq(test.t1.a, plus(test.t1.b, test.t2.b))
├─TableReader(Build) 10000.00 root data:TableFullScan
│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
└─TableReader(Probe) 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
drop table if exists t;
create table t(a int primary key, b int, c int, d int, index idx(b,c,d));
insert into t values(1,1,1,1),(2,2,2,2),(3,2,2,2),(4,2,2,2),(5,2,2,2);
analyze table t;
explain format = 'brief' select t.c in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c = 1 and s.d = t.a and s.a = t1.a) from t;
id estRows task access object operator info
Projection 5.00 root Column#22
└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#21)
├─TableReader(Build) 5.00 root data:TableFullScan
│ └─TableFullScan 5.00 cop[tikv] table:t keep order:false
└─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#21
└─IndexJoin 0.22 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a)
├─IndexReader(Build) 0.45 root index:IndexRangeScan
│ └─IndexRangeScan 0.45 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false
└─TableReader(Probe) 1.00 root data:TableRangeScan
└─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false
drop table if exists t;
create table t(a int, b int, c int);
explain format = 'brief' select a from t t1 where t1.a = (select max(t2.a) from t t2 where t1.b=t2.b and t1.c=t2.b);
id estRows task access object operator info
HashJoin 7992.00 root inner join, equal:[eq(test.t.b, test.t.b) eq(test.t.c, test.t.b) eq(test.t.a, Column#9)]
├─Selection(Build) 6393.60 root not(isnull(Column#9))
│ └─HashAgg 7992.00 root group by:test.t.b, funcs:max(Column#10)->Column#9, funcs:firstrow(test.t.b)->test.t.b
│ └─TableReader 7992.00 root data:HashAgg
│ └─HashAgg 7992.00 cop[tikv] group by:test.t.b, funcs:max(test.t.a)->Column#10
│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.b))
│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
└─TableReader(Probe) 9970.03 root data:Selection
└─Selection 9970.03 cop[tikv] not(isnull(test.t.a)), not(isnull(test.t.b)), not(isnull(test.t.c))
└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
drop table if exists t1, t2;
create table t1(a int(11));
create table t2(a decimal(40,20) unsigned, b decimal(40,20));
select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b);
x