[ { "Name": "TestLimitCrossEstimation", "Cases": [ { "SQL": [ "set session tidb_opt_correlation_exp_factor = 0", "EXPLAIN SELECT * FROM t WHERE b = 2 ORDER BY a limit 1;" ], "Plan": [ "TopN_8 1.00 root test.t.a:asc, offset:0, count:1", "└─IndexReader_16 1.00 root index:TopN_15", " └─TopN_15 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " └─IndexRangeScan_14 10.00 cop[tikv] table:t, index:idx_bc(b, c) range:[2,2], keep order:false, stats:pseudo" ] }, { "SQL": [ "insert into t (a, b) values (1, 1),(2, 1),(3, 1),(4, 1),(5, 1),(6, 1),(7, 1),(8, 1),(9, 1),(10, 1),(11, 1),(12, 1),(13, 1),(14, 1),(15, 1),(16, 1),(17, 1),(18, 1),(19, 1),(20, 2),(21, 2),(22, 2),(23, 2),(24, 2),(25, 2)", "analyze table t", "EXPLAIN SELECT * FROM t WHERE b = 2 ORDER BY a limit 1" ], "Plan": [ "TopN_8 1.00 root test.t.a:asc, offset:0, count:1", "└─IndexReader_16 1.00 root index:TopN_15", " └─TopN_15 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " └─IndexRangeScan_14 6.00 cop[tikv] table:t, index:idx_bc(b, c) range:[2,2], keep order:false" ] }, { "SQL": [ "truncate table t", "insert into t (a, b) values (1, 25),(2, 24),(3, 23),(4, 23),(5, 21),(6, 20),(7, 19),(8, 18),(9, 17),(10, 16),(11, 15),(12, 14),(13, 13),(14, 12),(15, 11),(16, 10),(17, 9),(18, 8),(19, 7),(20, 6),(21, 5),(22, 4),(23, 3),(24, 2),(25, 1)", "analyze table t", "EXPLAIN SELECT * FROM t WHERE b <= 6 ORDER BY a limit 1" ], "Plan": [ "TopN_8 1.00 root test.t.a:asc, offset:0, count:1", "└─IndexReader_16 1.00 root index:TopN_15", " └─TopN_15 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " └─IndexRangeScan_14 6.00 cop[tikv] table:t, index:idx_bc(b, c) range:[-inf,6], keep order:false" ] }, { "SQL": [ "EXPLAIN SELECT *, t1.a IN (SELECT t2.b FROM t t2) FROM t t1 WHERE t1.b <= 6 ORDER BY t1.a limit 1" ], "Plan": [ "Limit_17 1.00 root offset:0, count:1", "└─IndexJoin_62 1.00 root left outer semi join, inner:IndexReader_61, outer key:test.t.a, inner key:test.t.b, equal cond:eq(test.t.a, test.t.b)", " ├─TopN_25(Build) 1.00 root test.t.a:asc, offset:0, count:1", " │ └─IndexReader_33 1.00 root index:TopN_32", " │ └─TopN_32 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " │ └─IndexRangeScan_31 6.00 cop[tikv] table:t1, index:idx_bc(b, c) range:[-inf,6], keep order:false", " └─IndexReader_61(Probe) 1.04 root index:IndexRangeScan_60", " └─IndexRangeScan_60 1.04 cop[tikv] table:t2, index:idx_bc(b, c) range: decided by [eq(test.t.b, test.t.a)], keep order:false" ] }, { "SQL": [ "truncate table t", "insert into t (a, b) values (1, 1),(2, 1),(3, 1),(4, 1),(5, 1),(6, 1),(7, 2),(8, 2),(9, 2),(10, 2),(11, 2),(12, 2),(13, 2),(14, 2),(15, 2),(16, 2),(17, 2),(18, 2),(19, 2),(20, 2),(21, 2),(22, 2),(23, 2),(24, 2),(25, 2)", "analyze table t", "EXPLAIN SELECT * FROM t WHERE b = 1 ORDER BY a desc limit 1" ], "Plan": [ "TopN_8 1.00 root test.t.a:desc, offset:0, count:1", "└─IndexReader_16 1.00 root index:TopN_15", " └─TopN_15 1.00 cop[tikv] test.t.a:desc, offset:0, count:1", " └─IndexRangeScan_14 6.00 cop[tikv] table:t, index:idx_bc(b, c) range:[1,1], keep order:false" ] }, { "SQL": [ "truncate table t", "insert into t (a, b) values (1, 1),(2, 1),(3, 1),(4, 1),(5, 1),(6, 1),(7, 1),(8, 1),(9, 2),(10, 1),(11, 1),(12, 1),(13, 1),(14, 2),(15, 2),(16, 1),(17, 2),(18, 1),(19, 2),(20, 1),(21, 2),(22, 1),(23, 1),(24, 1),(25, 1)", "analyze table t", "EXPLAIN SELECT * FROM t WHERE b = 2 ORDER BY a limit 1" ], "Plan": [ "Limit_11 1.00 root offset:0, count:1", "└─TableReader_22 1.00 root data:Limit_21", " └─Limit_21 1.00 cop[tikv] offset:0, count:1", " └─Selection_20 1.00 cop[tikv] eq(test.t.b, 2)", " └─TableFullScan_19 4.17 cop[tikv] table:t keep order:true" ] }, { "SQL": [ "set session tidb_opt_correlation_exp_factor = 1", "EXPLAIN SELECT * FROM t WHERE b = 2 ORDER BY a limit 1" ], "Plan": [ "TopN_8 1.00 root test.t.a:asc, offset:0, count:1", "└─IndexReader_16 1.00 root index:TopN_15", " └─TopN_15 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " └─IndexRangeScan_14 6.00 cop[tikv] table:t, index:idx_bc(b, c) range:[2,2], keep order:false" ] }, { "SQL": [ "set session tidb_opt_correlation_exp_factor = 0", "truncate table t", "insert into t (a, b) values (1, 1),(2, 1),(3, 1),(4, 1),(5, 1),(6, 1),(7, 1),(8, 1),(9, 1),(10, 1),(11, 1),(12, 1),(13, 1),(14, 1),(15, 1),(16, 1),(17, 1),(18, 1),(19, 1),(20, 2),(21, 2),(22, 2),(23, 2),(24, 2),(25, 2)", "analyze table t", "EXPLAIN SELECT * FROM t WHERE b = 2 and a > 0 ORDER BY a limit 1" ], "Plan": [ "TopN_8 1.00 root test.t.a:asc, offset:0, count:1", "└─IndexReader_19 1.00 root index:TopN_18", " └─TopN_18 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " └─Selection_17 6.00 cop[tikv] gt(test.t.a, 0)", " └─IndexRangeScan_16 6.00 cop[tikv] table:t, index:idx_bc(b, c) range:[2,2], keep order:false" ] }, { "SQL": [ "drop table t", "create table t(a int primary key, b int, c int, d bigint default 2147483648, e bigint default 2147483648, f bigint default 2147483648, index idx(b,d,a,c))", "insert into t(a, b, c) values (1, 1, 1),(2, 1, 2),(3, 1, 1),(4, 1, 2),(5, 1, 1),(6, 1, 2),(7, 1, 1),(8, 1, 2),(9, 1, 1),(10, 1, 2),(11, 1, 1),(12, 1, 2),(13, 1, 1),(14, 1, 2),(15, 1, 1),(16, 1, 2),(17, 1, 1),(18, 1, 2),(19, 1, 1),(20, 2, 2),(21, 2, 1),(22, 2, 2),(23, 2, 1),(24, 2, 2),(25, 2, 1)", "analyze table t", "EXPLAIN SELECT a FROM t WHERE b = 2 and c > 0 ORDER BY a limit 1" ], "Plan": [ "Projection_7 1.00 root test.t.a", "└─TopN_8 1.00 root test.t.a:asc, offset:0, count:1", " └─IndexReader_17 1.00 root index:TopN_16", " └─TopN_16 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", " └─Selection_15 6.00 cop[tikv] gt(test.t.c, 0)", " └─IndexRangeScan_14 6.00 cop[tikv] table:t, index:idx(b, d, a, c) range:[2,2], keep order:false" ] } ] }, { "Name": "TestIssue9562", "Cases": [ { "SQL": [ "create table t1(a bigint, b bigint, c bigint)", "create table t2(a bigint, b bigint, c bigint, index idx(a, b, c))", "explain select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t2.a=t1.a and t2.b>t1.b-1 and t2.bColumn#13", " └─HashJoin_23 1.00 root inner join, equal:[eq(test.t.a, test.t.a)]", " ├─TableReader_33(Build) 1.00 root data:Selection_32", " │ └─Selection_32 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", " │ └─TableFullScan_31 10.00 cop[tikv] table:t1 keep order:false", " └─TableReader_27(Probe) 1.00 root data:Selection_26", " └─Selection_26 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", " └─TableFullScan_25 10.00 cop[tikv] table:s keep order:false" ], [ "Projection_8 10.00 root Column#9", "└─Apply_10 10.00 root CARTESIAN left outer join", " ├─TableReader_12(Build) 10.00 root data:TableFullScan_11", " │ └─TableFullScan_11 10.00 cop[tikv] table:t keep order:false", " └─MaxOneRow_15(Probe) 1.00 root ", " └─Projection_16 0.10 root concat(cast(test.t.a, var_string(20)), ,, cast(test.t.b, var_string(20)))->Column#9", " └─IndexReader_19 0.10 root index:Selection_18", " └─Selection_18 0.10 cop[tikv] eq(test.t.a, test.t.a)", " └─IndexRangeScan_17 1.00 cop[tikv] table:t1, index:idx(c, b, a) range: decided by [eq(test.t.c, test.t.c)], keep order:false" ] ] }, { "Name": "TestLowSelIndexGreedySearch", "Cases": [ { "SQL": "explain select max(e) from t where a='T3382' and b='ECO' and c='TOPIC' and d='23660fa1ace9455cb7f3ee831e14a342'", "Plan": [ "StreamAgg_14 1.00 root funcs:max(test.t.e)->Column#7", "└─TopN_17 0.00 root test.t.e:desc, offset:0, count:1", " └─IndexLookUp_49 0.00 root ", " ├─IndexRangeScan_46(Build) 0.00 cop[tikv] table:t, index:idx2(a, c) range:[\"T3382\" \"TOPIC\",\"T3382\" \"TOPIC\"], keep order:false", " └─Selection_48(Probe) 0.00 cop[tikv] eq(test.t.b, \"ECO\"), eq(test.t.d, \"23660fa1ace9455cb7f3ee831e14a342\"), not(isnull(test.t.e))", " └─TableRowIDScan_47 0.00 cop[tikv] table:t keep order:false" ] } ] }, { "Name": "TestEmptyTable", "Cases": [ "TableReader(Table(t)->Sel([le(test.t.c1, 50)]))", "LeftHashJoin{TableReader(Table(t)->Sel([not(isnull(test.t.c1))]))->TableReader(Table(t1)->Sel([not(isnull(test.t1.c1))]))->HashAgg}(test.t.c1,test.t1.c1)", "LeftHashJoin{TableReader(Table(t)->Sel([not(isnull(test.t.c1))]))->TableReader(Table(t1)->Sel([not(isnull(test.t1.c1))]))}(test.t.c1,test.t1.c1)", "Dual" ] }, { "Name": "TestIndexRead", "Cases": [ "IndexReader(Index(t.e)[[NULL,+inf]])->HashAgg", "IndexReader(Index(t.e)[[-inf,10]]->StreamAgg)->StreamAgg", "IndexReader(Index(t.e)[[-inf,50]]->StreamAgg)->StreamAgg", "IndexReader(Index(t.b_c)[[NULL,+inf]]->Sel([gt(test.t.c, 1)])->HashAgg)->HashAgg", "IndexLookUp(Index(t.e)[[1,1]], Table(t))->HashAgg", "TableReader(Table(t)->Sel([gt(test.t.e, 1)])->HashAgg)->HashAgg", "IndexLookUp(Index(t.b)[[-inf,20]], Table(t)->HashAgg)->HashAgg", "TableReader(Table(t)->Sel([le(test.t.b, 30)])->StreamAgg)->StreamAgg", "TableReader(Table(t)->Sel([le(test.t.b, 40)])->StreamAgg)->StreamAgg", "TableReader(Table(t)->Sel([le(test.t.b, 50)])->StreamAgg)->StreamAgg", "TableReader(Table(t)->Sel([le(test.t.b, 100000000000)])->StreamAgg)->StreamAgg", "TableReader(Table(t)->Sel([le(test.t.b, 40)]))", "TableReader(Table(t)->Sel([le(test.t.b, 50)]))", "TableReader(Table(t)->Sel([le(test.t.b, 10000000000)]))", "TableReader(Table(t)->Sel([le(test.t.b, 50)]))", "TableReader(Table(t)->Sel([le(test.t.b, 100)])->Limit)->Limit", "IndexLookUp(Index(t.b)[[-inf,1]]->TopN([test.t.a],0,10), Table(t))->TopN([test.t.a],0,10)", "IndexLookUp(Index(t.b)[[1,1]], Table(t))", "IndexLookUp(Index(t.d)[[-inf,1991-09-05 00:00:00)], Table(t))", "IndexLookUp(Index(t.ts)[[-inf,1991-09-05 00:00:00)], Table(t))", "IndexLookUp(Index(t1.idx)[[3,3]], Table(t1)->Sel([eq(test.t1.b, 100000)]))->Projection->Projection->StreamAgg->Limit" ] }, { "Name": "TestAnalyze", "Cases": [ "Analyze{Index(a),Table(a, b)}", "TableReader(Table(t)->Sel([le(test.t.a, 2)]))", "IndexReader(Index(t.b)[[-inf,2)])", "TableReader(Table(t)->Sel([eq(test.t.a, 1) le(test.t.b, 2)]))", "TableReader(Table(t1)->Sel([le(test.t1.a, 2)]))", "IndexLookUp(Index(t1.a)[[1,1]], Table(t1)->Sel([le(test.t1.b, 2)]))", "TableReader(Table(t2)->Sel([le(test.t2.a, 2)]))", "Analyze{Index(a),Index(b)}", "PartitionUnionAll{TableReader(Table(t4)->Sel([le(test.t4.a, 2)]))->TableReader(Table(t4)->Sel([le(test.t4.a, 2)]))}", "PartitionUnionAll{IndexReader(Index(t4.b)[[-inf,2)])->IndexReader(Index(t4.b)[[-inf,2)])}", "TableReader(Table(t4)->Sel([eq(test.t4.a, 1) le(test.t4.b, 2)]))" ] }, { "Name": "TestIndexEqualUnknown", "Cases": [ { "SQL": "explain select * from t where a = 7639902", "Plan": [ "IndexReader_6 6.68 root index:IndexRangeScan_5", "└─IndexRangeScan_5 6.68 cop[tikv] table:t, index:PRIMARY(a, c, b) range:[7639902,7639902], keep order:false" ] }, { "SQL": "explain select c, b from t where a = 7639902 order by b asc limit 6", "Plan": [ "Projection_7 6.00 root test.t.c, test.t.b", "└─TopN_8 6.00 root test.t.b:asc, offset:0, count:6", " └─IndexReader_16 6.00 root index:TopN_15", " └─TopN_15 6.00 cop[tikv] test.t.b:asc, offset:0, count:6", " └─IndexRangeScan_14 6.68 cop[tikv] table:t, index:PRIMARY(a, c, b) range:[7639902,7639902], keep order:false" ] } ] } ]