diff --git a/pkg/planner/core/casetest/flatplan/testdata/flat_plan_suite_out.json b/pkg/planner/core/casetest/flatplan/testdata/flat_plan_suite_out.json index 1839322a235dc..9a21833258c5f 100644 --- a/pkg/planner/core/casetest/flatplan/testdata/flat_plan_suite_out.json +++ b/pkg/planner/core/casetest/flatplan/testdata/flat_plan_suite_out.json @@ -212,8 +212,8 @@ { "Depth": 2, "Label": 0, - "IsRoot": false, - "StoreType": 0, + "IsRoot": true, + "StoreType": 2, "ReqType": 0, "IsPhysicalPlan": true, "TextTreeIndent": "│ │ ", @@ -232,15 +232,80 @@ { "Depth": 2, "Label": 0, - "IsRoot": false, - "StoreType": 0, + "IsRoot": true, + "StoreType": 2, "ReqType": 0, "IsPhysicalPlan": true, "TextTreeIndent": " │ ", "IsLastChild": true } ], - "CTEs": null + "CTEs": [ + [ + { + "Depth": 0, + "Label": 0, + "IsRoot": true, + "StoreType": 2, + "ReqType": 0, + "IsPhysicalPlan": true, + "TextTreeIndent": "", + "IsLastChild": true + }, + { + "Depth": 1, + "Label": 3, + "IsRoot": true, + "StoreType": 2, + "ReqType": 0, + "IsPhysicalPlan": true, + "TextTreeIndent": "│ ", + "IsLastChild": true + }, + { + "Depth": 2, + "Label": 0, + "IsRoot": false, + "StoreType": 0, + "ReqType": 0, + "IsPhysicalPlan": true, + "TextTreeIndent": " │ ", + "IsLastChild": true + } + ], + [ + { + "Depth": 0, + "Label": 0, + "IsRoot": true, + "StoreType": 2, + "ReqType": 0, + "IsPhysicalPlan": true, + "TextTreeIndent": "", + "IsLastChild": true + }, + { + "Depth": 1, + "Label": 3, + "IsRoot": true, + "StoreType": 2, + "ReqType": 0, + "IsPhysicalPlan": true, + "TextTreeIndent": "│ ", + "IsLastChild": true + }, + { + "Depth": 2, + "Label": 0, + "IsRoot": false, + "StoreType": 0, + "ReqType": 0, + "IsPhysicalPlan": true, + "TextTreeIndent": " │ ", + "IsLastChild": true + } + ] + ] }, { "SQL": "WITH RECURSIVE cte (n) AS( SELECT 1 UNION ALL SELECT n + 1 FROM cte WHERE n < 5)SELECT * FROM cte;", diff --git a/pkg/planner/core/casetest/hint/testdata/integration_suite_out.json b/pkg/planner/core/casetest/hint/testdata/integration_suite_out.json index 69bb41139613a..c5eda8263c235 100644 --- a/pkg/planner/core/casetest/hint/testdata/integration_suite_out.json +++ b/pkg/planner/core/casetest/hint/testdata/integration_suite_out.json @@ -796,18 +796,24 @@ { "SQL": "explain format = 'brief' select /*+ qb_name(qb_v8, v8), merge(@qb_v8) */ * from v8;", "Plan": [ - "HashAgg 16000.00 root group by:Column#41, funcs:firstrow(Column#41)->Column#41", + "HashAgg 16000.00 root group by:Column#21, funcs:firstrow(Column#21)->Column#21", "└─Union 1000000010000.00 root ", " ├─HashJoin 1000000000000.00 root CARTESIAN inner join", - " │ ├─IndexReader(Build) 10000.00 root index:IndexFullScan", - " │ │ └─IndexFullScan 10000.00 cop[tikv] table:t3, index:idx_a(a) keep order:false, stats:pseudo", - " │ └─HashJoin(Probe) 100000000.00 root CARTESIAN inner join", - " │ ├─IndexReader(Build) 10000.00 root index:IndexFullScan", - " │ │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", - " │ └─TableReader(Probe) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " │ ├─TableReader(Build) 10000.00 root data:TableFullScan", + " │ │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " │ └─CTEFullScan(Probe) 100000000.00 root CTE:cte2 data:CTE_1", " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "CTE_1 100000000.00 root Non-Recursive CTE", + "└─HashJoin(Seed Part) 100000000.00 root CARTESIAN inner join", + " ├─CTEFullScan(Build) 10000.00 root CTE:cte4 data:CTE_3", + " └─CTEFullScan(Probe) 10000.00 root CTE:cte3 data:CTE_2", + "CTE_3 10000.00 root Non-Recursive CTE", + "└─IndexReader(Seed Part) 10000.00 root index:IndexFullScan", + " └─IndexFullScan 10000.00 cop[tikv] table:t3, index:idx_a(a) keep order:false, stats:pseudo", + "CTE_2 10000.00 root Non-Recursive CTE", + "└─IndexReader(Seed Part) 10000.00 root index:IndexFullScan", + " └─IndexFullScan 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo" ], "Warn": null }, diff --git a/pkg/planner/core/casetest/planstats/BUILD.bazel b/pkg/planner/core/casetest/planstats/BUILD.bazel index 4ecf0a6a2dcfb..b0a6c3b911e99 100644 --- a/pkg/planner/core/casetest/planstats/BUILD.bazel +++ b/pkg/planner/core/casetest/planstats/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], data = glob(["testdata/**"]), flaky = True, - shard_count = 5, + shard_count = 6, deps = [ "//pkg/config", "//pkg/domain", diff --git a/pkg/planner/core/casetest/planstats/plan_stats_test.go b/pkg/planner/core/casetest/planstats/plan_stats_test.go index a599bc873dd97..aeb1fec4f220c 100644 --- a/pkg/planner/core/casetest/planstats/plan_stats_test.go +++ b/pkg/planner/core/casetest/planstats/plan_stats_test.go @@ -163,6 +163,7 @@ func TestPlanStatsLoad(t *testing.T) { require.Greater(t, countFullStats(ptr.StatsInfo().HistColl, tableInfo.Columns[2].ID), 0) }, }, +<<<<<<< HEAD { // CTE sql: "with cte(x, y) as (select d + 1, b from t where c > 1) select * from cte where x < 3", check: func(p plannercore.Plan, tableInfo *model.TableInfo) { @@ -177,6 +178,8 @@ func TestPlanStatsLoad(t *testing.T) { require.Greater(t, countFullStats(reader.StatsInfo().HistColl, tableInfo.Columns[2].ID), 0) }, }, +======= +>>>>>>> fa723c3bd54 (planner, CTE, view: Fix default inline CTE which contains orderby/limit/distinct and inside of view (#56609)) { // recursive CTE sql: "with recursive cte(x, y) as (select a, b from t where c > 1 union select x + 1, y from cte where x < 5) select * from cte", check: func(p plannercore.Plan, tableInfo *model.TableInfo) { @@ -220,6 +223,47 @@ func TestPlanStatsLoad(t *testing.T) { } } +func TestPlanStatsLoadForCTE(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("set @@session.tidb_analyze_version=2") + tk.MustExec("set @@session.tidb_partition_prune_mode = 'static'") + tk.MustExec("set @@session.tidb_stats_load_sync_wait = 60000") + tk.MustExec("set tidb_opt_projection_push_down = 0") + tk.MustExec("create table t(a int, b int, c int, d int, primary key(a), key idx(b))") + tk.MustExec("insert into t values (1,1,1,1),(2,2,2,2),(3,3,3,3)") + tk.MustExec("create table pt(a int, b int, c int) partition by range(a) (partition p0 values less than (10), partition p1 values less than (20), partition p2 values less than maxvalue)") + tk.MustExec("insert into pt values (1,1,1),(2,2,2),(13,13,13),(14,14,14),(25,25,25),(36,36,36)") + + oriLease := dom.StatsHandle().Lease() + dom.StatsHandle().SetLease(1) + defer func() { + dom.StatsHandle().SetLease(oriLease) + }() + tk.MustExec("analyze table t all columns") + tk.MustExec("analyze table pt all columns") + + var ( + input []string + output []struct { + Query string + Result []string + } + ) + testData := GetPlanStatsData() + testData.LoadTestCases(t, &input, &output) + for i, sql := range input { + testdata.OnRecord(func() { + output[i].Query = input[i] + output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(sql).Rows()) + }) + tk.MustQuery(sql).Check(testkit.Rows(output[i].Result...)) + } +} + func countFullStats(stats *statistics.HistColl, colID int64) int { for _, col := range stats.Columns { if col.Info.ID == colID { diff --git a/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_in.json b/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_in.json index 8f209105e6965..c337e47bdd266 100644 --- a/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_in.json +++ b/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_in.json @@ -70,5 +70,11 @@ "explain format = brief select * from t join tp where tp.a = 10 and t.b = tp.c", "explain format = brief select * from t join tp partition (p0) join t2 where t.a < 10 and t.b = tp.c and t2.a > 10 and t2.a = tp.c" ] + }, + { + "name": "TestPlanStatsLoadForCTE", + "cases": [ + "explain format= brief with cte(x, y) as (select d + 1, b from t where c > 1) select * from cte where x < 3" + ] } ] diff --git a/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_out.json b/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_out.json index 3542ae3815331..5265c5018ab61 100644 --- a/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_out.json +++ b/pkg/planner/core/casetest/planstats/testdata/plan_stats_suite_out.json @@ -143,5 +143,19 @@ ] } ] + }, + { + "Name": "TestPlanStatsLoadForCTE", + "Cases": [ + { + "Query": "explain format= brief with cte(x, y) as (select d + 1, b from t where c > 1) select * from cte where x < 3", + "Result": [ + "Projection 1.60 root plus(test.t.d, 1)->Column#12, test.t.b", + "└─TableReader 1.60 root data:Selection", + " └─Selection 1.60 cop[tikv] gt(test.t.c, 1), lt(plus(test.t.d, 1), 3)", + " └─TableFullScan 3.00 cop[tikv] table:t keep order:false" + ] + } + ] } ] diff --git a/pkg/planner/core/casetest/rule/testdata/outer2inner_in.json b/pkg/planner/core/casetest/rule/testdata/outer2inner_in.json new file mode 100644 index 0000000000000..7fa43e89adbfa --- /dev/null +++ b/pkg/planner/core/casetest/rule/testdata/outer2inner_in.json @@ -0,0 +1,53 @@ +[ + { + "name": "TestOuter2Inner", + "cases": [ + "select * from t1 left outer join t2 on a1=a2 where b2 < 1 -- basic case of outer to inner join conversion", + "select * from t1 left outer join t2 on a1=a2 where b2 is not null -- basic case of not null", + "select * from t1 left outer join t2 on a1=a2 where not(b2 is null) -- another form of basic case of not null", + "select * from t1 left outer join t2 on a1=a2 where c2 = 5 OR b2 < 55 -- case with A OR B (Both A and B are null filtering)", + "select * from t1 left outer join t2 on a1=a2 where c2 = 5 AND b2 is null -- case with A AND B (A is null filtering and B is not)", + "select * from t1 left outer join t2 on a1=a2 where b2 is NULL AND c2 = 5 -- case with A AND B (A is null filtering and B is not)", + "select * from t1 left outer join t2 on a1=a2 where not (b2 is NULL OR c2 = 5) -- NOT case ", + "select * from t1 left outer join t2 on a1=a2 where not (b2 is NULL AND c2 = 5) -- NOT case ", + "select * from t2 left outer join t1 on a1=a2 where b1+b1 > 2; -- expression evaluates to UNKNOWN/FALSE", + "select * from t2 left outer join t1 on a1=a2 where coalesce(b1,2) > 2; -- false condition for b1=NULL", + "select * from t2 left outer join t1 on a1=a2 where true and b1 = 5; -- AND with one branch is null filtering", + "select * from t2 left outer join t1 on a1=a2 where false OR b1 = 5; -- OR with both branches are null filtering", + "select * from t3 as t1 left join t3 as t2 on t1.c3 = t2.c3 where t2.b3 != NULL; -- self join", + "select * from t1 ta left outer join (t1 tb left outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1; -- nested join. On clause is null filtering on tc.", + "select * from t1 ta left outer join (t1 tb left outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1 where tb.a1 > 5; -- nested join. On clause and WHERE clause are filters", + "select * from (t2 left join t1 on a1=a2) join t3 on b1=b3 -- on clause applied nested join", + "select * from ((t1 left join t2 on a1=a2) left join t3 on b2=b3) join t4 on b3=b4 -- nested and propagation of null filtering", + "select * from t1 right join t2 on a1=a2 where exists (select 1 from t3 where b1=b3) -- semi join is null filtering on the outer join", + "select sum(l_extendedprice) / 7.0 as avg_yearly from lineitem, part where p_partkey = l_partkey and p_brand = 'Brand#44' and p_container = 'WRAP PKG' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey) -- Q17 in TPCH. null filter on derived outer join", + "WITH cte AS ( SELECT alias1.col_date AS field1 FROM d AS alias1 LEFT JOIN dd AS alias2 ON alias1.col_blob_key=alias2.col_blob_key WHERE alias1.col_varchar_key IS NULL OR alias1.col_blob_key >= 'a') SELECT * FROM d AS outr1 LEFT OUTER JOIN dd AS outr2 ON (outr1.col_date=outr2.col_date) JOIN cte AS outrcte ON outr2.col_blob_key=outrcte.field1 -- nested complex case", + "with cte as (select count(a2) as cnt,b2-5 as b3 from t1 left outer join t2 on a1=a2 group by b3) select * from cte where b3 > 1 -- aggregate case.", + "select * from dd as outr1 WHERE outr1.col_blob IN (SELECT DISTINCT innr1.col_blob_key AS y FROM d AS innrcte left outer join dd AS innr1 ON innr1.pk = innrcte.col_date WHERE outr1.col_int_key > 6)", + "select * from t0 left outer join t11 on a0=a1 where t0.b0 in (t11.b1, t11.c1) -- each = in the in list is null filtering", + "select * from t1 left outer join t2 on a1=a2 where b2 is null -- negative case with single predicate which is not null filtering", + "select * from t1 left outer join t2 on a1=a2 where c2 = 5 OR b2 is null -- negative case with A OR B (A is null filtering and B is not)", + "select * from t1 left outer join t2 on a1=a2 where not(b2 is not null) -- nested 'not' negative case", + "select * from t1 left outer join t2 on a1=a2 where not(not(b2 is null)) -- nested 'not' negative case", + "select * from t1 left outer join t2 on a1=a2 where b1 is not null -- negative case with condition on outer table.", + "select * from t2 left outer join t1 on a1=a2 where coalesce(b1,2) = 2; -- true condition for b1=NULL", + "select * from t2 left outer join t1 on a1=a2 where true OR b1 = 5; -- negative case with OR and one branch is TRUE", + "select * from t3 as t1 left join t3 as t2 on t1.c3 = t2.c3 where t1.b3 != NULL -- negative case with self join", + "select * from (t1 left outer join t2 on a1=a2) left outer join t3 on a2=a3 and b2 = 5 -- negative case. inner side is not a join", + "select * from t1 ta right outer join (t1 tb right outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1; -- negative case. inner side is not a join", + "select * from t1 ta right outer join (t1 tb right outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1 where tc.a1 > 5; -- negative case. inner side is not a join and WHERE clause on outer table", + "select * from (t2 left join t1 on a1=a2) join t3 on b2=b3 -- negative case, on clause on outer table in nested join", + "select t1.c1 in (select count(s.b1) from t1 s where s.a1 = t1.a1) from t1 -- subquery test that generates outer join and not converted", + "SELECT * FROM ti LEFT JOIN (SELECT i FROM ti WHERE FALSE) AS d1 ON ti.i = d1.i WHERE NOT EXISTS (SELECT 1 FROM ti AS inner_t1 WHERE i = d1.i) -- anti semi join", + "select count(*) from t1 where t1.a1+100 > ( select count(*) from t2 where t1.a1=t2.a2 and t1.b1=t2.b2) group by t1.b1 -- filter not filtering over derived outer join", + "with cte as (select count(a2) as cnt,ifnull(b2,5) as b2 from t1 left outer join t2 on a1=a2 group by b2) select * from cte where b2 > 1 -- non null filter on group by", + "with cte as (select count(a2) as cnt,ifnull(b2,5) as b2 from t1 left outer join t2 on a1=a2 group by b2) select * from cte where cnt > 1 -- filter on aggregates not applicable", + "select * from t0 left outer join t11 on a0=a1 where t0.b0 in (t0.b0, t11.b1)", + "select * from t0 left outer join t11 on a0=a1 where '5' not in (t0.b0, t11.b1)", + "select * from t0 left outer join t11 on a0=a1 where '1' in (t0.b0, t11.b1)", + "select * from t0 left outer join t11 on a0=a1 where t0.b0 in ('5', t11.b1) -- some = in the in list is not null filtering", + "select * from t0 left outer join t11 on a0=a1 where '5' in (t0.b0, t11.b1) -- some = in the in list is not null filtering", + "select * from t1 left outer join t2 on a1=a2 where not (b2 is NOT NULL AND c2 = 5) -- NOT case " + ] + } +] diff --git a/pkg/planner/core/casetest/rule/testdata/outer2inner_out.json b/pkg/planner/core/casetest/rule/testdata/outer2inner_out.json new file mode 100644 index 0000000000000..f55028ad56bb0 --- /dev/null +++ b/pkg/planner/core/casetest/rule/testdata/outer2inner_out.json @@ -0,0 +1,654 @@ +[ + { + "Name": "TestOuter2Inner", + "Cases": [ + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where b2 < 1 -- basic case of outer to inner join conversion", + "Plan": [ + "Projection 4150.01 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 4150.01 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 3320.01 root data:Selection", + " │ └─Selection 3320.01 cop[tikv] lt(test.t2.b2, 1), not(isnull(test.t2.a2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where b2 is not null -- basic case of not null", + "Plan": [ + "Projection 12475.01 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 12475.01 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a2)), not(isnull(test.t2.b2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where not(b2 is null) -- another form of basic case of not null", + "Plan": [ + "Projection 12475.01 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 12475.01 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a2)), not(isnull(test.t2.b2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where c2 = 5 OR b2 < 55 -- case with A OR B (Both A and B are null filtering)", + "Plan": [ + "Projection 4158.35 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 4158.35 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 3326.68 root data:Selection", + " │ └─Selection 3326.68 cop[tikv] not(isnull(test.t2.a2)), or(eq(test.t2.c2, 5), lt(test.t2.b2, 55))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where c2 = 5 AND b2 is null -- case with A AND B (A is null filtering and B is not)", + "Plan": [ + "Projection 0.01 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 0.01 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 0.01 root data:Selection", + " │ └─Selection 0.01 cop[tikv] eq(test.t2.c2, 5), isnull(test.t2.b2), not(isnull(test.t2.a2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where b2 is NULL AND c2 = 5 -- case with A AND B (A is null filtering and B is not)", + "Plan": [ + "Projection 0.01 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 0.01 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 0.01 root data:Selection", + " │ └─Selection 0.01 cop[tikv] eq(test.t2.c2, 5), isnull(test.t2.b2), not(isnull(test.t2.a2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where not (b2 is NULL OR c2 = 5) -- NOT case ", + "Plan": [ + "Projection 9990.00 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 9990.00 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 7992.00 root data:Selection", + " │ └─Selection 7992.00 cop[tikv] and(not(isnull(test.t2.b2)), ne(test.t2.c2, 5)), not(isnull(test.t2.a2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where not (b2 is NULL AND c2 = 5) -- NOT case ", + "Plan": [ + "Projection 12483.33 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2", + "└─HashJoin 12483.33 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9986.66 root data:Selection", + " │ └─Selection 9986.66 cop[tikv] not(isnull(test.t2.a2)), or(not(isnull(test.t2.b2)), ne(test.t2.c2, 5))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t2 left outer join t1 on a1=a2 where b1+b1 > 2; -- expression evaluates to UNKNOWN/FALSE", + "Plan": [ + "Projection 9990.00 root test.t2.a2, test.t2.b2, test.t2.c2, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 9990.00 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 7992.00 root data:Selection", + " │ └─Selection 7992.00 cop[tikv] gt(plus(test.t1.b1, test.t1.b1), 2), not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t2 left outer join t1 on a1=a2 where coalesce(b1,2) > 2; -- false condition for b1=NULL", + "Plan": [ + "Projection 9990.00 root test.t2.a2, test.t2.b2, test.t2.c2, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 9990.00 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 7992.00 root data:Selection", + " │ └─Selection 7992.00 cop[tikv] gt(coalesce(test.t1.b1, 2), 2), not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t2 left outer join t1 on a1=a2 where true and b1 = 5; -- AND with one branch is null filtering", + "Plan": [ + "Projection 12.49 root test.t2.a2, test.t2.b2, test.t2.c2, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 12.49 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9.99 root data:Selection", + " │ └─Selection 9.99 cop[tikv] eq(test.t1.b1, 5), not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t2 left outer join t1 on a1=a2 where false OR b1 = 5; -- OR with both branches are null filtering", + "Plan": [ + "Projection 12.49 root test.t2.a2, test.t2.b2, test.t2.c2, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 12.49 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9.99 root data:Selection", + " │ └─Selection 9.99 cop[tikv] not(isnull(test.t1.a1)), or(0, eq(test.t1.b1, 5))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t3 as t1 left join t3 as t2 on t1.c3 = t2.c3 where t2.b3 != NULL; -- self join", + "Plan": [ + "Projection 0.00 root test.t3.a3, test.t3.b3, test.t3.c3, test.t3.a3, test.t3.b3, test.t3.c3", + "└─HashJoin 0.00 root inner join, equal:[eq(test.t3.c3, test.t3.c3)]", + " ├─TableReader(Build) 0.00 root data:Selection", + " │ └─Selection 0.00 cop[tikv] ne(test.t3.b3, NULL), not(isnull(test.t3.c3))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t3.c3))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 ta left outer join (t1 tb left outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1; -- nested join. On clause is null filtering on tc.", + "Plan": [ + "HashJoin 15593.77 root left outer join, equal:[eq(test.t1.a1, test.t1.a1)]", + "├─TableReader(Build) 10000.00 root data:TableFullScan", + "│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", + "└─Projection(Probe) 12475.01 root test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1", + " └─HashJoin 12475.01 root inner join, equal:[eq(test.t1.b1, test.t1.b1)]", + " ├─TableReader(Build) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a1)), not(isnull(test.t1.b1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.b1))", + " └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 ta left outer join (t1 tb left outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1 where tb.a1 > 5; -- nested join. On clause and WHERE clause are filters", + "Plan": [ + "Projection 5203.12 root test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 5203.12 root inner join, equal:[eq(test.t1.a1, test.t1.a1)]", + " ├─HashJoin(Build) 4162.50 root inner join, equal:[eq(test.t1.b1, test.t1.b1)]", + " │ ├─TableReader(Build) 3330.00 root data:Selection", + " │ │ └─Selection 3330.00 cop[tikv] gt(test.t1.a1, 5), not(isnull(test.t1.b1))", + " │ │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo", + " │ └─TableReader(Probe) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a1)), not(isnull(test.t1.b1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from (t2 left join t1 on a1=a2) join t3 on b1=b3 -- on clause applied nested join", + "Plan": [ + "Projection 15593.77 root test.t2.a2, test.t2.b2, test.t2.c2, test.t1.a1, test.t1.b1, test.t1.c1, test.t3.a3, test.t3.b3, test.t3.c3", + "└─HashJoin 15593.77 root inner join, equal:[eq(test.t1.b1, test.t3.b3)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t3.b3))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", + " └─HashJoin(Probe) 12475.01 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a1)), not(isnull(test.t1.b1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from ((t1 left join t2 on a1=a2) left join t3 on b2=b3) join t4 on b3=b4 -- nested and propagation of null filtering", + "Plan": [ + "Projection 19492.21 root test.t1.a1, test.t1.b1, test.t1.c1, test.t2.a2, test.t2.b2, test.t2.c2, test.t3.a3, test.t3.b3, test.t3.c3, test.t4.a4, test.t4.b4, test.t4.c4", + "└─HashJoin 19492.21 root inner join, equal:[eq(test.t3.b3, test.t4.b4)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t4.b4))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t4 keep order:false, stats:pseudo", + " └─HashJoin(Probe) 15593.77 root inner join, equal:[eq(test.t2.b2, test.t3.b3)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t3.b3))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", + " └─HashJoin(Probe) 12475.01 root inner join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a2)), not(isnull(test.t2.b2))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 right join t2 on a1=a2 where exists (select 1 from t3 where b1=b3) -- semi join is null filtering on the outer join", + "Plan": [ + "HashJoin 9980.01 root semi join, equal:[eq(test.t1.b1, test.t3.b3)]", + "├─TableReader(Build) 9990.00 root data:Selection", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t3.b3))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", + "└─HashJoin(Probe) 12475.01 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9980.01 root data:Selection", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a1)), not(isnull(test.t1.b1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select sum(l_extendedprice) / 7.0 as avg_yearly from lineitem, part where p_partkey = l_partkey and p_brand = 'Brand#44' and p_container = 'WRAP PKG' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey) -- Q17 in TPCH. null filter on derived outer join", + "Plan": [ + "Projection 1.00 root div(Column#15, 7.0)->Column#16", + "└─StreamAgg 1.00 root funcs:sum(test.lineitem.l_extendedprice)->Column#15", + " └─HashJoin 0.01 root inner join, equal:[eq(test.part.p_partkey, test.lineitem.l_partkey)], other cond:lt(test.lineitem.l_quantity, mul(0.2, Column#13))", + " ├─HashJoin(Build) 0.01 root inner join, equal:[eq(test.part.p_partkey, test.lineitem.l_partkey)]", + " │ ├─TableReader(Build) 0.01 root data:Selection", + " │ │ └─Selection 0.01 cop[tikv] eq(test.part.p_brand, \"Brand#44\"), eq(test.part.p_container, \"WRAP PKG\"), not(isnull(test.part.p_partkey))", + " │ │ └─TableFullScan 10000.00 cop[tikv] table:part keep order:false, stats:pseudo", + " │ └─TableReader(Probe) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.lineitem.l_partkey))", + " │ └─TableFullScan 10000.00 cop[tikv] table:lineitem keep order:false, stats:pseudo", + " └─HashAgg(Probe) 7992.00 root group by:test.lineitem.l_partkey, funcs:avg(Column#19, Column#20)->Column#13, funcs:firstrow(test.lineitem.l_partkey)->test.lineitem.l_partkey", + " └─TableReader 7992.00 root data:HashAgg", + " └─HashAgg 7992.00 cop[tikv] group by:test.lineitem.l_partkey, funcs:count(test.lineitem.l_quantity)->Column#19, funcs:sum(test.lineitem.l_quantity)->Column#20", + " └─Selection 9990.00 cop[tikv] not(isnull(test.lineitem.l_partkey))", + " └─TableFullScan 10000.00 cop[tikv] table:lineitem keep order:false, stats:pseudo" + ] + }, + { + "SQL": "WITH cte AS ( SELECT alias1.col_date AS field1 FROM d AS alias1 LEFT JOIN dd AS alias2 ON alias1.col_blob_key=alias2.col_blob_key WHERE alias1.col_varchar_key IS NULL OR alias1.col_blob_key >= 'a') SELECT * FROM d AS outr1 LEFT OUTER JOIN dd AS outr2 ON (outr1.col_date=outr2.col_date) JOIN cte AS outrcte ON outr2.col_blob_key=outrcte.field1 -- nested complex case", + "Plan": [ + "Projection 6523.44 root test.d.pk, test.d.col_blob, test.d.col_blob_key, test.d.col_varchar_key, test.d.col_date, test.d.col_int_key, test.dd.pk, test.dd.col_blob, test.dd.col_blob_key, test.dd.col_date, test.dd.col_int_key, test.d.col_date", + "└─HashJoin 6523.44 root inner join, equal:[eq(test.d.col_date, Column#41)]", + " ├─HashJoin(Build) 4175.00 root left outer join, equal:[eq(test.d.col_blob_key, test.dd.col_blob_key)]", + " │ ├─TableReader(Build) 3340.00 root data:Selection", + " │ │ └─Selection 3340.00 cop[tikv] or(isnull(test.d.col_varchar_key), ge(test.d.col_blob_key, \"a\"))", + " │ │ └─TableFullScan 10000.00 cop[tikv] table:alias1 keep order:false, stats:pseudo", + " │ └─TableReader(Probe) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.dd.col_blob_key))", + " │ └─TableFullScan 10000.00 cop[tikv] table:alias2 keep order:false, stats:pseudo", + " └─Projection(Probe) 12487.50 root test.d.pk, test.d.col_blob, test.d.col_blob_key, test.d.col_varchar_key, test.d.col_date, test.d.col_int_key, test.dd.pk, test.dd.col_blob, test.dd.col_blob_key, test.dd.col_date, test.dd.col_int_key, cast(test.dd.col_blob_key, datetime(6) BINARY)->Column#41", + " └─HashJoin 12487.50 root inner join, equal:[eq(test.d.col_date, test.dd.col_date)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.dd.col_date))", + " │ └─TableFullScan 10000.00 cop[tikv] table:outr2 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.d.col_date))", + " └─TableFullScan 10000.00 cop[tikv] table:outr1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "with cte as (select count(a2) as cnt,b2-5 as b3 from t1 left outer join t2 on a1=a2 group by b3) select * from cte where b3 > 1 -- aggregate case.", + "Plan": [ + "Projection 6393.60 root Column#21, minus(test.t2.b2, 5)->Column#22", + "└─Selection 6393.60 root gt(minus(test.t2.b2, 5), 1)", + " └─HashAgg 7992.00 root group by:Column#26, funcs:count(Column#24)->Column#21, funcs:firstrow(Column#25)->test.t2.b2", + " └─Projection 12487.50 root test.t2.a2->Column#24, test.t2.b2->Column#25, minus(test.t2.b2, 5)->Column#26", + " └─HashJoin 12487.50 root inner join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from dd as outr1 WHERE outr1.col_blob IN (SELECT DISTINCT innr1.col_blob_key AS y FROM d AS innrcte left outer join dd AS innr1 ON innr1.pk = innrcte.col_date WHERE outr1.col_int_key > 6)", + "Plan": [ + "Apply 9990.00 root semi join, equal:[eq(test.dd.col_blob, test.dd.col_blob_key)]", + "├─TableReader(Build) 9990.00 root data:Selection", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.dd.col_blob))", + "│ └─TableFullScan 10000.00 cop[tikv] table:outr1 keep order:false, stats:pseudo", + "└─HashAgg(Probe) 63872064.00 root group by:test.dd.col_blob_key, funcs:firstrow(test.dd.col_blob_key)->test.dd.col_blob_key", + " └─HashJoin 99800100.00 root inner join, equal:[eq(Column#21, Column#20)]", + " ├─Projection(Build) 79920000.00 root cast(test.d.col_date, double BINARY)->Column#20", + " │ └─TableReader 79920000.00 root data:Selection", + " │ └─Selection 79920000.00 cop[tikv] gt(test.dd.col_int_key, 6)", + " │ └─TableFullScan 99900000.00 cop[tikv] table:innrcte keep order:false, stats:pseudo", + " └─Projection(Probe) 79840080.00 root test.dd.col_blob_key, cast(test.dd.pk, double BINARY)->Column#21", + " └─TableReader 79840080.00 root data:Selection", + " └─Selection 79840080.00 cop[tikv] gt(test.dd.col_int_key, 6), not(isnull(test.dd.col_blob_key))", + " └─TableFullScan 99900000.00 cop[tikv] table:innr1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t0 left outer join t11 on a0=a1 where t0.b0 in (t11.b1, t11.c1) -- each = in the in list is null filtering", + "Plan": [ + "HashJoin 12487.50 root inner join, equal:[eq(test.t0.a0, test.t11.a1)], other cond:in(test.t0.b0, test.t11.b1, test.t11.c1)", + "├─TableReader(Build) 9990.00 root data:Selection", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t11.a1))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t11 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t0.a0))", + " └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where b2 is null -- negative case with single predicate which is not null filtering", + "Plan": [ + "Selection 9990.00 root isnull(test.t2.b2)", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " │ └─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" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where c2 = 5 OR b2 is null -- negative case with A OR B (A is null filtering and B is not)", + "Plan": [ + "Selection 9990.00 root or(eq(test.t2.c2, 5), isnull(test.t2.b2))", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " │ └─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" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where not(b2 is not null) -- nested 'not' negative case", + "Plan": [ + "Selection 9990.00 root not(not(isnull(test.t2.b2)))", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " │ └─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" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where not(not(b2 is null)) -- nested 'not' negative case", + "Plan": [ + "Selection 9990.00 root not(not(isnull(test.t2.b2)))", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " │ └─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" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where b1 is not null -- negative case with condition on outer table.", + "Plan": [ + "HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + "├─TableReader(Build) 9990.00 root data:Selection", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.b1))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t2 left outer join t1 on a1=a2 where coalesce(b1,2) = 2; -- true condition for b1=NULL", + "Plan": [ + "Selection 9990.00 root eq(coalesce(test.t1.b1, 2), 2)", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t2 left outer join t1 on a1=a2 where true OR b1 = 5; -- negative case with OR and one branch is TRUE", + "Plan": [ + "Selection 9990.00 root or(1, eq(test.t1.b1, 5))", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t3 as t1 left join t3 as t2 on t1.c3 = t2.c3 where t1.b3 != NULL -- negative case with self join", + "Plan": [ + "HashJoin 0.00 root left outer join, equal:[eq(test.t3.c3, test.t3.c3)]", + "├─TableReader(Build) 0.00 root data:Selection", + "│ └─Selection 0.00 cop[tikv] ne(test.t3.b3, NULL)", + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t3.c3))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from (t1 left outer join t2 on a1=a2) left outer join t3 on a2=a3 and b2 = 5 -- negative case. inner side is not a join", + "Plan": [ + "HashJoin 15609.38 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + "├─TableReader(Build) 10000.00 root data:TableFullScan", + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "└─HashJoin(Probe) 12487.50 root left outer join, equal:[eq(test.t2.a2, test.t3.a3)], left cond:[eq(test.t2.b2, 5)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t3.a3))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 ta right outer join (t1 tb right outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1; -- negative case. inner side is not a join", + "Plan": [ + "Projection 15593.77 root test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 15593.77 root right outer join, equal:[eq(test.t1.b1, test.t1.b1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.b1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo", + " └─HashJoin(Probe) 12487.50 root right outer join, equal:[eq(test.t1.a1, test.t1.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 ta right outer join (t1 tb right outer join t1 tc on tb.b1 = tc.b1) on ta.a1=tc.a1 where tc.a1 > 5; -- negative case. inner side is not a join and WHERE clause on outer table", + "Plan": [ + "Projection 5208.33 root test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1, test.t1.a1, test.t1.b1, test.t1.c1", + "└─HashJoin 5208.33 root right outer join, equal:[eq(test.t1.b1, test.t1.b1)]", + " ├─HashJoin(Build) 4166.67 root right outer join, equal:[eq(test.t1.a1, test.t1.a1)]", + " │ ├─TableReader(Build) 3333.33 root data:Selection", + " │ │ └─Selection 3333.33 cop[tikv] gt(test.t1.a1, 5)", + " │ │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo", + " │ └─TableReader(Probe) 3333.33 root data:Selection", + " │ └─Selection 3333.33 cop[tikv] gt(test.t1.a1, 5), not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t1.b1))", + " └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from (t2 left join t1 on a1=a2) join t3 on b2=b3 -- negative case, on clause on outer table in nested join", + "Plan": [ + "HashJoin 15609.38 root inner join, equal:[eq(test.t2.b2, test.t3.b3)]", + "├─TableReader(Build) 9990.00 root data:Selection", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t3.b3))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", + "└─HashJoin(Probe) 12487.50 root left outer join, equal:[eq(test.t2.a2, test.t1.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.b2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select t1.c1 in (select count(s.b1) from t1 s where s.a1 = t1.a1) from t1 -- subquery test that generates outer join and not converted", + "Plan": [ + "Projection 10000.00 root Column#14", + "└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, Column#13)", + " ├─TableReader(Build) 10000.00 root data:TableFullScan", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─StreamAgg(Probe) 10000.00 root funcs:count(Column#16)->Column#13", + " └─TableReader 10000.00 root data:StreamAgg", + " └─StreamAgg 10000.00 cop[tikv] funcs:count(test.t1.b1)->Column#16", + " └─Selection 100000.00 cop[tikv] eq(test.t1.a1, test.t1.a1)", + " └─TableFullScan 100000000.00 cop[tikv] table:s keep order:false, stats:pseudo" + ] + }, + { + "SQL": "SELECT * FROM ti LEFT JOIN (SELECT i FROM ti WHERE FALSE) AS d1 ON ti.i = d1.i WHERE NOT EXISTS (SELECT 1 FROM ti AS inner_t1 WHERE i = d1.i) -- anti semi join", + "Plan": [ + "HashJoin 8000.00 root anti semi join, equal:[eq(test.ti.i, test.ti.i)]", + "├─TableReader(Build) 10000.00 root data:TableFullScan", + "│ └─TableFullScan 10000.00 cop[tikv] table:inner_t1 keep order:false, stats:pseudo", + "└─HashJoin(Probe) 10000.00 root left outer join, equal:[eq(test.ti.i, test.ti.i)]", + " ├─Selection(Build) 0.00 root not(isnull(test.ti.i))", + " │ └─TableDual 0.00 root rows:0", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:ti keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select count(*) from t1 where t1.a1+100 > ( select count(*) from t2 where t1.a1=t2.a2 and t1.b1=t2.b2) group by t1.b1 -- filter not filtering over derived outer join", + "Plan": [ + "HashAgg 6400.00 root group by:test.t1.b1, funcs:count(1)->Column#10", + "└─Selection 8000.00 root gt(plus(test.t1.a1, 100), ifnull(Column#9, 0))", + " └─HashJoin 10000.00 root left outer join, equal:[eq(test.t1.a1, test.t2.a2) eq(test.t1.b1, test.t2.b2)]", + " ├─HashAgg(Build) 7984.01 root group by:test.t2.a2, test.t2.b2, funcs:count(Column#11)->Column#9, funcs:firstrow(test.t2.a2)->test.t2.a2, funcs:firstrow(test.t2.b2)->test.t2.b2", + " │ └─TableReader 7984.01 root data:HashAgg", + " │ └─HashAgg 7984.01 cop[tikv] group by:test.t2.a2, test.t2.b2, funcs:count(1)->Column#11", + " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a2)), not(isnull(test.t2.b2))", + " │ └─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" + ] + }, + { + "SQL": "with cte as (select count(a2) as cnt,ifnull(b2,5) as b2 from t1 left outer join t2 on a1=a2 group by b2) select * from cte where b2 > 1 -- non null filter on group by", + "Plan": [ + "Projection 6393.60 root Column#21, ifnull(test.t2.b2, 5)->Column#22", + "└─HashAgg 6393.60 root group by:test.t2.b2, funcs:count(test.t2.a2)->Column#21, funcs:firstrow(test.t2.b2)->test.t2.b2", + " └─Selection 9990.00 root gt(ifnull(test.t2.b2, 5), 1)", + " └─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 10000.00 root data:TableFullScan", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "with cte as (select count(a2) as cnt,ifnull(b2,5) as b2 from t1 left outer join t2 on a1=a2 group by b2) select * from cte where cnt > 1 -- filter on aggregates not applicable", + "Plan": [ + "Projection 6393.60 root Column#21, ifnull(test.t2.b2, 5)->Column#22", + "└─Selection 6393.60 root gt(Column#21, 1)", + " └─HashAgg 7992.00 root group by:test.t2.b2, funcs:count(test.t2.a2)->Column#21, funcs:firstrow(test.t2.b2)->test.t2.b2", + " └─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 10000.00 root data:TableFullScan", + " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t0 left outer join t11 on a0=a1 where t0.b0 in (t0.b0, t11.b1)", + "Plan": [ + "Selection 9990.00 root in(test.t0.b0, test.t0.b0, test.t11.b1)", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t0.a0, test.t11.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t11.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t11 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t0 left outer join t11 on a0=a1 where '5' not in (t0.b0, t11.b1)", + "Plan": [ + "Selection 9990.00 root not(in(\"5\", test.t0.b0, test.t11.b1))", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t0.a0, test.t11.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t11.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t11 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t0 left outer join t11 on a0=a1 where '1' in (t0.b0, t11.b1)", + "Plan": [ + "Selection 9990.00 root in(\"1\", test.t0.b0, test.t11.b1)", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t0.a0, test.t11.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t11.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t11 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t0 left outer join t11 on a0=a1 where t0.b0 in ('5', t11.b1) -- some = in the in list is not null filtering", + "Plan": [ + "Selection 9990.00 root in(test.t0.b0, \"5\", test.t11.b1)", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t0.a0, test.t11.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t11.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t11 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t0 left outer join t11 on a0=a1 where '5' in (t0.b0, t11.b1) -- some = in the in list is not null filtering", + "Plan": [ + "Selection 9990.00 root in(\"5\", test.t0.b0, test.t11.b1)", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t0.a0, test.t11.a1)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t11.a1))", + " │ └─TableFullScan 10000.00 cop[tikv] table:t11 keep order:false, stats:pseudo", + " └─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo" + ] + }, + { + "SQL": "select * from t1 left outer join t2 on a1=a2 where not (b2 is NOT NULL AND c2 = 5) -- NOT case ", + "Plan": [ + "Selection 9990.00 root not(and(not(isnull(test.t2.b2)), eq(test.t2.c2, 5)))", + "└─HashJoin 12487.50 root left outer join, equal:[eq(test.t1.a1, test.t2.a2)]", + " ├─TableReader(Build) 9990.00 root data:Selection", + " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a2))", + " │ └─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" + ] + } + ] + } +] diff --git a/pkg/planner/core/logical_plan_builder.go b/pkg/planner/core/logical_plan_builder.go index a226da89b7d86..e3420e2a50359 100644 --- a/pkg/planner/core/logical_plan_builder.go +++ b/pkg/planner/core/logical_plan_builder.go @@ -347,7 +347,7 @@ func (b *PlanBuilder) buildAggregation(ctx context.Context, p LogicalPlan, aggFu } // flag it if cte contain aggregation if b.buildingCTE { - b.outerCTEs[len(b.outerCTEs)-1].containAggOrWindow = true + b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator = true } var rollupExpand *LogicalExpand if expand, ok := p.(*LogicalExpand); ok { @@ -1959,10 +1959,21 @@ func (b *PlanBuilder) buildProjection(ctx context.Context, p LogicalPlan, fields return proj, proj.Exprs, oldLen, nil } +<<<<<<< HEAD func (b *PlanBuilder) buildDistinct(child LogicalPlan, length int) (*LogicalAggregation, error) { b.optFlag = b.optFlag | flagBuildKeyInfo b.optFlag = b.optFlag | flagPushDownAgg plan4Agg := LogicalAggregation{ +======= +func (b *PlanBuilder) buildDistinct(child base.LogicalPlan, length int) (*logicalop.LogicalAggregation, error) { + b.optFlag = b.optFlag | rule.FlagBuildKeyInfo + b.optFlag = b.optFlag | rule.FlagPushDownAgg + // flag it if cte contain distinct + if b.buildingCTE { + b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator = true + } + plan4Agg := logicalop.LogicalAggregation{ +>>>>>>> fa723c3bd54 (planner, CTE, view: Fix default inline CTE which contains orderby/limit/distinct and inside of view (#56609)) AggFuncs: make([]*aggregation.AggFuncDesc, 0, child.Schema().Len()), GroupByItems: expression.Column2Exprs(child.Schema().Clone().Columns[:length]), }.Init(b.ctx, child.SelectBlockOffset()) @@ -2552,8 +2563,17 @@ func extractLimitCountOffset(ctx sessionctx.Context, limit *ast.Limit) (count ui return count, offset, nil } +<<<<<<< HEAD func (b *PlanBuilder) buildLimit(src LogicalPlan, limit *ast.Limit) (LogicalPlan, error) { b.optFlag = b.optFlag | flagPushDownTopN +======= +func (b *PlanBuilder) buildLimit(src base.LogicalPlan, limit *ast.Limit) (base.LogicalPlan, error) { + b.optFlag = b.optFlag | rule.FlagPushDownTopN + // flag it if cte contain limit + if b.buildingCTE { + b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator = true + } +>>>>>>> fa723c3bd54 (planner, CTE, view: Fix default inline CTE which contains orderby/limit/distinct and inside of view (#56609)) var ( offset, count uint64 err error @@ -4649,6 +4669,10 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L } if sel.OrderBy != nil { + // flag it if cte contain order by + if b.buildingCTE { + b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator = true + } // We need to keep the ORDER BY clause for the following cases: // 1. The select is top level query, order should be honored // 2. The query has LIMIT clause @@ -4962,9 +4986,9 @@ func (b *PlanBuilder) tryBuildCTE(ctx context.Context, tn *ast.TableName, asName prevSchema := cte.seedLP.Schema().Clone() lp.SetSchema(getResultCTESchema(cte.seedLP.Schema(), b.ctx.GetSessionVars())) - // If current CTE query contain another CTE which 'containAggOrWindow' is true, current CTE 'containAggOrWindow' will be true + // If current CTE query contain another CTE which 'containRecursiveForbiddenOperator' is true, current CTE 'containRecursiveForbiddenOperator' will be true if b.buildingCTE { - b.outerCTEs[len(b.outerCTEs)-1].containAggOrWindow = cte.containAggOrWindow || b.outerCTEs[len(b.outerCTEs)-1].containAggOrWindow + b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator = cte.containRecursiveForbiddenOperator || b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator } // Compute cte inline b.computeCTEInlineFlag(cte) @@ -5022,13 +5046,22 @@ func (b *PlanBuilder) computeCTEInlineFlag(cte *cteInfo) { b.ctx.GetSessionVars().StmtCtx.AppendWarning( ErrInternal.GenWithStack("Recursive CTE %s can not be inlined by merge() or tidb_opt_force_inline_cte.", cte.def.Name)) } - } else if cte.containAggOrWindow && b.buildingRecursivePartForCTE { + cte.isInline = false + } else if cte.containRecursiveForbiddenOperator && b.buildingRecursivePartForCTE { if cte.forceInlineByHintOrVar { b.ctx.GetSessionVars().StmtCtx.AppendWarning(ErrCTERecursiveForbidsAggregation.FastGenByArgs(cte.def.Name)) } - } else if cte.consumerCount > 1 { + cte.isInline = false + } else if cte.consumerCount != 1 { + // If hint or session variable is set, it can be inlined by user. if cte.forceInlineByHintOrVar { cte.isInline = true + } else { + // Consumer count > 1 or = 0, CTE can not be inlined by default. + // Case the consumer count = 0 (issue #56582) + // It means that CTE maybe inside of view and the UpdateCTEConsumerCount(preprocess phase) is skipped + // So all of CTE.consumerCount is not updated, and we can not use it to determine whether CTE can be inlined. + cte.isInline = false } } else { cte.isInline = true @@ -7072,7 +7105,7 @@ func sortWindowSpecs(groupedFuncs map[*ast.WindowSpec][]*ast.WindowFuncExpr, ord func (b *PlanBuilder) buildWindowFunctions(ctx context.Context, p LogicalPlan, groupedFuncs map[*ast.WindowSpec][]*ast.WindowFuncExpr, orderedSpec []*ast.WindowSpec, aggMap map[*ast.AggregateFuncExpr]int) (LogicalPlan, map[*ast.WindowFuncExpr]int, error) { if b.buildingCTE { - b.outerCTEs[len(b.outerCTEs)-1].containAggOrWindow = true + b.outerCTEs[len(b.outerCTEs)-1].containRecursiveForbiddenOperator = true } args := make([]ast.ExprNode, 0, 4) windowMap := make(map[*ast.WindowFuncExpr]int) diff --git a/pkg/planner/core/planbuilder.go b/pkg/planner/core/planbuilder.go index a25662f3b404c..7cfe1ada57122 100644 --- a/pkg/planner/core/planbuilder.go +++ b/pkg/planner/core/planbuilder.go @@ -494,8 +494,8 @@ type cteInfo struct { isInline bool // forceInlineByHintOrVar will be true when CTE is hint by merge() or session variable "tidb_opt_force_inline_cte=true" forceInlineByHintOrVar bool - // If CTE contain aggregation or window function in query (Indirect references to other cte containing agg or window in the query are also counted.) - containAggOrWindow bool + // If CTE contain aggregation, window function, order by, distinct and limit in query (Indirect references to other cte containing those operator in the query are also counted.) + containRecursiveForbiddenOperator bool // Compute in preprocess phase. Record how many consumers the current CTE has consumerCount int } diff --git a/pkg/planner/indexadvisor/BUILD.bazel b/pkg/planner/indexadvisor/BUILD.bazel new file mode 100644 index 0000000000000..90c6b83749508 --- /dev/null +++ b/pkg/planner/indexadvisor/BUILD.bazel @@ -0,0 +1,61 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "indexadvisor", + srcs = [ + "algorithm.go", + "indexadvisor.go", + "model.go", + "optimizer.go", + "options.go", + "utils.go", + ], + importpath = "github.com/pingcap/tidb/pkg/planner/indexadvisor", + visibility = ["//visibility:public"], + deps = [ + "//pkg/domain", + "//pkg/infoschema", + "//pkg/kv", + "//pkg/meta/model", + "//pkg/parser", + "//pkg/parser/ast", + "//pkg/parser/model", + "//pkg/parser/mysql", + "//pkg/parser/opcode", + "//pkg/planner/util/fixcontrol", + "//pkg/sessionctx", + "//pkg/types", + "//pkg/types/parser_driver", + "//pkg/util/chunk", + "//pkg/util/intest", + "//pkg/util/logutil", + "//pkg/util/parser", + "//pkg/util/set", + "//pkg/util/sqlexec", + "@com_github_google_uuid//:uuid", + "@com_github_pkg_errors//:errors", + "@org_uber_go_zap//:zap", + ], +) + +go_test( + name = "indexadvisor_test", + timeout = "short", + srcs = [ + "indexadvisor_sql_test.go", + "indexadvisor_test.go", + "indexadvisor_tpch_test.go", + "optimizer_test.go", + "options_test.go", + "utils_test.go", + ], + flaky = True, + shard_count = 46, + deps = [ + ":indexadvisor", + "//pkg/parser/mysql", + "//pkg/testkit", + "//pkg/util/set", + "@com_github_stretchr_testify//require", + ], +) diff --git a/pkg/planner/indexadvisor/indexadvisor_test.go b/pkg/planner/indexadvisor/indexadvisor_test.go new file mode 100644 index 0000000000000..9c940d90c7894 --- /dev/null +++ b/pkg/planner/indexadvisor/indexadvisor_test.go @@ -0,0 +1,580 @@ +// Copyright 2024 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package indexadvisor_test + +import ( + "context" + "fmt" + "math/rand" + "sort" + "strings" + "testing" + + "github.com/pingcap/tidb/pkg/planner/indexadvisor" + "github.com/pingcap/tidb/pkg/testkit" + s "github.com/pingcap/tidb/pkg/util/set" + "github.com/stretchr/testify/require" +) + +func check(ctx context.Context, t *testing.T, tk *testkit.TestKit, + expected, SQLs string) { + if ctx == nil { + ctx = context.Background() + } + var sqls []string + if SQLs != "" { + sqls = strings.Split(SQLs, ";") + } + r, err := indexadvisor.AdviseIndexes(ctx, tk.Session(), sqls, nil) + if expected == "err" { + require.Error(t, err) + return + } + require.NoError(t, err) + + if expected == "" { + require.Len(t, r, 0) + return + } + + indexes := make([]string, 0, len(r)) + for _, result := range r { + indexes = append(indexes, fmt.Sprintf("%v.%v.%v", result.Database, result.Table, strings.Join(result.IndexColumns, "_"))) + } + sort.Strings(indexes) + require.Equal(t, expected, strings.Join(indexes, ",")) +} + +func TestIndexAdvisorInvalidQuery(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + + check(nil, t, tk, "err", "xxx") + check(nil, t, tk, "err", "xxx;select a from t where a=1") +} + +func TestIndexAdvisorFrequency(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int)`) + tk.MustExec(`recommend index set max_num_index=1`) + + querySet := s.NewSet[indexadvisor.Query]() + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where a=1", Frequency: 2}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where b=1", Frequency: 1}) + ctx := context.WithValue(context.Background(), indexadvisor.TestKey("query_set"), querySet) + check(ctx, t, tk, "test.t.a", "") + + querySet = s.NewSet[indexadvisor.Query]() + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where a=1", Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where b=1", Frequency: 2}) + ctx = context.WithValue(context.Background(), indexadvisor.TestKey("query_set"), querySet) + check(ctx, t, tk, "test.t.b", "") + + querySet = s.NewSet[indexadvisor.Query]() + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where a=1", Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where b=1", Frequency: 2}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: "select * from t where c=1", Frequency: 100}) + ctx = context.WithValue(context.Background(), indexadvisor.TestKey("query_set"), querySet) + check(ctx, t, tk, "test.t.c", "") +} + +func TestIndexAdvisorBasic1(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int)`) + + check(nil, t, tk, "test.t.a", "select * from t where a=1") + check(nil, t, tk, "test.t.a,test.t.b", "select * from t where a=1; select * from t where b=1") + check(nil, t, tk, "test.t.a,test.t.b", "select a from t where a=1; select b from t where b=1") +} + +func TestIndexAdvisorBasic2(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + + sqls := make([]string, 0, 100) + for i := 0; i < 100; i++ { + tk.MustExec(fmt.Sprintf(`create table t%d (a int, b int, c int)`, i)) + sql := fmt.Sprintf("select * from t%d", i) // useless SQLs + sqls = append(sqls, sql) + } + sqls = append(sqls, "select * from t0 where a=1") // only 1 single useful SQL + check(nil, t, tk, "test.t0.a", strings.Join(sqls, ";")) +} + +// (TODO) The index advisor miss the preprocessor phase which cause the CTE_inline rule_by_default is not applied. +//func TestIndexAdvisorCTE(t *testing.T) { +// store := testkit.CreateMockStore(t) +// tk := testkit.NewTestKit(t, store) +// tk.MustExec(`use test`) +// tk.MustExec(`create table t (a int, b int, c int)`) +// +// check(nil, t, tk, "test.t.a_b", +// "with cte as (select * from t where a=1) select * from cte where b=1") +// check(nil, t, tk, "test.t.a_b_c,test.t.c", +// "with cte as (select * from t where a=1) select * from cte where b=1; select * from t where c=1") +//} + +func TestIndexAdvisorFixControl43817(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t1 (a int, b int, c int)`) + tk.MustExec(`create table t2 (a int, b int, c int)`) + + check(nil, t, tk, "err", "select * from t1 where a=(select max(a) from t2)") + check(nil, t, tk, "err", + "select * from t1 where a=(select max(a) from t2); select * from t1 where b=1") + check(nil, t, tk, "err", + "select * from t1 where a=(select max(a) from t2);select a from t1 where a=1") + + querySet := s.NewSet[indexadvisor.Query]() + querySet.Add(indexadvisor.Query{SchemaName: "test", + Text: "select * from t1 where a=(select max(a) from t2)", Frequency: 1}) + ctx := context.WithValue(context.Background(), indexadvisor.TestKey("query_set"), querySet) + check(ctx, t, tk, "err", "") // empty query set after filtering invalid queries + querySet.Add(indexadvisor.Query{SchemaName: "test", + Text: "select * from t1 where a=(select max(a) from t2); select * from t1 where b=1", Frequency: 1}) + check(ctx, t, tk, "err", "") // empty query set after filtering invalid queries + querySet.Add(indexadvisor.Query{SchemaName: "test", + Text: "select a from t1 where a=1", Frequency: 1}) + check(ctx, t, tk, "test.t1.a", "") // invalid queries would be ignored +} + +func TestIndexAdvisorView(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int)`) + tk.MustExec("create DEFINER=`root`@`127.0.0.1` view v as select * from t where a=1") + + check(nil, t, tk, "test.t.b", "select * from v where b=1") + check(nil, t, tk, "test.t.b,test.t.c", + "select * from v where b=1; select * from t where c=1") +} + +func TestIndexAdvisorMassive(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`recommend index set max_num_index=3`) + + for i := 0; i < 10; i++ { + sql := fmt.Sprintf(`create table t%d(c0 int,c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int)`, i) + tk.MustExec(sql) + } + sqls := make([]string, 0, 10) + for i := 0; i < 10; i++ { + sql := fmt.Sprintf("select * from t%d where c%d=1 and c%d=1 and c%d=1", + rand.Intn(10), rand.Intn(8), rand.Intn(8), rand.Intn(8)) + sqls = append(sqls, sql) + } + r, err := indexadvisor.AdviseIndexes(context.Background(), tk.Session(), sqls, nil) + require.NoError(t, err) // no error and can get some recommendations + require.Len(t, r, 3) +} + +func TestIndexAdvisorIncorrectCurrentDB(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int)`) + + tk.MustExec(`use mysql`) + check(nil, t, tk, "test.t.a", "select * from test.t where a=1") +} + +func TestIndexAdvisorPrefix(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int)`) + + check(nil, t, tk, "test.t.a_b", + "select * from t where a=1;select * from t where a=1 and b=1") + check(nil, t, tk, "test.t.a_b_c", // a_b_c can cover a_b + "select * from t where a=1;select * from t where a=1 and b=1; select * from t where a=1 and b=1 and c=1") +} + +func TestIndexAdvisorCoveringIndex(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int, d int)`) + + check(nil, t, tk, "test.t.a_b", "select b from t where a=1") + check(nil, t, tk, "test.t.a_b_c", "select b, c from t where a=1") + check(nil, t, tk, "test.t.a_d_b", "select b from t where a=1 and d=1") +} + +func TestIndexAdvisorExistingIndex(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int, index ab (a, b))`) + + check(nil, t, tk, "", "select * from t where a=1") // covered by existing a_b + check(nil, t, tk, "", "select * from t where a=1; select * from t where a=1 and b=1") + check(nil, t, tk, "test.t.c", + "select * from t where a=1; select * from t where a=1 and b=1; select * from t where c=1") +} + +func TestIndexAdvisorTPCC(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + + // All PKs are removed otherwise can't recommend any index. + tk.MustExec(`CREATE TABLE IF NOT EXISTS customer ( + c_id INT NOT NULL, + c_d_id INT NOT NULL, + c_w_id INT NOT NULL, + c_first VARCHAR(16), + c_middle CHAR(2), + c_last VARCHAR(16), + c_street_1 VARCHAR(20), + c_street_2 VARCHAR(20), + c_city VARCHAR(20), + c_state CHAR(2), + c_zip CHAR(9), + c_phone CHAR(16), + c_since TIMESTAMP, + c_credit CHAR(2), + c_credit_lim DECIMAL(12, 2), + c_discount DECIMAL(4,4), + c_balance DECIMAL(12,2), + c_ytd_payment DECIMAL(12,2), + c_payment_cnt INT, + c_delivery_cnt INT, + c_data VARCHAR(500))`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS warehouse ( + w_id INT NOT NULL, + w_name VARCHAR(10), + w_street_1 VARCHAR(20), + w_street_2 VARCHAR(20), + w_city VARCHAR(20), + w_state CHAR(2), + w_zip CHAR(9), + w_tax DECIMAL(4, 4), + w_ytd DECIMAL(12, 2))`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS stock ( + s_i_id INT NOT NULL, + s_w_id INT NOT NULL, + s_quantity INT, + s_dist_01 CHAR(24), + s_dist_02 CHAR(24), + s_dist_03 CHAR(24), + s_dist_04 CHAR(24), + s_dist_05 CHAR(24), + s_dist_06 CHAR(24), + s_dist_07 CHAR(24), + s_dist_08 CHAR(24), + s_dist_09 CHAR(24), + s_dist_10 CHAR(24), + s_ytd INT, + s_order_cnt INT, + s_remote_cnt INT, + s_data VARCHAR(50))`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS orders ( + o_id INT NOT NULL, + o_d_id INT NOT NULL, + o_w_id INT NOT NULL, + o_c_id INT, + o_entry_d DATETIME, + o_carrier_id INT, + o_ol_cnt INT, + o_all_local INT)`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS new_order ( + no_o_id INT NOT NULL, + no_d_id INT NOT NULL, + no_w_id INT NOT NULL)`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS district ( + d_id INT NOT NULL, + d_w_id INT NOT NULL, + d_name VARCHAR(10), + d_street_1 VARCHAR(20), + d_street_2 VARCHAR(20), + d_city VARCHAR(20), + d_state CHAR(2), + d_zip CHAR(9), + d_tax DECIMAL(4, 4), + d_ytd DECIMAL(12, 2), + d_next_o_id INT)`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS item ( + i_id INT NOT NULL, + i_im_id INT, + i_name VARCHAR(24), + i_price DECIMAL(5, 2), + i_data VARCHAR(50))`) + tk.MustExec(`CREATE TABLE IF NOT EXISTS order_line ( + ol_o_id INT NOT NULL, + ol_d_id INT NOT NULL, + ol_w_id INT NOT NULL, + ol_number INT NOT NULL, + ol_i_id INT NOT NULL, + ol_supply_w_id INT, + ol_delivery_d TIMESTAMP, + ol_quantity INT, + ol_amount DECIMAL(6, 2), + ol_dist_info CHAR(24))`) + + q1 := `SELECT c_discount, c_last, c_credit, w_tax FROM customer, warehouse WHERE w_id = 1 AND c_w_id = w_id AND c_d_id = 6 AND c_id = 1309` + q2 := `SELECT s_i_id, s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 FROM stock WHERE (s_w_id, s_i_id) IN ((1, 54388), (1, 40944), (1, 66045)) FOR UPDATE` + q3 := `SELECT o_id, o_carrier_id, o_entry_d FROM orders WHERE o_w_id = 4 AND o_d_id = 6 AND o_c_id = 914 ORDER BY o_id DESC LIMIT 1` + q4 := `SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_credit, c_credit_lim, c_discount, c_balance, c_since FROM customer WHERE c_w_id = 2 AND c_d_id = 1 AND c_id = 1106 FOR UPDATE` + q5 := `SELECT count(c_id) namecnt FROM customer WHERE c_w_id = 4 AND c_d_id = 6 AND c_last = 'EINGOUGHTPRI'` + q6 := `SELECT c_id FROM customer WHERE c_w_id = 2 AND c_d_id = 1 AND c_last = "PRESCALLYCALLY" ORDER BY c_first` + q7 := `SELECT no_o_id FROM new_order WHERE no_w_id = 1 AND no_d_id = 1 ORDER BY no_o_id ASC LIMIT 1 FOR UPDATE` + q8 := `SELECT d_next_o_id, d_tax FROM district WHERE d_id = 1 AND d_w_id = 3 FOR UPDATE` + q9 := `SELECT i_price, i_name, i_data, i_id FROM item WHERE i_id IN (81071, 93873, 97661, 2909, 24471, 8669, 40429, 31485, 31064, 20916, 16893, 8283)` + q10 := `SELECT s_i_id, s_quantity, s_data, s_dist_01, s_dist_02, s_dist_03, s_dist_04, s_dist_05, s_dist_06, s_dist_07, s_dist_08, s_dist_09, s_dist_10 FROM stock WHERE (s_w_id, s_i_id) IN ((1, 33259),(1, 98411)) FOR UPDATE` + q11 := `SELECT c_balance, c_first, c_middle, c_id FROM customer WHERE c_w_id = 4 AND c_d_id = 4 AND c_last = 'EINGOUGHTPRI' ORDER BY c_first` + q12 := `SELECT d_next_o_id FROM district WHERE d_w_id = 4 AND d_id = 5` + q13 := `SELECT /*+ TIDB_INLJ(order_line,stock) */ COUNT(DISTINCT (s_i_id)) stock_count FROM order_line, stock WHERE ol_w_id = 4 AND ol_d_id = 5 AND ol_o_id < 3005 AND ol_o_id >= 3005 - 20 AND s_w_id = 4 AND s_i_id = ol_i_id AND s_quantity < 14` + q14 := `SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d FROM order_line WHERE ol_w_id = 4 AND ol_d_id = 6 AND ol_o_id = 93` + q15 := `SELECT c_data FROM customer WHERE c_w_id = 3 AND c_d_id = 9 AND c_id = 640` + + querySet := s.NewSet[indexadvisor.Query]() + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q1, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q2, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q3, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q4, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q5, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q6, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q7, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q8, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q9, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q10, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q11, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q12, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q13, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q14, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q15, Frequency: 1}) + + tk.MustExec(`recommend index set max_num_index=3`) + ctx := context.WithValue(context.Background(), indexadvisor.TestKey("query_set"), querySet) + r, err := indexadvisor.AdviseIndexes(ctx, tk.Session(), nil, nil) + require.NoError(t, err) + require.True(t, len(r) > 0) +} + +func TestIndexAdvisorWeb3Bench(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + + tk.MustExec(`CREATE TABLE blocks ( + timestamp bigint(20) DEFAULT NULL, + number bigint(20) DEFAULT NULL, + hash varchar(66) DEFAULT NULL, + parent_hash varchar(66) DEFAULT NULL, + nonce varchar(42) DEFAULT NULL, + sha3_uncles varchar(66) DEFAULT NULL, + logs_bloom text DEFAULT NULL, + transactions_root varchar(66) DEFAULT NULL, + state_root varchar(66) DEFAULT NULL, + receipts_root varchar(66) DEFAULT NULL, + miner varchar(42) DEFAULT NULL, + difficulty decimal(38,0) DEFAULT NULL, + total_difficulty decimal(38,0) DEFAULT NULL, + size bigint(20) DEFAULT NULL, + extra_data text DEFAULT NULL, + gas_limit bigint(20) DEFAULT NULL, + gas_used bigint(20) DEFAULT NULL, + transaction_count bigint(20) DEFAULT NULL, + base_fee_per_gas bigint(20) DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE transactions ( + hash varchar(66) DEFAULT NULL, + nonce bigint(20) DEFAULT NULL, + block_hash varchar(66) DEFAULT NULL, + block_number bigint(20) DEFAULT NULL, + transaction_index bigint(20) DEFAULT NULL, + from_address varchar(42) DEFAULT NULL, + to_address varchar(42) DEFAULT NULL, + value decimal(38,0) DEFAULT NULL, + gas bigint(20) DEFAULT NULL, + gas_price bigint(20) DEFAULT NULL, + input text DEFAULT NULL, + block_timestamp bigint(20) DEFAULT NULL, + max_fee_per_gas bigint(20) DEFAULT NULL, + max_priority_fee_per_gas bigint(20) DEFAULT NULL, + transaction_type bigint(20) DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE token_transfers ( + token_address varchar(42) DEFAULT NULL, + from_address varchar(42) DEFAULT NULL, + to_address varchar(42) DEFAULT NULL, + value varchar(78) DEFAULT NULL COMMENT 'Postgresql use numeric(78), while the max_value of Decimal is decimal(65), thus use string here', + transaction_hash varchar(66) DEFAULT NULL, + log_index bigint(20) DEFAULT NULL, + block_number bigint(20) DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE receipts ( + transaction_hash varchar(66) DEFAULT NULL, + transaction_index bigint(20) DEFAULT NULL, + block_hash varchar(66) DEFAULT NULL, + block_number bigint(20) DEFAULT NULL, + cumulative_gas_used bigint(20) DEFAULT NULL, + gas_used bigint(20) DEFAULT NULL, + contract_address varchar(42) DEFAULT NULL, + root varchar(66) DEFAULT NULL, + status bigint(20) DEFAULT NULL, + effective_gas_price bigint(20) DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE logs ( + log_index bigint(20) DEFAULT NULL, + transaction_hash varchar(66) DEFAULT NULL, + transaction_index bigint(20) DEFAULT NULL, + block_hash varchar(66) DEFAULT NULL, + block_number bigint(20) DEFAULT NULL, + address varchar(42) DEFAULT NULL, + data text DEFAULT NULL, + topics text DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE contracts ( + address char(42) DEFAULT NULL, + bytecode text DEFAULT NULL, + function_sighashes text DEFAULT NULL, + is_erc20 tinyint(1) DEFAULT NULL, + is_erc721 tinyint(1) DEFAULT NULL, + block_number bigint(20) DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE tokens ( + address char(42) DEFAULT NULL, + symbol text DEFAULT NULL, + name text DEFAULT NULL, + decimals bigint(20) DEFAULT NULL, + total_supply decimal(38,0) DEFAULT NULL, + block_number bigint(20) DEFAULT NULL)`) + tk.MustExec(`CREATE TABLE traces ( + block_number bigint(20) DEFAULT NULL, + transaction_hash varchar(66) DEFAULT NULL, + transaction_index bigint(20) DEFAULT NULL, + from_address varchar(42) DEFAULT NULL, + to_address varchar(42) DEFAULT NULL, + value decimal(38,0) DEFAULT NULL, + input text DEFAULT NULL, + output text DEFAULT NULL, + trace_type varchar(16) DEFAULT NULL, + call_type varchar(16) DEFAULT NULL, + reward_type varchar(16) DEFAULT NULL, + gas bigint(20) DEFAULT NULL, + gas_used bigint(20) DEFAULT NULL, + subtraces bigint(20) DEFAULT NULL, + trace_address text DEFAULT NULL, + error text DEFAULT NULL, + status bigint(20) DEFAULT NULL, + trace_id text DEFAULT NULL)`) + + q1 := `Select to_address, from_address from transactions where hash = '0x1f415defb2729863fd8088727900d99b7df6f03d5e22e2105fc984cac3d0fb1c'` + q2 := `Select * from transactions where to_address in ('0x70f0f4f40fed33420c1e4ceefa1eb482e044ba24', + '0x34662f274a42a17876926bc7b0ba541535e40e5f', + '0x7259c2a51a9b1f7e373dcd00898d26a44ffc2e7c')` + q3 := `Select * from transactions +where hash in ('0x1f415defb2729863fd8088727900d99b7df6f03d5e22e2105fc984cac3d0fb1c', + '0xbeff7a4cf341d10c6293a2ecfb255f39c21836bf8956c6877d0f2486794fd5b8', + '0x5dee984c63cc26037a81d0f2861565c4e0c21a87ebf165b331faec347d7a76a1', + '0xc7da1e3391e4b7769fffe8e6afc284175a6cbe5fd9b333d9c0585944a36118dd') and to_address <> from_address` + q4 := `SELECT * FROM token_transfers WHERE from_address = '0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98' ORDER BY block_number DESC LIMIT 5` + q5 := `Select count(*) from token_transfers where token_address = '0x7a93f0d9f302c0818022f8dca6ee1eb0f1b50308'` + q6 := `SELECT * FROM transactions +WHERE from_address = '0x31d118c5f75502b96ca21d3d0d3fb8d7b19fed24' OR to_address = '0x6364989a903f45798c7a292778285a83d0928608' +ORDER BY block_timestamp DESC LIMIT 10` + q7 := `SELECT count(DISTINCT from_address) FROM transactions` + q8 := `SELECT + count(*) as count +FROM (SELECT * + FROM token_transfers t + WHERE from_address = '0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98' + UNION ALL + SELECT t2.* + FROM token_transfers t2 + INNER JOIN token_transfers t ON t2.from_address = t.to_address + AND t.value < t2.value + LIMIT 100) as temp` + q9 := `SELECT COUNT(DISTINCT block_receipts) as count +FROM (SELECT block_number AS block_receipts + FROM receipts + WHERE NOT EXISTS ( + SELECT block_number + FROM transactions + WHERE block_number = receipts.block_number)) as temp` + + querySet := s.NewSet[indexadvisor.Query]() + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q1, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q2, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q3, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q4, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q5, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q6, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q7, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q8, Frequency: 1}) + querySet.Add(indexadvisor.Query{SchemaName: "test", Text: q9, Frequency: 1}) + + tk.MustExec(`recommend index set max_num_index=3`) + ctx := context.WithValue(context.Background(), indexadvisor.TestKey("query_set"), querySet) + r, err := indexadvisor.AdviseIndexes(ctx, tk.Session(), nil, nil) + require.NoError(t, err) + require.True(t, len(r) > 0) +} + +func TestIndexAdvisorRunFor(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t1 (a int, b int, c int)`) + tk.MustExec(`create table t2 (a int, b int, c int)`) + + r := tk.MustQuery(`recommend index run for "select * from t1 where a=1"`) + require.True(t, len(r.Rows()) == 1) + r = tk.MustQuery(`recommend index run for "select * from t1 where a=1;select * from t2 where b=1"`) + require.True(t, len(r.Rows()) == 2) + tk.MustQueryToErr(`recommend index run for ";"`) + tk.MustQueryToErr(`recommend index run for "xxx"`) + tk.MustQueryToErr(`recommend index run for ";;;"`) + tk.MustQueryToErr(`recommend index run for ";;xx;"`) + r = tk.MustQuery(`recommend index run for ";;select * from t1 where a=1;; ;; ;"`) + require.True(t, len(r.Rows()) == 1) +} + +func TestIndexAdvisorStorage(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`create table t (a int, b int, c int, d varchar(32))`) + q := `select index_columns, index_details->'$.Reason' from mysql.index_advisor_results` + + tk.MustQuery(`recommend index run for "select a from t where a=1"`) + tk.MustQuery(q).Sort().Check(testkit.Rows( + "a \"Column [a] appear in Equal or Range Predicate clause(s) in query: select `a` from `test` . `t` where `a` = ?\"")) + + tk.MustQuery(`recommend index run for "select b from t where b=1"`) + tk.MustQuery(q).Sort().Check(testkit.Rows( + "a \"Column [a] appear in Equal or Range Predicate clause(s) in query: select `a` from `test` . `t` where `a` = ?\"", + "b \"Column [b] appear in Equal or Range Predicate clause(s) in query: select `b` from `test` . `t` where `b` = ?\"")) + + tk.MustQuery(`recommend index run for "select d from t where d='x'"`) + tk.MustQuery(q).Sort().Check(testkit.Rows( + "a \"Column [a] appear in Equal or Range Predicate clause(s) in query: select `a` from `test` . `t` where `a` = ?\"", + "b \"Column [b] appear in Equal or Range Predicate clause(s) in query: select `b` from `test` . `t` where `b` = ?\"", + "d \"Column [d] appear in Equal or Range Predicate clause(s) in query: select `d` from `test` . `t` where `d` = ?\"")) + + tk.MustQuery(`recommend index run for "select c, b from t where c=1 and b=1"`) + tk.MustQuery(q).Sort().Check(testkit.Rows( + "a \"Column [a] appear in Equal or Range Predicate clause(s) in query: select `a` from `test` . `t` where `a` = ?\"", + "b \"Column [b] appear in Equal or Range Predicate clause(s) in query: select `b` from `test` . `t` where `b` = ?\"", + "b,c \"Column [b c] appear in Equal or Range Predicate clause(s) in query: select `c` , `b` from `test` . `t` where `c` = ? and `b` = ?\"", + "d \"Column [d] appear in Equal or Range Predicate clause(s) in query: select `d` from `test` . `t` where `d` = ?\"")) +} diff --git a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result new file mode 100644 index 0000000000000..34b2a496a295f --- /dev/null +++ b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result @@ -0,0 +1,3866 @@ +drop table if exists t1, t2; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +explain format = 'brief' select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +explain format = 'brief' select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +IndexHashJoin 12500.00 root left outer join, inner:TableReader, outer key:planner__core__casetest__physicalplantest__physical_plan.t1.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t2.a, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a), eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t1.a], keep order:false, stats:pseudo +select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +explain format = 'brief' select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +IndexJoin 12500.00 root left outer join, inner:TableReader, outer key:planner__core__casetest__physicalplantest__physical_plan.t1.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t2.a, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a), eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t1.a], keep order:false, stats:pseudo +select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +explain format = 'brief' select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +drop table if exists t1, t2, t3; +create table t1(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, UNIQUE KEY idx_a (a)); +create table t2(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL); +create table t3(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, c int(11) DEFAULT NULL, UNIQUE KEY idx_abc (a, b, c)); +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +id estRows task access object operator info +HashJoin 9990.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a)], other cond:lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) +├─IndexReader(Build) 7992.00 root index:Selection +│ └─Selection 7992.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) +│ └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo +└─TableReader(Probe) 7992.00 root data:Selection + └─Selection 7992.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t2.a), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +a +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +id estRows task access object operator info +Projection 9990.00 root planner__core__casetest__physicalplantest__physical_plan.t2.a +└─Apply 9990.00 root CARTESIAN inner join, other cond:lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─Selection(Probe) 7992.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)) + └─MaxOneRow 9990.00 root + └─IndexLookUp 9.99 root + ├─IndexRangeScan(Build) 9990.00 cop[tikv] table:t1, index:idx_a(a) range:[NULL,NULL], keep order:false, stats:pseudo + └─Selection(Probe) 9.99 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) + └─TableRowIDScan 9990.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +a +explain format = 'brief' select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); +id estRows task access object operator info +Projection 9990.00 root planner__core__casetest__physicalplantest__physical_plan.t2.a +└─Apply 9990.00 root CARTESIAN inner join, other cond:lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a) + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─Selection(Probe) 7992.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t3.a)) + └─MaxOneRow 9990.00 root + └─IndexReader 19980.00 root index:IndexRangeScan + └─IndexRangeScan 19980.00 cop[tikv] table:t3, index:idx_abc(a, b, c) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t3.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)], keep order:false, stats:pseudo +select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); +a +set tidb_cost_model_version=2; +drop table if exists t, tt; +create table t (a int primary key, b int, index idx(a)); +create table tt (a int primary key) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200)); +set @@tidb_partition_prune_mode='static'; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a; +id estRows task access object operator info +IndexJoin 12500.00 root inner join, inner:UnionScan, outer key:planner__core__casetest__physicalplantest__physical_plan.t.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t.a, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.a) +├─UnionScan(Build) 10000.00 root +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─UnionScan(Probe) 10000.00 root + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t.a], keep order:false, stats:pseudo +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.b; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b +└─HashJoin 12487.50 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.a)] + ├─UnionScan(Build) 9990.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + │ └─TableReader 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─UnionScan(Probe) 10000.00 root + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ t1.a , t2.b from t t1, t t2 where t1.a = t2.b; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b +└─HashJoin 12487.50 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.a)] + ├─UnionScan(Build) 10000.00 root + │ └─IndexReader 10000.00 root index:IndexFullScan + │ └─IndexFullScan 10000.00 cop[tikv] table:t1, index:idx(a) keep order:false, stats:pseudo + └─UnionScan(Probe) 9990.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + └─TableReader 9990.00 root data:Selection + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +rollback; +begin; +insert into tt values(1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from tt t1, tt t2 where t1.a = t2.a; +id estRows task access object operator info +HashJoin 25000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tt.a, planner__core__casetest__physicalplantest__physical_plan.tt.a)] +├─PartitionUnion(Build) 20000.00 root +│ ├─UnionScan 10000.00 root +│ │ └─TableReader 10000.00 root data:TableFullScan +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +│ └─UnionScan 10000.00 root +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 20000.00 root + ├─UnionScan 10000.00 root + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo + └─UnionScan 10000.00 root + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo +rollback; +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), primary key (c_int)); +create table t2 (c_int int, c_str varchar(40), primary key (c_int)); +insert into t1 (`c_int`, `c_str`) values (11, 'keen williamson'), (10, 'gracious hermann'); +insert into t2 (`c_int`, `c_str`) values (10, 'gracious hermann'); +begin; +insert into t2 values (11, 'amazing merkle'); +insert into t2 values (12, 'amazing merkle'); +explain format = 'brief' select /*+ MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_int = t2.c_int order by t1.c_int, t2.c_str; +id estRows task access object operator info +Sort 12500.00 root planner__core__casetest__physicalplantest__physical_plan.t1.c_int, planner__core__casetest__physicalplantest__physical_plan.t2.c_str +└─MergeJoin 12500.00 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.c_int, right key:planner__core__casetest__physicalplantest__physical_plan.t2.c_int + ├─UnionScan(Build) 10000.00 root + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +rollback; +set tidb_cost_model_version=2; +drop table if exists tn; +create table tn(a int, b int, c int, d int, key (a, b, c, d)); +set tidb_opt_limit_push_down_threshold=0; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +id estRows task access object operator info +TopN 0.83 root planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 +└─IndexReader 0.83 root index:TopN + └─TopN 0.83 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 + └─Selection 0.83 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.tn.c, 50) + └─IndexRangeScan 2.50 cop[tikv] table:tn, index:a(a, b, c, d) range:(1 10,1 20), keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +id estRows task access object operator info +TopN 0.83 root planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 +└─IndexReader 0.83 root index:TopN + └─TopN 0.83 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 + └─Selection 0.83 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.tn.c, 50) + └─IndexRangeScan 2.50 cop[tikv] table:tn, index:a(a, b, c, d) range:(1 10,1 20), keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a div 2 order by a limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─IndexReader 1.00 root index:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─Selection 1.00 cop[tikv] intdiv(planner__core__casetest__physicalplantest__physical_plan.tn.a, 2) + └─IndexFullScan 1.25 cop[tikv] table:tn, index:a(a, b, c, d) keep order:true, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─IndexReader 1.00 root index:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─IndexRangeScan 1.00 cop[tikv] table:tn, index:a(a, b, c, d) range:(10,+inf], keep order:false, stats:pseudo +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +set tidb_opt_limit_push_down_threshold=DEFAULT; +drop table if exists tc, te, t1, t2, t3, t4; +drop view if exists v; +create table tc(a int); +create table te(c int); +create table t1(a int); +create table t2(b int); +create table t3(c int); +create table t4(d int); +insert into tc values (1), (5), (10), (15), (20), (30), (50); +insert into te values (1), (5), (10), (25), (40), (60), (100); +insert into t1 values (1), (5), (10), (25), (40), (60), (100); +insert into t2 values (1), (5), (10), (25), (40), (60), (100); +insert into t3 values (1), (5), (10), (25), (40), (60), (100); +insert into t4 values (1), (5), (10), (25), (40), (60), (100); +analyze table tc all columns; +analyze table te all columns; +analyze table t1 all columns; +analyze table t2 all columns; +analyze table t3 all columns; +analyze table t4 all columns; +create definer='root'@'localhost' view v as select * from tc; +explain format = 'brief' with cte as (select /*+ MERGE() */ * from tc where tc.a < 60) select * from cte where cte.a <18; +id estRows task access object operator info +TableReader 4.00 root data:Selection +└─Selection 4.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 18), lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 60) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte as (select * from tc where tc.a < 60) select * from cte c1, cte c2 where c1.a <18; +id estRows task access object operator info +Projection 39.20 root planner__core__casetest__physicalplantest__physical_plan.tc.a, planner__core__casetest__physicalplantest__physical_plan.tc.a +└─HashJoin 39.20 root CARTESIAN inner join + ├─Selection(Build) 5.60 root lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 18) + │ └─CTEFullScan 7.00 root CTE:cte AS c1 data:CTE_0 + └─CTEFullScan(Probe) 7.00 root CTE:cte AS c2 data:CTE_0 +CTE_0 7.00 root Non-Recursive CTE +└─TableReader(Seed Part) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 60), or(lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 18), 1) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte as (select /*+ MERGE() */ * from v) select * from cte; +id estRows task access object operator info +TableReader 7.00 root data:TableFullScan +└─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' WITH cte1 AS (SELECT /*+ MERGE() */ a FROM tc), cte2 AS (SELECT /*+ MERGE()*/ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +id estRows task access object operator info +HashJoin 7.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tc.a, planner__core__casetest__physicalplantest__physical_plan.te.c)] +├─TableReader(Build) 7.00 root data:Selection +│ └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.te.c)) +│ └─TableFullScan 7.00 cop[tikv] table:te keep order:false +└─TableReader(Probe) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.a)) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' WITH cte1 AS (SELECT a FROM tc), cte2 AS (SELECT /*+ MERGE() */ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +id estRows task access object operator info +HashJoin 7.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tc.a, planner__core__casetest__physicalplantest__physical_plan.te.c)] +├─TableReader(Build) 7.00 root data:Selection +│ └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.te.c)) +│ └─TableFullScan 7.00 cop[tikv] table:te keep order:false +└─TableReader(Probe) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.a)) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte1 data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 + └─Selection 0.80 root lt(Column#3, 100) + └─CTETable 1.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format = 'brief' WITH cte1 AS (SELECT * FROM t1) SELECT /*+ MERGE() */ * FROM cte1 join t2 on cte1.a = t2.b; +id estRows task access object operator info +HashJoin 7.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 7.00 root data:Selection +│ └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +└─TableReader(Probe) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)) + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +explain format = 'brief' with cte1 as (with cte3 as (select /*+ MERGE() */ * from t1),cte4 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3,cte4) ,cte2 as (select /*+ MERGE() */ * from t3) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 343.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from tc), cte2 as (with cte3 as (select /*+ MERGE() */ * from te) ,cte4 as (select * from tc) select * from cte3,cte4) select * from cte2; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (with cte2 as (select /*+ MERGE() */ * from te) ,cte3 as (select /*+ MERGE() */ * from tc) select /*+ MERGE() */ * from cte2,cte3) select * from cte1; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select /*+ MERGE() */ * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select /*+ MERGE() */ * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select /*+ MERGE() */ * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte2 as (with cte4 as (select * from tc) select * from te, cte4) select * from cte2; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte2 as (with cte4 as (select /*+ merge() */ * from tc) select * from te, cte4) select * from cte2; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select /*+ MERGE() */ * from t1) ttt) select * from cte1; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +show warnings; +Level Code Message +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select /*+ MERGE() */ * from t3) ttw; +id estRows task access object operator info +HashJoin 343.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +show warnings; +Level Code Message +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select * from t3) ttw; +id estRows task access object operator info +HashJoin 343.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +show warnings; +Level Code Message +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11)); +insert into t values (1), (5), (10), (15), (20), (30), (50); +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inline; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with cte as (select * from t) select * from cte cte1, cte cte2; -- inline CTEs is used by multi consumers; +id estRows task access object operator info +HashJoin 100000000.00 root CARTESIAN inner join +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with cte1 as (select * from t), cte2 as (select a from cte1 group by a) select * from cte1, cte2; -- multi inline CTEs; +id estRows task access object operator info +HashJoin 80000000.00 root CARTESIAN inner join +├─HashAgg(Build) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.a)->planner__core__casetest__physicalplantest__physical_plan.t.a +│ └─TableReader 8000.00 root data:HashAgg +│ └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t.a, +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with recursive cte1(c1) as (select 1 union select c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte1 data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 + └─Selection 0.80 root lt(Column#3, 100) + └─CTETable 1.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +id estRows task access object operator info +CTEFullScan 8001.00 root CTE:cte2 data:CTE_0 +CTE_0 8001.00 root Recursive CTE +├─TableReader(Seed Part) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─Projection(Recursive Part) 8000.00 root cast(plus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1), int(11))->planner__core__casetest__physicalplantest__physical_plan.t.a + └─Selection 8000.00 root lt(planner__core__casetest__physicalplantest__physical_plan.t.a, 100) + └─CTETable 10000.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte2 data:CTE_2 +CTE_2 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#9 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12 + └─Selection 0.80 root lt(Column#10, 100) + └─CTETable 1.00 root Scan on CTE_2 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte. +Warning 1815 Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte. +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inlined by single consumer; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline, merge hint override session variable; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte1 data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 + └─Selection 0.80 root lt(Column#3, 100) + └─CTETable 1.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +id estRows task access object operator info +CTEFullScan 8001.00 root CTE:cte2 data:CTE_0 +CTE_0 8001.00 root Recursive CTE +├─TableReader(Seed Part) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─Projection(Recursive Part) 8000.00 root cast(plus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1), int(11))->planner__core__casetest__physicalplantest__physical_plan.t.a + └─Selection 8000.00 root lt(planner__core__casetest__physicalplantest__physical_plan.t.a, 100) + └─CTETable 10000.00 root Scan on CTE_0 +show warnings; +Level Code Message +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte2 data:CTE_2 +CTE_2 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#9 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12 + └─Selection 0.80 root lt(Column#10, 100) + └─CTETable 1.00 root Scan on CTE_2 +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +set tidb_opt_force_inline_cte=DEFAULT; +drop table if exists t, t1, t2; +CREATE TABLE `t` (`a` int(11)); +create table t1 (c1 int primary key, c2 int, index c2 (c2)); +create table t2 (c1 int unique, c2 int); +insert into t values (1), (5), (10), (15), (20), (30), (50); +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 1) select * from cte1; -- non-recursive limit, inline cte1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─HashAgg 1.00 root group by:Column#18, funcs:firstrow(Column#18)->Column#18 + └─Union 20000.00 root + ├─IndexReader 10000.00 root index:IndexFullScan + │ └─IndexFullScan 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:false, stats:pseudo + └─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 100 offset 100) select * from cte1; -- non-recursive limit, inline cte1; +id estRows task access object operator info +Limit 100.00 root offset:100, count:100 +└─HashAgg 200.00 root group by:Column#18, funcs:firstrow(Column#18)->Column#18 + └─Union 20000.00 root + ├─IndexReader 10000.00 root index:IndexFullScan + │ └─IndexFullScan 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:false, stats:pseudo + └─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 0 offset 0) select * from cte1; -- non-recursive limit, inline cte1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union (with cte2 as (select 3) select * from cte2 union all select * from cte2) -- inline cte1, not inline cte2; +id estRows task access object operator info +HashAgg 3.00 root group by:Column#9, funcs:firstrow(Column#9)->Column#9 +└─Union 3.00 root + ├─Projection 1.00 root 1->Column#9 + │ └─TableDual 1.00 root rows:1 + └─Union 2.00 root + ├─CTEFullScan 1.00 root CTE:cte2 data:CTE_2 + └─CTEFullScan 1.00 root CTE:cte2 data:CTE_2 +CTE_2 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 3->Column#5 + └─TableDual 1.00 root rows:1 +explain format='brief' with base1 as (WITH RECURSIVE cte(a) AS (with tmp as (select 1 as a) SELECT a from tmp UNION SELECT a+1 FROM cte) SELECT * FROM cte) select * from base1; -- issue #43318; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte data:CTE_3 +CTE_3 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#15 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 1.00 root cast(plus(Column#16, 1), bigint(1) BINARY)->Column#18 + └─CTETable 1.00 root Scan on CTE_3 +explain format='brief' with cte as (select 1) select * from cte; -- inline cte; +id estRows task access object operator info +Projection 1.00 root 1->Column#3 +└─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union select * from cte2; -- inline cte1, cte2; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#7 +└─Union 2.00 root + ├─Projection 1.00 root 1->Column#7 + │ └─TableDual 1.00 root rows:1 + └─Projection 1.00 root 2->Column#7 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- cannot be inlined; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#4, funcs:firstrow(Column#4)->Column#4 +└─Union 2.00 root + ├─CTEFullScan 1.00 root CTE:cte data:CTE_0 + └─CTEFullScan 1.00 root CTE:cte data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#1 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte; -- inline nested cte; +id estRows task access object operator info +Projection 1.00 root 1->Column#7 +└─TableDual 1.00 root rows:1 +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte a, cte b; -- inline inner cte, cannot be inlined outer cte; +id estRows task access object operator info +HashJoin 1.00 root CARTESIAN inner join +├─CTEFullScan(Build) 1.00 root CTE:cte AS b data:CTE_0 +└─CTEFullScan(Probe) 1.00 root CTE:cte AS a data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#3 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte1, cte2; -- inline cte2, cte3, cannot be inlined cte1; +id estRows task access object operator info +HashJoin 1.00 root CARTESIAN inner join +├─CTEFullScan(Build) 1.00 root CTE:cte1 data:CTE_0 +└─CTEFullScan(Probe) 1.00 root CTE:cte1 data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#1 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte2; -- inline cte1, cte2, cte3; +id estRows task access object operator info +Projection 1.00 root 1->Column#12 +└─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (select * from cte1) select * from cte2 a, cte2 b; -- inline cte1, cannot be inlined cte2; +id estRows task access object operator info +HashJoin 1.00 root CARTESIAN inner join +├─CTEFullScan(Build) 1.00 root CTE:cte2 AS b data:CTE_1 +└─CTEFullScan(Probe) 1.00 root CTE:cte2 AS a data:CTE_1 +CTE_1 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#3 + └─TableDual 1.00 root rows:1 +explain format='brief' with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─CTETable(Recursive Part) 1.00 root Scan on CTE_0 +explain format='brief' with x as (select * from (select a from t for update) s) select * from x where a = 1; +id estRows task access object operator info +Projection 10.00 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─SelectLock 10.00 root for update 0 + └─TableReader 10.00 root data:Selection + └─Selection 10.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- force inline cte while multi-consumer; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#6, funcs:firstrow(Column#6)->Column#6 +└─Union 2.00 root + ├─Projection 1.00 root 1->Column#6 + │ └─TableDual 1.00 root rows:1 + └─Projection 1.00 root 1->Column#6 + └─TableDual 1.00 root rows:1 +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select 1) select /*+ MERGE() */ * from cte union select * from cte; -- firstly inline cte, secondly cannot be inlined; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#4, funcs:firstrow(Column#4)->Column#4 +└─Union 2.00 root + ├─CTEFullScan 1.00 root CTE:cte data:CTE_0 + └─CTEFullScan 1.00 root CTE:cte data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#1 + └─TableDual 1.00 root rows:1 +explain format='brief' with a as (select 8 as id from dual),maxa as (select max(id) as max_id from a),b as (with recursive temp as (select 1 as lvl from dual union all select lvl+1 from temp, maxa where lvl < max_id)select * from temp) select * from b; -- issue #47711, maxa cannot be inlined because it contains agg and in the recursive part of cte temp; +id estRows task access object operator info +CTEFullScan 1.64 root CTE:temp data:CTE_4 +CTE_4 1.64 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#14 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.64 root cast(plus(Column#15, 1), bigint(1) BINARY)->Column#18 + └─HashJoin 0.64 root CARTESIAN inner join, other cond:lt(Column#15, Column#16) + ├─Selection(Build) 0.80 root not(isnull(Column#16)) + │ └─CTEFullScan 1.00 root CTE:maxa data:CTE_1 + └─Selection(Probe) 0.80 root not(isnull(Column#15)) + └─CTETable 1.00 root Scan on CTE_4 +CTE_1 1.00 root Non-Recursive CTE +└─StreamAgg(Seed Part) 1.00 root funcs:max(Column#3)->Column#4 + └─Projection 1.00 root 8->Column#3 + └─TableDual 1.00 root rows:1 +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select 1 as res from t1 union all select res+1 from tmp,b where res+1 < bb) select * from tmp) select * from c; -- inline a, cannot be inline b because b indirectly contains agg and in the recursive part of cte tmp; +id estRows task access object operator info +CTEFullScan 20000.00 root CTE:tmp data:CTE_4 +CTE_4 20000.00 root Recursive CTE +├─Projection(Seed Part) 10000.00 root 1->Column#26 +│ └─IndexReader 10000.00 root index:IndexFullScan +│ └─IndexFullScan 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:false, stats:pseudo +└─Projection(Recursive Part) 10000.00 root cast(plus(Column#27, 1), bigint(1) BINARY)->Column#30 + └─HashJoin 10000.00 root CARTESIAN inner join, other cond:lt(plus(Column#27, 1), Column#28) + ├─CTEFullScan(Build) 1.00 root CTE:b data:CTE_1 + └─CTETable(Probe) 10000.00 root Scan on CTE_4 +CTE_1 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 2->Column#8 + └─HashAgg 1.00 root funcs:count(Column#37)->Column#35 + └─IndexReader 1.00 root index:HashAgg + └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#37 + └─IndexFullScan 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:false, stats:pseudo +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c; +id estRows task access object operator info +CTEFullScan 1.80 root CTE:tmp data:CTE_4 +CTE_4 1.80 root Recursive CTE +├─Projection(Seed Part) 1.00 root 2->Column#37 +│ └─HashAgg 1.00 root funcs:count(Column#46)->Column#44 +│ └─IndexReader 1.00 root index:HashAgg +│ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#46 +│ └─IndexFullScan 10000.00 cop[tikv] table:t1, index:c2(c2) keep order:false, stats:pseudo +└─Projection(Recursive Part) 0.80 root cast(plus(Column#38, 1), bigint(1) BINARY)->Column#40 + └─Selection 0.80 root lt(plus(Column#38, 1), 10) + └─CTETable 1.00 root Scan on CTE_4 +create table test(a int); +explain WITH RECURSIVE CTE (x) AS (SELECT 1 UNION ALL SELECT distinct a FROM test), CTE1 AS (SELECT x FROM CTE UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain distinct and ref by CET1 recursive part cannot be inlined; +id estRows task access object operator info +CTEFullScan_52 14401.80 root CTE:cte1 data:CTE_1 +CTE_1 14401.80 root Recursive CTE +├─CTEFullScan_40(Seed Part) 8001.00 root CTE:cte data:CTE_0 +└─HashJoin_45(Recursive Part) 6400.80 root inner join, equal:[eq(Column#11, Column#12)] + ├─Selection_49(Build) 6400.80 root not(isnull(Column#12)) + │ └─CTETable_50 8001.00 root Scan on CTE_1 + └─Selection_47(Probe) 6400.80 root not(isnull(Column#11)) + └─CTEFullScan_48 8001.00 root CTE:cte data:CTE_0 +CTE_0 8001.00 root Non-Recursive CTE +└─Union_27(Seed Part) 8001.00 root + ├─Projection_28 1.00 root 1->Column#7 + │ └─TableDual_29 1.00 root rows:1 + └─Projection_30 8000.00 root cast(planner__core__casetest__physicalplantest__physical_plan.test.a, bigint(11) BINARY)->Column#7 + └─HashAgg_35 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.test.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.test.a)->planner__core__casetest__physicalplantest__physical_plan.test.a + └─TableReader_36 8000.00 root data:HashAgg_31 + └─HashAgg_31 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.test.a, + └─TableFullScan_34 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +create view test_cte(a) as WITH RECURSIVE CTE (x) AS (SELECT 1 UNION ALL SELECT distinct a FROM test) , CTE1 AS (SELECT x FROM CTE UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; +explain select * from test_cte; -- CTE (inside of view) cannot be inlined by default; +id estRows task access object operator info +CTEFullScan_54 14401.80 root CTE:cte1 data:CTE_1 +CTE_1 14401.80 root Recursive CTE +├─CTEFullScan_42(Seed Part) 8001.00 root CTE:cte data:CTE_0 +└─HashJoin_47(Recursive Part) 6400.80 root inner join, equal:[eq(Column#11, Column#12)] + ├─Selection_51(Build) 6400.80 root not(isnull(Column#12)) + │ └─CTETable_52 8001.00 root Scan on CTE_1 + └─Selection_49(Probe) 6400.80 root not(isnull(Column#11)) + └─CTEFullScan_50 8001.00 root CTE:cte data:CTE_0 +CTE_0 8001.00 root Non-Recursive CTE +└─Union_29(Seed Part) 8001.00 root + ├─Projection_30 1.00 root 1->Column#7 + │ └─TableDual_31 1.00 root rows:1 + └─Projection_32 8000.00 root cast(planner__core__casetest__physicalplantest__physical_plan.test.a, bigint(11) BINARY)->Column#7 + └─HashAgg_37 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.test.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.test.a)->planner__core__casetest__physicalplantest__physical_plan.test.a + └─TableReader_38 8000.00 root data:HashAgg_33 + └─HashAgg_33 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.test.a, + └─TableFullScan_36 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +create view test_inline_cte(a) as with CTE (x) as (select distinct a from test) select * from CTE; +explain select * from test_inline_cte; -- CTE (inside of view) cannot be inlined by default; +id estRows task access object operator info +CTEFullScan_17 8000.00 root CTE:cte data:CTE_0 +CTE_0 8000.00 root Non-Recursive CTE +└─HashAgg_12(Seed Part) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.test.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.test.a)->planner__core__casetest__physicalplantest__physical_plan.test.a + └─TableReader_13 8000.00 root data:HashAgg_8 + └─HashAgg_8 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.test.a, + └─TableFullScan_11 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +create view test_force_inline_cte(a) as with CTE (x) as (select /*+ merge() */ distinct a from test) select * from CTE; +explain select * from test_force_inline_cte; -- CTE (inside of view) can be inlined by force; +id estRows task access object operator info +HashAgg_16 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.test.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.test.a)->planner__core__casetest__physicalplantest__physical_plan.test.a +└─TableReader_17 8000.00 root data:HashAgg_12 + └─HashAgg_12 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.test.a, + └─TableFullScan_15 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test limit 1) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain limit and ref by CET1 recursive part cannot be inlined; +id estRows task access object operator info +CTEFullScan_42 16400.00 root CTE:cte1 data:CTE_1 +CTE_1 16400.00 root Recursive CTE +├─TableReader_22(Seed Part) 10000.00 root data:TableFullScan_21 +│ └─TableFullScan_21 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +└─HashJoin_36(Recursive Part) 6400.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.test.a, planner__core__casetest__physicalplantest__physical_plan.test.a)] + ├─Selection_37(Build) 0.80 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + │ └─CTEFullScan_38 1.00 root CTE:cte data:CTE_0 + └─Selection_39(Probe) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + └─CTETable_40 10000.00 root Scan on CTE_1 +CTE_0 1.00 root Non-Recursive CTE +└─Limit_28(Seed Part) 1.00 root offset:0, count:1 + └─TableReader_32 1.00 root data:Limit_31 + └─Limit_31 1.00 cop[tikv] offset:0, count:1 + └─TableFullScan_30 1.00 cop[tikv] table:test keep order:false, stats:pseudo +explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test order by a) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain order by and ref by CET1 recursive part cannot be inlined; +id estRows task access object operator info +CTEFullScan_35 20000.00 root CTE:cte1 data:CTE_1 +CTE_1 20000.00 root Recursive CTE +├─TableReader_20(Seed Part) 10000.00 root data:TableFullScan_19 +│ └─TableFullScan_19 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +└─HashJoin_29(Recursive Part) 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.test.a, planner__core__casetest__physicalplantest__physical_plan.test.a)] + ├─Selection_30(Build) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + │ └─CTEFullScan_31 10000.00 root CTE:cte data:CTE_0 + └─Selection_32(Probe) 8000.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.test.a)) + └─CTETable_33 10000.00 root Scan on CTE_1 +CTE_0 10000.00 root Non-Recursive CTE +└─TableReader_25(Seed Part) 10000.00 root data:TableFullScan_24 + └─TableFullScan_24 10000.00 cop[tikv] table:test keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, b int, c int, index(c)); +insert into t values (1, 1, 1), (1, 1, 3), (1, 2, 3), (2, 1, 3), (1, 2, NULL); +drop table if exists pt; +CREATE TABLE pt (a int, b int) PARTITION BY RANGE (a) ( +PARTITION p0 VALUES LESS THAN (2), +PARTITION p1 VALUES LESS THAN (100) +); +drop table if exists tc; +CREATE TABLE `tc`(`timestamp` timestamp NULL DEFAULT NULL, KEY `idx_timestamp` (`timestamp`)) PARTITION BY RANGE ( UNIX_TIMESTAMP(`timestamp`) ) (PARTITION `p2020072312` VALUES LESS THAN (1595480400),PARTITION `p2020072313` VALUES LESS THAN (1595484000)); +drop table if exists ta; +create table ta(a int); +insert into ta values(1), (1); +drop table if exists tb; +create table tb(a int); +insert into tb values(1), (1); +set session sql_mode=''; +set session tidb_hashagg_partial_concurrency=1; +set session tidb_hashagg_final_concurrency=1; +set @@tidb_partition_prune_mode='static'; +set @@session.tidb_opt_distinct_agg_push_down = 1; +set session tidb_opt_agg_push_down = 0; +set tidb_cost_model_version=2; +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(distinct Column#9)->Column#4 +└─Projection 16000.00 root cast(planner__core__casetest__physicalplantest__physical_plan.pt.b, decimal(10,0) BINARY)->Column#9 + └─PartitionUnion 16000.00 root + ├─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b + │ └─TableReader 8000.00 root data:HashAgg + │ └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, + │ └─TableFullScan 10000.00 cop[tikv] table:pt, partition:p0 keep order:false, stats:pseudo + └─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, + └─TableFullScan 10000.00 cop[tikv] table:pt, partition:p1 keep order:false, stats:pseudo +select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +sum(distinct b) +NULL +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +id estRows task access object operator info +HashAgg 1.00 root funcs:count(distinct Column#5)->Column#6 +└─Union 20000.00 root + ├─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +count(distinct a) +1 +explain format = 'brief' select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; +id estRows task access object operator info +HashAgg 16000.00 root group by:Column#5, funcs:firstrow(Column#6)->Column#3 +└─PartitionUnion 16000.00 root + ├─HashAgg 8000.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#6, funcs:firstrow(Column#7)->Column#5 + │ └─IndexReader 8000.00 root index:HashAgg + │ └─HashAgg 8000.00 cop[tikv] group by:date_format(planner__core__casetest__physicalplantest__physical_plan.tc.timestamp, "%Y-%m-%d %H"), + │ └─IndexFullScan 10000.00 cop[tikv] table:tc, partition:p2020072312, index:idx_timestamp(timestamp) keep order:false, stats:pseudo + └─HashAgg 8000.00 root group by:Column#10, funcs:firstrow(Column#10)->Column#6, funcs:firstrow(Column#10)->Column#5 + └─IndexReader 8000.00 root index:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:date_format(planner__core__casetest__physicalplantest__physical_plan.tc.timestamp, "%Y-%m-%d %H"), + └─IndexFullScan 10000.00 cop[tikv] table:tc, partition:p2020072313, index:idx_timestamp(timestamp) keep order:false, stats:pseudo +select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; +tt +set session sql_mode=DEFAULT; +set session tidb_hashagg_partial_concurrency=DEFAULT; +set session tidb_hashagg_final_concurrency=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +set @@session.tidb_opt_distinct_agg_push_down = DEFAULT; +set session tidb_opt_agg_push_down = DEFAULT; +drop table if exists t; +create table t (a int, b int, index idx_a(a), index idx_b(b)); +insert into t values(1, 1); +insert into t values(1, 2); +insert into t values(2, 4); +insert into t values(3, 5); +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +id estRows task access object operator info +MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b +├─IndexReader(Build) 9990.00 root index:IndexFullScan +│ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo +└─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, minus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, unaryminus(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(unaryminus(planner__core__casetest__physicalplantest__physical_plan.t.a), 3)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(1, planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, minus(1, planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(minus(1, planner__core__casetest__physicalplantest__physical_plan.t.a), 3)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(plus(1, planner__core__casetest__physicalplantest__physical_plan.t.a), 3)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Sort 12487.50 root Column#7 + └─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, mul(3, planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; +a +1 +1 +2 +drop table if exists test.tt; +create table test.tt (a int,b int, index(a), index(b)); +insert into test.tt values (1, 1), (2, 2), (3, 4); +set @@tidb_partition_prune_mode='static'; +explain format = 'brief' select /*+nth_plan(1)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.a, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select /*+nth_plan(3)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.a, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +set @@tidb_partition_prune_mode=DEFAULT; +drop table if exists t; +create table t(e enum('c','b','a',''), index idx(e)); +insert ignore into t values(0),(1),(2),(3),(4); +explain format='brief' select e from t where e = 'b'; +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:["b","b"], keep order:false, stats:pseudo +select e from t where e = 'b'; +e +b +explain format='brief' select e from t where e != 'b'; +id estRows task access object operator info +IndexReader 40.00 root index:IndexRangeScan +└─IndexRangeScan 40.00 cop[tikv] table:t, index:idx(e) range:["",""], ["c","c"], ["a","a"], ["",""], keep order:false, stats:pseudo +select e from t where e != 'b'; +e + + +a +c +explain format='brief' select e from t where e > 'b'; +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:["c","c"], keep order:false, stats:pseudo +select e from t where e > 'b'; +e +c +explain format='brief' select e from t where e >= 'b'; +id estRows task access object operator info +IndexReader 20.00 root index:IndexRangeScan +└─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], keep order:false, stats:pseudo +select e from t where e >= 'b'; +e +b +c +explain format='brief' select e from t where e < 'b'; +id estRows task access object operator info +IndexReader 30.00 root index:IndexRangeScan +└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["",""], ["a","a"], ["",""], keep order:false, stats:pseudo +select e from t where e < 'b'; +e + + +a +explain format='brief' select e from t where e <= 'b'; +id estRows task access object operator info +IndexReader 40.00 root index:IndexRangeScan +└─IndexRangeScan 40.00 cop[tikv] table:t, index:idx(e) range:["",""], ["b","b"], ["a","a"], ["",""], keep order:false, stats:pseudo +select e from t where e <= 'b'; +e + + +a +b +explain format='brief' select e from t where e = 2; +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:["b","b"], keep order:false, stats:pseudo +select e from t where e = 2; +e +b +explain format='brief' select e from t where e != 2; +id estRows task access object operator info +IndexReader 6656.67 root index:IndexRangeScan +└─IndexRangeScan 6656.67 cop[tikv] table:t, index:idx(e) range:[-inf,"b"), ("b",+inf], keep order:false, stats:pseudo +select e from t where e != 2; +e + + +a +c +explain format='brief' select e from t where e > 2; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:("b",+inf], keep order:false, stats:pseudo +select e from t where e > 2; +e + +a +explain format='brief' select e from t where e >= 2; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:["b",+inf], keep order:false, stats:pseudo +select e from t where e >= 2; +e + +a +b +explain format='brief' select e from t where e < 2; +id estRows task access object operator info +IndexReader 3323.33 root index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t, index:idx(e) range:[-inf,"b"), keep order:false, stats:pseudo +select e from t where e < 2; +e + +c +explain format='brief' select e from t where e <= 2; +id estRows task access object operator info +IndexReader 3323.33 root index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t, index:idx(e) range:[-inf,"b"], keep order:false, stats:pseudo +select e from t where e <= 2; +e + +b +c +explain format='brief' select e from t where e > ''; +id estRows task access object operator info +IndexReader 30.00 root index:IndexRangeScan +└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], ["a","a"], keep order:false, stats:pseudo +select e from t where e > ''; +e +a +b +c +explain format='brief' select e from t where e > 'd'; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select e from t where e > 'd'; +e +explain format='brief' select e from t where e > -1; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:["",+inf], keep order:false, stats:pseudo +select e from t where e > -1; +e + + +a +b +c +explain format='brief' select e from t where e > 5; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:("",+inf], keep order:false, stats:pseudo +select e from t where e > 5; +e +explain format='brief' select e from t where e = ''; +id estRows task access object operator info +IndexReader 20.00 root index:IndexRangeScan +└─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:["",""], ["",""], keep order:false, stats:pseudo +select e from t where e = ''; +e + + +explain format='brief' select e from t where e != ''; +id estRows task access object operator info +IndexReader 30.00 root index:IndexRangeScan +└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], ["a","a"], keep order:false, stats:pseudo +select e from t where e != ''; +e +a +b +c +drop table if exists PK_S_MULTI_31; +CREATE TABLE `PK_S_MULTI_31` ( +`COL1` tinyint(45) NOT NULL, +`COL2` tinyint(45) NOT NULL, +PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into PK_S_MULTI_31 values(122,100),(124,-22),(124,34),(127,103); +explain format='brief' SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; +id estRows task access object operator info +Sort 0.80 root planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2 +└─Projection 0.80 root planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2 + └─Selection 0.80 root gt(Column#7, 2) + └─HashAgg 1.00 root group by:planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1, planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2)->planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2, funcs:count(distinct planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1, planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2)->Column#7 + └─HashJoin 100000000.00 root CARTESIAN left outer join, other cond:gt(planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1, planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1) + ├─IndexReader(Build) 10000.00 root index:IndexFullScan + │ └─IndexFullScan 10000.00 cop[tikv] table:T2, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:T1, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo +SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; +col2 +100 +drop table if exists t1, t2; +create table t1(a int, b int as (a+1) virtual); +create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a)); +## Make sure row_count(tikv_selection) == row_count(table_reader) and row_count(table_reader) > row_count(tidb_selection) +explain format='brief' select * from t1 where a > 1 and b > 1; +id estRows task access object operator info +Selection 1111.11 root gt(planner__core__casetest__physicalplantest__physical_plan.t1.b, 1) +└─TableReader 3333.33 root data:Selection + └─Selection 3333.33 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, 1) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +## Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) +explain format='brief' select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1; +id estRows task access object operator info +Selection 370.37 root gt(planner__core__casetest__physicalplantest__physical_plan.t2.b, 1) +└─IndexLookUp 1111.11 root + ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t2, index:idx_a(a) range:(1,+inf], keep order:false, stats:pseudo + └─Selection(Probe) 1111.11 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.t2.c, 1) + └─TableRowIDScan 3333.33 cop[tikv] table:t2 keep order:false, stats:pseudo +drop table if exists t; +create table t(a int); +explain format='brief' select * from t where t.a < 3 and t.a < 3; +id estRows task access object operator info +TableReader 3323.33 root data:Selection +└─Selection 3323.33 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.t.a, 3) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11), `b` int(11), `c` int(11), `d` date); +insert into t (a,b,c,d) value(1,4,5,'2019-06-01'); +insert into t (a,b,c,d) value(2,null,1,'2019-07-01'); +insert into t (a,b,c,d) value(3,4,5,'2019-08-01'); +insert into t (a,b,c,d) value(3,6,2,'2019-09-01'); +insert into t (a,b,c,d) value(10,4,null,'2020-06-01'); +insert into t (a,b,c,d) value(20,null,1,'2020-07-01'); +insert into t (a,b,c,d) value(30,4,5,'2020-08-01'); +insert into t (a,b,c,d) value(30,6,5,'2020-09-01'); +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +df sum(a) count(b) count(distinct c) +2019 9 3 3 +2020 90 3 2 +set @@tidb_opt_skew_distinct_agg=1; +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +df sum(a) count(b) count(distinct c) +2019 9 3 3 +2020 90 3 2 +select count(distinct b), sum(c) from t group by a order by 1,2; +count(distinct b) sum(c) +0 1 +0 1 +1 NULL +1 5 +2 7 +2 10 +select count(distinct b) from t group by date_format(d,'%Y') order by 1; +count(distinct b) +2 +2 +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y') order by 1,2,3; +count(a) count(distinct b) max(b) +4 2 6 +4 2 6 +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +count(a) count(distinct b) max(b) +1 0 NULL +1 0 NULL +1 1 4 +1 1 6 +2 1 4 +2 2 6 +select avg(distinct b), count(a), sum(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +avg(distinct b) count(a) sum(b) +NULL 1 NULL +NULL 1 NULL +4.0000 1 4 +4.0000 2 8 +5.0000 2 10 +6.0000 1 6 +explain format='brief' select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y'); +id estRows task access object operator info +Projection 8000.00 root date_format(planner__core__casetest__physicalplantest__physical_plan.t.d, %Y)->Column#9, Column#6, cast(Column#13, bigint(21) BINARY)->Column#7, Column#8 +└─HashAgg 8000.00 root group by:Column#23, funcs:sum(Column#19)->Column#6, funcs:sum(Column#20)->Column#13, funcs:count(Column#21)->Column#8, funcs:firstrow(Column#22)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─Projection 8000.00 root Column#11->Column#19, cast(Column#12, decimal(20,0) BINARY)->Column#20, planner__core__casetest__physicalplantest__physical_plan.t.c->Column#21, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#22, date_format(planner__core__casetest__physicalplantest__physical_plan.t.d, %Y)->Column#23 + └─HashAgg 8000.00 root group by:Column#14, planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:sum(Column#15)->Column#11, funcs:count(Column#16)->Column#12, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.c)->planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:firstrow(Column#18)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:date_format(planner__core__casetest__physicalplantest__physical_plan.t.d, "%Y"), planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#15, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#16, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.d)->Column#18 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format='brief' select d, a, count(*), count(b), count(distinct c) from t group by d, a; +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t.d, planner__core__casetest__physicalplantest__physical_plan.t.a, cast(Column#10, bigint(21) BINARY)->Column#6, cast(Column#12, bigint(21) BINARY)->Column#7, Column#8 +└─HashAgg 8000.00 root group by:Column#21, Column#22, funcs:sum(Column#18)->Column#10, funcs:sum(Column#19)->Column#12, funcs:count(Column#20)->Column#8, funcs:firstrow(Column#21)->planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:firstrow(Column#22)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─Projection 8000.00 root cast(Column#9, decimal(20,0) BINARY)->Column#18, cast(Column#11, decimal(20,0) BINARY)->Column#19, planner__core__casetest__physicalplantest__physical_plan.t.c->Column#20, planner__core__casetest__physicalplantest__physical_plan.t.a->Column#21, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#22 + └─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:count(Column#13)->Column#9, funcs:count(Column#14)->Column#11, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.c)->planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.a)->planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.d)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:count(1)->Column#13, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#14 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format='brief' select d, sum(a), count(b), avg(distinct c) from t group by d; +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t.d, Column#6, cast(Column#11, bigint(21) BINARY)->Column#7, Column#8 +└─HashAgg 8000.00 root group by:Column#19, funcs:sum(Column#16)->Column#6, funcs:sum(Column#17)->Column#11, funcs:avg(Column#18)->Column#8, funcs:firstrow(Column#19)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─Projection 8000.00 root Column#9->Column#16, cast(Column#10, decimal(20,0) BINARY)->Column#17, cast(planner__core__casetest__physicalplantest__physical_plan.t.c, decimal(10,0) BINARY)->Column#18, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#19 + └─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:sum(Column#12)->Column#9, funcs:count(Column#13)->Column#10, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.c)->planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.d)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#12, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#13 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_cost_model_version=DEFAULT; +set @@tidb_opt_skew_distinct_agg=DEFAULT; +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +create table t3(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (t2) in optimizer hint /*+ HASH_JOIN_PROBE(t2, t2) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (t1) in optimizer hint /*+ HASH_JOIN_BUILD(t1, t1) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (tt) in optimizer hint /*+ HASH_JOIN_PROBE(tt) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (tt) in optimizer hint /*+ HASH_JOIN_BUILD(tt) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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:tt keep order:false, stats:pseudo +select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +Projection 15625.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a +└─HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo + └─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) eq(planner__core__casetest__physicalplantest__physical_plan.t2.b, planner__core__casetest__physicalplantest__physical_plan.t1.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +Projection 15625.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a +└─HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo + └─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) eq(planner__core__casetest__physicalplantest__physical_plan.t2.b, planner__core__casetest__physicalplantest__physical_plan.t1.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 +select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.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 +select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─StreamAgg(Build) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a +│ └─TableReader 8000.00 root data:StreamAgg +│ └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─StreamAgg(Probe) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a + └─TableReader 8000.00 root data:StreamAgg + └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─StreamAgg(Probe) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a + └─TableReader 8000.00 root data:StreamAgg + └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─StreamAgg(Build) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a +│ └─TableReader 8000.00 root data:StreamAgg +│ └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 12500.00 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 12500.00 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +set tidb_cost_model_version=DEFAULT; +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int, b int) partition by hash(a) partitions 4; +create table t2(a int, b int) partition by hash(a) partitions 5; +create table t3(a int, b int) partition by hash(b) partitions 3; +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +set @@tidb_partition_prune_mode="static"; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 49900.05 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 39920.04 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 39920.04 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 49900.05 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 39920.04 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 49900.05 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 49900.05 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 39920.04 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3, ta, tb, tc, td; +create table t1(a int, b int); +create table t2(a int primary key, b int); +create table t3(a int, b int); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +create table ta(id int, code int, name varchar(20), index idx_ta_id(id),index idx_ta_name(name), index idx_ta_code(code)); +create table tb(id int, code int, name varchar(20), index idx_tb_id(id),index idx_tb_name(name)); +create table tc(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +create table td(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +explain format = 'brief' select /*+ no_decorrelate() */ * from t1; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ no_decorrelate() */ * from t1; +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery. +explain format = 'brief' select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +id estRows task access object operator info +HashJoin 100000000.00 root CARTESIAN inner join +├─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 +select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +a b a b +1 1 1 1 +1 1 2 1 +2 2 1 1 +2 2 2 1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery. +explain format = 'brief' select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +id estRows task access object operator info +Projection 10000.00 root plus(planner__core__casetest__physicalplantest__physical_plan.t1.a, 1)->Column#4, minus(planner__core__casetest__physicalplantest__physical_plan.t1.b, 1)->Column#5 +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +a+1 b-1 +2 0 +3 1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery. +explain format = 'brief' select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +id estRows task access object operator info +HashJoin 10000.00 root left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t3.a, planner__core__casetest__physicalplantest__physical_plan.t1.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +exists (select /*+ semi_join_rewrite(), no_decorrelate() * from t1 where t1.a=t3.a) +1 +1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() and SEMI_JOIN_REWRITE() are in conflict. Both will be ineffective. +explain format = 'brief' select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +HashJoin 7984.01 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 9990.00 root data:Selection +│ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +└─TableReader(Probe) 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +Projection 9990.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a +└─Apply 9990.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 99800.10 root data:Selection + └─Selection 99800.10 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + └─TableRangeScan 9990.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a +└─Selection 8000.00 root Column#6 + └─HashJoin 10000.00 root left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.a)], other cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.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 +select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a +└─Selection 8000.00 root Column#6 + └─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b) + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, and(or(or(gt(Column#9, 1), ne(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8)), if(ne(Column#10, 0), , 0)), and(ne(Column#11, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 1)))->Column#12 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#14)->Column#8, funcs:count(distinct Column#15)->Column#9, funcs:sum(Column#16)->Column#10, funcs:count(1)->Column#11 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#14, planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#15, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#16 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +a t1.a != any (select t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, and(or(or(gt(Column#9, 1), ne(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8)), if(ne(Column#10, 0), , 0)), and(ne(Column#11, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 1)))->Column#12 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#14)->Column#8, funcs:count(distinct Column#15)->Column#9, funcs:sum(Column#16)->Column#10, funcs:count(1)->Column#11 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#14, planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#15, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#16 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +a t1.a != any (select /*+ no_decorrelate() t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, or(and(gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 0)))->Column#11 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#19)->Column#8, funcs:sum(Column#20)->Column#9, funcs:count(1)->Column#10 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#19, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#20 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +a t1.a > all (select t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, or(and(gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 0)))->Column#11 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#19)->Column#8, funcs:sum(Column#20)->Column#9, funcs:count(1)->Column#10 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#19, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#20 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +a t1.a > all (select /*+ no_decorrelate() t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─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 +select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +a (select t2.b from t2 where t2.a = t1.b) +1 1 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b +└─Apply 10000.00 root CARTESIAN left outer join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─MaxOneRow(Probe) 10000.00 root + └─TableReader 2000.00 root data:TableRangeScan + └─TableRangeScan 2000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +a (select /*+ no_decorrelate() t2.b from t2 where t2.a = t1.b) +1 1 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.b not in (select t3.b from t3) from t1; +id estRows task access object operator info +HashJoin 10000.00 root Null-aware anti left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a, t1.b not in (select t3.b from t3) from t1; +a t1.b not in (select t3.b from t3) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +id estRows task access object operator info +HashJoin 10000.00 root Null-aware anti left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +a t1.b not in (select /*+ no_decorrelate() t3.b from t3) +1 0 +2 1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because there are no correlated columns. +explain format = 'brief' select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +id estRows task access object operator info +HashJoin 10000.00 root left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +exists (select t3.b from t3 where t3.a = t1.b limit 2) +1 +1 +show warnings; +Level Code Message +explain format = 'brief' select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +id estRows task access object operator info +Projection 10000.00 root Column#10 +└─Apply 10000.00 root CARTESIAN left outer semi join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─Limit(Probe) 20000.00 root offset:0, count:2 + └─TableReader 20000.00 root data:Limit + └─Limit 20000.00 cop[tikv] offset:0, count:2 + └─Selection 20000.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t3.a, planner__core__casetest__physicalplantest__physical_plan.t1.b) + └─TableFullScan 20000000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +exists (select /*+ no_decorrelate() t3.b from t3 where t3.a = t1.b limit 2) +1 +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +id estRows task access object operator info +Projection 1.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#6->Column#11 +└─HashJoin 1.00 root CARTESIAN left outer join + ├─Point_Get(Build) 1.00 root table:t2 handle:10 + └─HashAgg(Probe) 1.00 root funcs:sum(Column#13)->Column#6, funcs:firstrow(Column#14)->planner__core__casetest__physicalplantest__physical_plan.t1.a + └─TableReader 1.00 root data:HashAgg + └─HashAgg 1.00 cop[tikv] funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t1.a)->Column#13, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t1.a)->Column#14 + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +a (select sum(t1.a) from t2 where t2.a = 10) +1 3 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +id estRows task access object operator info +Projection 1.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#9->Column#11 +└─Apply 1.00 root CARTESIAN left outer join + ├─HashAgg(Build) 1.00 root funcs:sum(Column#14)->Column#6, funcs:firstrow(Column#15)->planner__core__casetest__physicalplantest__physical_plan.t1.a + │ └─Projection 10000.00 root cast(planner__core__casetest__physicalplantest__physical_plan.t1.a, decimal(10,0) BINARY)->Column#14, planner__core__casetest__physicalplantest__physical_plan.t1.a->Column#15 + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─MaxOneRow(Probe) 1.00 root + └─Projection 1.00 root Column#6->Column#9 + └─Point_Get 1.00 root table:t2 handle:10 +select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +a (select /*+ no_decorrelate() sum(t1.a) from t2 where t2.a = 10) +1 NULL +show warnings; +Level Code Message +explain format = 'brief' select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root ifnull(Column#10, 0)->Column#10 +└─HashJoin 10000.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.b)] + ├─HashAgg(Build) 7992.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t3.b, funcs:count(Column#11)->Column#10, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t3.b)->planner__core__casetest__physicalplantest__physical_plan.t3.b + │ └─TableReader 7992.00 root data:HashAgg + │ └─HashAgg 7992.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t3.b, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t3.a)->Column#11 + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t3.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +(select count(t3.a) from t3 where t3.b = t1.b) +0 +2 +show warnings; +Level Code Message +explain format = 'brief' select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root Column#10 +└─Apply 10000.00 root CARTESIAN left outer join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─MaxOneRow(Probe) 10000.00 root + └─StreamAgg 10000.00 root funcs:count(Column#12)->Column#10 + └─TableReader 10000.00 root data:StreamAgg + └─StreamAgg 10000.00 cop[tikv] funcs:count(planner__core__casetest__physicalplantest__physical_plan.t3.a)->Column#12 + └─Selection 100000.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t3.b, planner__core__casetest__physicalplantest__physical_plan.t1.b) + └─TableFullScan 100000000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +(select /*+ no_decorrelate() count(t3.a) from t3 where t3.b = t1.b) +0 +2 +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +HashJoin 250.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] +├─IndexLookUp(Build) 250.00 root +│ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) +│ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo +│ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo +└─HashAgg(Probe) 7992.00 root group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:sum(Column#26)->Column#13, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tb.id)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─TableReader 7992.00 root data:HashAgg + └─HashAgg 7992.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:sum(planner__core__casetest__physicalplantest__physical_plan.tb.code)->Column#26 + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)) + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +Projection 250.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name, Column#13 +└─Apply 250.00 root CARTESIAN left outer join + ├─IndexLookUp(Build) 250.00 root + │ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) + │ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─MaxOneRow(Probe) 250.00 root + └─StreamAgg 250.00 root funcs:sum(Column#21)->Column#13 + └─Projection 2500.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#21 + └─IndexLookUp 2500.00 root + ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +HashJoin 250.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] +├─IndexLookUp(Build) 250.00 root +│ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) +│ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo +│ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo +└─HashAgg(Probe) 6387.21 root group by:Column#38, funcs:sum(Column#37)->Column#18, funcs:firstrow(Column#38)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─Projection 7984.01 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#37, planner__core__casetest__physicalplantest__physical_plan.tb.id->Column#38 + └─HashJoin 7984.01 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)] + ├─TableReader(Build) 7992.00 root data:Selection + │ └─Selection 7992.00 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.name)) + │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo + └─TableReader(Probe) 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.name)) + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +Projection 250.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name, Column#18 +└─Apply 250.00 root CARTESIAN left outer join + ├─IndexLookUp(Build) 250.00 root + │ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) + │ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─MaxOneRow(Probe) 250.00 root + └─StreamAgg 250.00 root funcs:sum(Column#33)->Column#18 + └─Projection 1998.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#33 + └─IndexHashJoin 1998.00 root semi join, inner:IndexLookUp, outer key:planner__core__casetest__physicalplantest__physical_plan.tb.name, inner key:planner__core__casetest__physicalplantest__physical_plan.tc.name, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name) + ├─IndexLookUp(Build) 2497.50 root + │ ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + │ └─Selection(Probe) 2497.50 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.name)) + │ └─TableRowIDScan 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─IndexLookUp(Probe) 3121.87 root + ├─Selection(Build) 3902.34 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.name)) + │ └─IndexRangeScan 3906.25 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tc.name, planner__core__casetest__physicalplantest__physical_plan.tb.name)], keep order:false, stats:pseudo + └─Selection(Probe) 3121.87 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92) + └─TableRowIDScan 3902.34 cop[tikv] table:tc keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +HashJoin 250.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] +├─IndexLookUp(Build) 250.00 root +│ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) +│ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo +│ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo +└─HashAgg(Probe) 7992.00 root group by:Column#27, funcs:sum(Column#26)->Column#18, funcs:firstrow(Column#27)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─Projection 9990.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#26, planner__core__casetest__physicalplantest__physical_plan.tb.id->Column#27 + └─Apply 9990.00 root CARTESIAN semi join + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)) + │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─IndexLookUp(Probe) 79920.00 root + ├─IndexRangeScan(Build) 99900.00 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)], keep order:false, stats:pseudo + └─Selection(Probe) 79920.00 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92) + └─TableRowIDScan 99900.00 cop[tikv] table:tc keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +Projection 250.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name, Column#18 +└─Apply 250.00 root CARTESIAN left outer join + ├─IndexLookUp(Build) 250.00 root + │ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) + │ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 250.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─MaxOneRow(Probe) 250.00 root + └─StreamAgg 250.00 root funcs:sum(Column#22)->Column#18 + └─Projection 2500.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#22 + └─Apply 2500.00 root CARTESIAN semi join + ├─IndexLookUp(Build) 2500.00 root + │ ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─IndexLookUp(Probe) 20000.00 root + ├─IndexRangeScan(Build) 25000.00 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)], keep order:false, stats:pseudo + └─Selection(Probe) 20000.00 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92) + └─TableRowIDScan 25000.00 cop[tikv] table:tc keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +id estRows task access object operator info +Projection 9.99 root planner__core__casetest__physicalplantest__physical_plan.ta.id, split->Column#10 +└─IndexHashJoin 9.99 root inner join, inner:Selection, outer key:planner__core__casetest__physicalplantest__physical_plan.ta.id, inner key:planner__core__casetest__physicalplantest__physical_plan.tb.id, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id) + ├─IndexLookUp(Build) 9.99 root + │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad999"], keep order:false, stats:pseudo + │ └─Selection(Probe) 9.99 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.id)) + │ └─TableRowIDScan 10.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─Selection(Probe) 63872.06 root gt(Column#9, 900) + └─HashAgg 79840.08 root group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:max(Column#13)->Column#9, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tb.id)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─IndexLookUp 79840.08 root + ├─Selection(Build) 9.99 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)) + │ └─IndexRangeScan 10.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tb.id, planner__core__casetest__physicalplantest__physical_plan.ta.id)], keep order:false, stats:pseudo + └─HashAgg(Probe) 79840.08 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:max(planner__core__casetest__physicalplantest__physical_plan.tb.code)->Column#13 + └─TableRowIDScan 9.99 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +id flag +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +id estRows task access object operator info +Projection 10.00 root planner__core__casetest__physicalplantest__physical_plan.ta.id, split->Column#10 +└─Apply 10.00 root CARTESIAN inner join + ├─IndexLookUp(Build) 10.00 root + │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad999"], keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 10.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─Selection(Probe) 8.00 root gt(Column#9, 900) + └─MaxOneRow 10.00 root + └─StreamAgg 10.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tb.code)->Column#9 + └─TopN 10.00 root planner__core__casetest__physicalplantest__physical_plan.tb.code:desc, offset:0, count:1 + └─IndexLookUp 10.00 root + ├─IndexRangeScan(Build) 100.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + └─TopN(Probe) 10.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tb.code:desc, offset:0, count:1 + └─Selection 99.90 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.code)) + └─TableRowIDScan 100.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +id flag +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +id estRows task access object operator info +HashJoin 159.84 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.td.id)] +├─Selection(Build) 159.84 root gt(Column#19, 100) +│ └─HashAgg 199.80 root group by:planner__core__casetest__physicalplantest__physical_plan.td.id, funcs:max(Column#51)->Column#19, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.td.id)->planner__core__casetest__physicalplantest__physical_plan.td.id +│ └─TableReader 199.80 root data:HashAgg +│ └─HashAgg 199.80 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.td.id, funcs:max(planner__core__casetest__physicalplantest__physical_plan.td.id)->Column#51 +│ └─Selection 249.75 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.td.name, "chad999%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.td.id)) +│ └─TableFullScan 10000.00 cop[tikv] table:td keep order:false, stats:pseudo +└─HashJoin(Probe) 200.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)] + ├─Selection(Build) 160.00 root gt(Column#14, 100) + │ └─HashAgg 200.00 root group by:planner__core__casetest__physicalplantest__physical_plan.tc.name, funcs:max(Column#46)->Column#14, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tc.name)->planner__core__casetest__physicalplantest__physical_plan.tc.name + │ └─IndexLookUp 200.00 root + │ ├─Selection(Build) 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tc.name, "chad99%", 92) + │ │ └─IndexRangeScan 250.00 cop[tikv] table:tc, index:idx_tc_name(name) range:["chad99","chad9:"), keep order:false, stats:pseudo + │ └─HashAgg(Probe) 200.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.tc.name, funcs:max(planner__core__casetest__physicalplantest__physical_plan.tc.id)->Column#46 + │ └─TableRowIDScan 250.00 cop[tikv] table:tc keep order:false, stats:pseudo + └─HashJoin(Probe) 7976.02 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.code, planner__core__casetest__physicalplantest__physical_plan.tb.code)] + ├─TableReader(Build) 249.75 root data:Selection + │ └─Selection 249.75 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tb.name, "chad9%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.code)) + │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─TableReader(Probe) 9970.03 root data:Selection + └─Selection 9970.03 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.code)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.id)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.name)) + └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo +SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +NAME +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +id estRows task access object operator info +Projection 249.75 root planner__core__casetest__physicalplantest__physical_plan.ta.name +└─Apply 249.75 root CARTESIAN inner join + ├─Apply(Build) 249.75 root CARTESIAN inner join + │ ├─IndexHashJoin(Build) 249.75 root inner join, inner:IndexLookUp, outer key:planner__core__casetest__physicalplantest__physical_plan.tb.code, inner key:planner__core__casetest__physicalplantest__physical_plan.ta.code, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.tb.code, planner__core__casetest__physicalplantest__physical_plan.ta.code) + │ │ ├─HashAgg(Build) 199.80 root group by:planner__core__casetest__physicalplantest__physical_plan.tb.code, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tb.code)->planner__core__casetest__physicalplantest__physical_plan.tb.code + │ │ │ └─TableReader 249.75 root data:Selection + │ │ │ └─Selection 249.75 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tb.name, "chad9%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.code)) + │ │ │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo + │ │ └─IndexLookUp(Probe) 249.75 root + │ │ ├─Selection(Build) 249.75 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.code)) + │ │ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_code(code) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.code, planner__core__casetest__physicalplantest__physical_plan.tb.code)], keep order:false, stats:pseudo + │ │ └─TableRowIDScan(Probe) 249.75 cop[tikv] table:ta keep order:false, stats:pseudo + │ └─Selection(Probe) 199.80 root gt(Column#14, 100) + │ └─MaxOneRow 249.75 root + │ └─StreamAgg 249.75 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tc.id)->Column#14 + │ └─TopN 62.38 root planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─IndexLookUp 62.38 root + │ ├─Selection(Build) 62.38 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.name, planner__core__casetest__physicalplantest__physical_plan.tc.name), like(planner__core__casetest__physicalplantest__physical_plan.tc.name, "chad99%", 92) + │ │ └─IndexRangeScan 62437.50 cop[tikv] table:tc, index:idx_tc_name(name) range:["chad99","chad9:"), keep order:false, stats:pseudo + │ └─TopN(Probe) 62.38 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─Selection 62.38 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.id)) + │ └─TableRowIDScan 62.38 cop[tikv] table:tc keep order:false, stats:pseudo + └─Selection(Probe) 199.80 root gt(Column#19, 100) + └─MaxOneRow 249.75 root + └─StreamAgg 249.75 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.td.id)->Column#19 + └─TopN 62.38 root planner__core__casetest__physicalplantest__physical_plan.td.id:desc, offset:0, count:1 + └─IndexLookUp 62.38 root + ├─Selection(Build) 1560.94 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.td.name, "chad999%", 92) + │ └─IndexRangeScan 62437.50 cop[tikv] table:td, index:idx_tc_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo + └─TopN(Probe) 62.38 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.td.id:desc, offset:0, count:1 + └─Selection 62.38 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.td.id), not(isnull(planner__core__casetest__physicalplantest__physical_plan.td.id)) + └─TableRowIDScan 1560.94 cop[tikv] table:td keep order:false, stats:pseudo +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +NAME +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name +└─Apply 10000.00 root CARTESIAN inner join + ├─Apply(Build) 10000.00 root CARTESIAN inner join + │ ├─Apply(Build) 10000.00 root CARTESIAN semi join + │ │ ├─TableReader(Build) 10000.00 root data:TableFullScan + │ │ │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + │ │ └─IndexLookUp(Probe) 2500.00 root + │ │ ├─Selection(Build) 62500.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tb.name, "chad9%", 92) + │ │ │ └─IndexRangeScan 2500000.00 cop[tikv] table:tb, index:idx_tb_name(name) range:["chad9","chad:"), keep order:false, stats:pseudo + │ │ └─Selection(Probe) 2500.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.code, planner__core__casetest__physicalplantest__physical_plan.tb.code) + │ │ └─TableRowIDScan 62500.00 cop[tikv] table:tb keep order:false, stats:pseudo + │ └─Selection(Probe) 8000.00 root gt(Column#14, 100) + │ └─MaxOneRow 10000.00 root + │ └─StreamAgg 10000.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tc.id)->Column#14 + │ └─TopN 2497.50 root planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─IndexLookUp 2497.50 root + │ ├─Selection(Build) 2497.50 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.name, planner__core__casetest__physicalplantest__physical_plan.tc.name), like(planner__core__casetest__physicalplantest__physical_plan.tc.name, "chad99%", 92) + │ │ └─IndexRangeScan 2500000.00 cop[tikv] table:tc, index:idx_tc_name(name) range:["chad99","chad9:"), keep order:false, stats:pseudo + │ └─TopN(Probe) 2497.50 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─Selection 2497.50 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.id)) + │ └─TableRowIDScan 2497.50 cop[tikv] table:tc keep order:false, stats:pseudo + └─Selection(Probe) 8000.00 root gt(Column#19, 100) + └─MaxOneRow 10000.00 root + └─StreamAgg 10000.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.td.id)->Column#19 + └─TopN 2497.50 root planner__core__casetest__physicalplantest__physical_plan.td.id:desc, offset:0, count:1 + └─IndexLookUp 2497.50 root + ├─Selection(Build) 62500.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.td.name, "chad999%", 92) + │ └─IndexRangeScan 2500000.00 cop[tikv] table:td, index:idx_tc_name(name) range:["chad999","chad99:"), keep order:false, stats:pseudo + └─TopN(Probe) 2497.50 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.td.id:desc, offset:0, count:1 + └─Selection 2497.50 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.td.id), not(isnull(planner__core__casetest__physicalplantest__physical_plan.td.id)) + └─TableRowIDScan 62500.00 cop[tikv] table:td keep order:false, stats:pseudo +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +NAME +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +drop table if exists t, t_pick_row_id; +set tidb_cost_model_version=1; +create table t (a int(11) not null, b varchar(10) not null, c date not null, d char(1) not null, e bigint not null, f datetime not null, g bool not null, h bool ); +create table t_pick_row_id (a char(20) not null); +explain format = 'brief' select count(*) from t; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#12)->Column#10 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#12 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(1), count(3.1415), count(0), count(null) from t -- shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#18)->Column#10, funcs:count(Column#19)->Column#11, funcs:count(Column#20)->Column#12, funcs:count(Column#21)->Column#13 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#18, funcs:count(3.1415)->Column#19, funcs:count(0)->Column#20, funcs:count(NULL)->Column#21 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(*) from t where a=1; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#12)->Column#10 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#12 + └─Selection 10.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(*) from t_pick_row_id; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#5)->Column#3 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#5 + └─TableFullScan 10000.00 cop[tikv] table:t_pick_row_id keep order:false, stats:pseudo +explain format = 'brief' select t.b, t.c from (select count(*) as c from t) a, t where a.c=t.a -- shouldn't be rewritten; +id estRows task access object operator info +HashJoin 1.25 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.a, Column#10)] +├─StreamAgg(Build) 1.00 root funcs:count(Column#21)->Column#10 +│ └─TableReader 1.00 root data:StreamAgg +│ └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#21 +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t outTable where outTable.a > (select count(*) from t inn where inn.a = outTable.b) -- shouldn't be rewritten; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, planner__core__casetest__physicalplantest__physical_plan.t.e, planner__core__casetest__physicalplantest__physical_plan.t.f, planner__core__casetest__physicalplantest__physical_plan.t.g, planner__core__casetest__physicalplantest__physical_plan.t.h +└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(planner__core__casetest__physicalplantest__physical_plan.t.a, Column#19) + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:outTable keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:count(Column#21)->Column#19 + └─TableReader 10000.00 root data:StreamAgg + └─StreamAgg 10000.00 cop[tikv] funcs:count(1)->Column#21 + └─Selection 80000000.00 cop[tikv] eq(cast(planner__core__casetest__physicalplantest__physical_plan.t.a, double BINARY), cast(planner__core__casetest__physicalplantest__physical_plan.t.b, double BINARY)) + └─TableFullScan 100000000.00 cop[tikv] table:inn keep order:false, stats:pseudo +explain format = 'brief' select count(*) from t t1, t t2 where t1.a=t2.e -- shouldn't be rewritten; +id estRows task access object operator info +HashAgg 1.00 root funcs:count(1)->Column#19 +└─HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.e)] + ├─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 +explain format = 'brief' select count(distinct 1) from t -- shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(distinct 1)->Column#10 +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(1), count(a), count(b) from t -- shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#16)->Column#10, funcs:count(Column#17)->Column#11, funcs:count(Column#18)->Column#12 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#16, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#17, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#18 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select a, count(*) from t group by a -- shouldn't be rewritten; +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, Column#10 +└─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:count(1)->Column#10, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.a)->planner__core__casetest__physicalplantest__physical_plan.t.a + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select sum(a) from t -- sum shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:sum(Column#12)->Column#10 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#12 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_cost_model_version=DEFAULT; +drop table if exists t, tcommon, thash; +set tidb_cost_model_version=1; +create table t (a int, b int, c int, index idx(a, c), index idx2(b, c)); +create table tcommon (a int, b int, c int, primary key(a, c), index idx2(b, c)); +create table thash(a int, b int, c int, index idx_ac(a, c), index idx_bc(b, c)) PARTITION BY HASH (`a`) PARTITIONS 4; +explain format = 'brief' select * from t where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where a = 1 or b in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 39.97 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where a in (1, 2, 3) or b = 1 order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 39.97 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where a in (1, 2, 3) or b in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 59.91 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b = 1) order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 0.02 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 0.02 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:true, stats:pseudo + ├─Limit(Build) 1.98 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.98 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 and c = 2) or b in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 30.10 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b in (1, 2, 3) and c = 3) order by c limit 2; +id estRows task access object operator info +TopN 0.40 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 0.40 root type: union + ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 0.30 cop[tikv] table:t, index:idx2(b, c) range:[1 3,1 3], [2 3,2 3], [3 3,3 3], keep order:false, stats:pseudo + └─TopN(Probe) 0.40 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 0.40 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 or b = 2) and c = 3 order by c limit 2; +id estRows task access object operator info +TopN 0.02 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 0.02 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo + └─TopN(Probe) 0.02 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─Selection 0.02 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.c, 3) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 0.06 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 0.06 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo + └─TopN(Probe) 0.06 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─Selection 0.06 cop[tikv] in(planner__core__casetest__physicalplantest__physical_plan.t.c, 1, 2, 3) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by b limit 2; +id estRows task access object operator info +TopN 0.06 root planner__core__casetest__physicalplantest__physical_plan.t.b, offset:0, count:2 +└─IndexMerge 0.06 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo + └─TopN(Probe) 0.06 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.b, offset:0, count:2 + └─Selection 0.06 cop[tikv] in(planner__core__casetest__physicalplantest__physical_plan.t.c, 1, 2, 3) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from tcommon where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.tcommon.a, planner__core__casetest__physicalplantest__physical_plan.tcommon.b, planner__core__casetest__physicalplantest__physical_plan.tcommon.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:tcommon, index:PRIMARY(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:tcommon, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:tcommon keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from tcommon where (a = 1 and c = 2) or (b = 1) order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.tcommon.a, planner__core__casetest__physicalplantest__physical_plan.tcommon.b, planner__core__casetest__physicalplantest__physical_plan.tcommon.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 0.18 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 0.18 cop[tikv] table:tcommon, index:PRIMARY(a, c) range:[1 2,1 2], keep order:true, stats:pseudo + ├─Limit(Build) 1.82 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.82 cop[tikv] table:tcommon, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:tcommon keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from thash use index(idx_ac, idx_bc) where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.thash.a, planner__core__casetest__physicalplantest__physical_plan.thash.b, planner__core__casetest__physicalplantest__physical_plan.thash.c +└─IndexMerge 2.00 root partition:all type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:thash, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:thash, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash keep order:false, stats:pseudo +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +drop table if exists t, t2, t3; +set tidb_cost_model_version=1; +CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ; +insert into t2 values(1,2,1),(2,1,1),(3,3,1); +create table t(a int, j json, index kj((cast(j as signed array)))); +insert into t values(1, '[1,2,3]'); +CREATE TABLE `t3` ( +`id` int(11) NOT NULL, +`aid` bigint(20) DEFAULT NULL, +`c1` varchar(255) DEFAULT NULL, +`c2` varchar(255) DEFAULT NULL, +`d` int(11) DEFAULT NULL, +PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, +KEY `aid_c1` (`aid`,`c1`), +KEY `aid_c2` (`aid`,`c2`) +); +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; +id estRows task access object operator info +Limit 2.00 root offset:0, count:2 +└─IndexMerge 0.00 root type: union + ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo + └─Limit(Probe) 0.00 cop[tikv] offset:0, count:2 + └─Selection 0.00 cop[tikv] or(eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, 1), and(eq(planner__core__casetest__physicalplantest__physical_plan.t2.b, 1), eq(planner__core__casetest__physicalplantest__physical_plan.t2.c, 1))) + └─TableRowIDScan 3.99 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; +id estRows task access object operator info +Limit 0.00 root offset:0, count:2 +└─IndexMerge 0.01 root type: intersection + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo + └─Limit(Probe) 0.01 cop[tikv] offset:0, count:2 + └─Selection 0.01 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t2.c, 1) + └─TableRowIDScan 0.01 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; +a b c +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; +id estRows task access object operator info +IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) +├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 +│ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo +├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 +│ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 2.00 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; +id estRows task access object operator info +IndexMerge 0.01 root type: intersection, limit embedded(offset:0, count:2) +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.01 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; +a b c +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; +id estRows task access object operator info +IndexMerge 1.00 root type: union, limit embedded(offset:0, count:1) +├─Limit(Build) 1.00 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; +id estRows task access object operator info +IndexMerge 0.00 root type: intersection, limit embedded(offset:0, count:1) +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Selection 1.00 root json_overlaps(planner__core__casetest__physicalplantest__physical_plan.t.j, cast("[1, 2, 3]", json BINARY)) + └─IndexMerge 1.00 root type: union + ├─IndexRangeScan(Build) 0.33 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 0.33 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 0.33 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 1.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now. +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; +id estRows task access object operator info +Limit 0.01 root offset:0, count:1 +└─IndexMerge 0.01 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + └─Limit(Probe) 0.01 cop[tikv] offset:0, count:1 + └─Selection 0.01 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; +id estRows task access object operator info +Limit 0.00 root offset:0, count:1 +└─IndexMerge 0.00 root type: intersection + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Limit(Probe) 0.00 cop[tikv] offset:0, count:1 + └─Selection 0.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableRowIDScan 0.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Selection 1.00 root json_overlaps(planner__core__casetest__physicalplantest__physical_plan.t.j, cast("[1, 2, 3]", json BINARY)) + └─IndexMerge 0.00 root type: union + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Selection(Probe) 0.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableRowIDScan 3.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now. +set tidb_cost_model_version=DEFAULT; +explain select /*+ USE_INDEX_MERGE(t3, aid_c1, aid_c2) */ * from t3 where (aid = 1 and c1='aaa') or (aid = 1 and c2='bbb') limit 1; +id estRows task access object operator info +IndexMerge_20 1.00 root type: union, limit embedded(offset:0, count:1) +├─Limit_18(Build) 0.01 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_11 0.01 cop[tikv] table:t3, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo +├─Limit_19(Build) 0.01 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_12 0.01 cop[tikv] table:t3, index:aid_c2(aid, c2) range:[1 "bbb",1 "bbb"], keep order:false, stats:pseudo +└─TableRowIDScan_13(Probe) 1.00 cop[tikv] table:t3 keep order:false, stats:pseudo +show warnings; +Level Code Message +CREATE TABLE `tbl_43` ( +`col_304` binary(207) NOT NULL DEFAULT 'eIenHx\0\0\0\0\0\0\0\0\0\0\0\0', +PRIMARY KEY (`col_304`) /*T![clustered_index] CLUSTERED */, +UNIQUE KEY `idx_259` (`col_304`(5)), +UNIQUE KEY `idx_260` (`col_304`(2)), +KEY `idx_261` (`col_304`), +UNIQUE KEY `idx_262` (`col_304`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +insert into tbl_43 values("BCmuENPHzSOIMJLPB"),("LDOdXZYpOR"),("R"),("TloTqcHhdgpwvMsSoJ"),("UajN"),("mAwLZbiyq"),("swLIoWa"); +explain format = 'brief' select min(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +id estRows task access object operator info +StreamAgg 1.00 root funcs:min(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304)->Column#2 +└─Limit 1.00 root offset:0, count:1 + └─IndexMerge 1.00 root type: union + ├─Selection(Build) 0.00 cop[tikv] 1 + │ └─TableRangeScan 0.00 cop[tikv] table:tbl_43 range:["LUBGzGMA","LUBGzGMA"], keep order:true, stats:pseudo + ├─IndexRangeScan(Build) 0.42 cop[tikv] table:tbl_43, index:idx_261(col_304) range:[-inf,"YEpfYfPVvhMlHGHSMKm"), keep order:true, stats:pseudo + ├─IndexRangeScan(Build) 0.42 cop[tikv] table:tbl_43, index:idx_262(col_304) range:("PE",+inf], keep order:true, stats:pseudo + ├─TableRangeScan(Build) 0.42 cop[tikv] table:tbl_43 range:[-inf,"MFWmuOsoyDv"), keep order:true, stats:pseudo + ├─TableRangeScan(Build) 0.42 cop[tikv] table:tbl_43 range:("TSeMYpDXnFIyp",+inf], keep order:true, stats:pseudo + └─Selection(Probe) 1.00 cop[tikv] or(or(lt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "YEpfYfPVvhMlHGHSMKm"), gt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "PE")), or(and(eq(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "LUBGzGMA"), 1), or(lt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "MFWmuOsoyDv"), gt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "TSeMYpDXnFIyp")))) + └─TableRowIDScan 1.25 cop[tikv] table:tbl_43 keep order:false, stats:pseudo +select min(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +min(col_304) +BCmuENPHzSOIMJLPB +explain format = 'brief' select max(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +id estRows task access object operator info +StreamAgg 1.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304)->Column#2 +└─Limit 1.00 root offset:0, count:1 + └─IndexMerge 1.00 root type: union + ├─Selection(Build) 0.00 cop[tikv] 1 + │ └─TableRangeScan 0.00 cop[tikv] table:tbl_43 range:["LUBGzGMA","LUBGzGMA"], keep order:true, desc, stats:pseudo + ├─IndexRangeScan(Build) 0.42 cop[tikv] table:tbl_43, index:idx_261(col_304) range:[-inf,"YEpfYfPVvhMlHGHSMKm"), keep order:true, desc, stats:pseudo + ├─IndexRangeScan(Build) 0.42 cop[tikv] table:tbl_43, index:idx_262(col_304) range:("PE",+inf], keep order:true, desc, stats:pseudo + ├─TableRangeScan(Build) 0.42 cop[tikv] table:tbl_43 range:[-inf,"MFWmuOsoyDv"), keep order:true, desc, stats:pseudo + ├─TableRangeScan(Build) 0.42 cop[tikv] table:tbl_43 range:("TSeMYpDXnFIyp",+inf], keep order:true, desc, stats:pseudo + └─Selection(Probe) 1.00 cop[tikv] or(or(lt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "YEpfYfPVvhMlHGHSMKm"), gt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "PE")), or(and(eq(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "LUBGzGMA"), 1), or(lt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "MFWmuOsoyDv"), gt(planner__core__casetest__physicalplantest__physical_plan.tbl_43.col_304, "TSeMYpDXnFIyp")))) + └─TableRowIDScan 1.25 cop[tikv] table:tbl_43 keep order:false, stats:pseudo +select max(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +max(col_304) +swLIoWa diff --git a/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test b/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test new file mode 100644 index 0000000000000..f9d3df51eeaa0 --- /dev/null +++ b/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test @@ -0,0 +1,1019 @@ +# TestINMJHint +drop table if exists t1, t2; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +explain format = 'brief' select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; + +# TestEliminateMaxOneRow +drop table if exists t1, t2, t3; +create table t1(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, UNIQUE KEY idx_a (a)); +create table t2(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL); +create table t3(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, c int(11) DEFAULT NULL, UNIQUE KEY idx_abc (a, b, c)); +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +explain format = 'brief' select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); +select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); + +# TestIndexJoinUnionScan +set tidb_cost_model_version=2; +drop table if exists t, tt; +create table t (a int primary key, b int, index idx(a)); +create table tt (a int primary key) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200)); +set @@tidb_partition_prune_mode='static'; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a; +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.b; +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ t1.a , t2.b from t t1, t t2 where t1.a = t2.b; +rollback; +begin; +insert into tt values(1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from tt t1, tt t2 where t1.a = t2.a; +rollback; +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; + +# TestMergeJoinUnionScan +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), primary key (c_int)); +create table t2 (c_int int, c_str varchar(40), primary key (c_int)); +insert into t1 (`c_int`, `c_str`) values (11, 'keen williamson'), (10, 'gracious hermann'); +insert into t2 (`c_int`, `c_str`) values (10, 'gracious hermann'); +begin; +insert into t2 values (11, 'amazing merkle'); +insert into t2 values (12, 'amazing merkle'); +explain format = 'brief' select /*+ MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_int = t2.c_int order by t1.c_int, t2.c_str; +rollback; + +# TestLimitToCopHint +set tidb_cost_model_version=2; +drop table if exists tn; +create table tn(a int, b int, c int, d int, key (a, b, c, d)); +set tidb_opt_limit_push_down_threshold=0; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +show warnings; +explain format = 'brief' select * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +show warnings; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a div 2 order by a limit 1; +show warnings; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1; +show warnings; +set tidb_cost_model_version=DEFAULT; +set tidb_opt_limit_push_down_threshold=DEFAULT; + +# TestCTEMergeHint +drop table if exists tc, te, t1, t2, t3, t4; +drop view if exists v; +create table tc(a int); +create table te(c int); +create table t1(a int); +create table t2(b int); +create table t3(c int); +create table t4(d int); +insert into tc values (1), (5), (10), (15), (20), (30), (50); +insert into te values (1), (5), (10), (25), (40), (60), (100); +insert into t1 values (1), (5), (10), (25), (40), (60), (100); +insert into t2 values (1), (5), (10), (25), (40), (60), (100); +insert into t3 values (1), (5), (10), (25), (40), (60), (100); +insert into t4 values (1), (5), (10), (25), (40), (60), (100); +analyze table tc all columns; +analyze table te all columns; +analyze table t1 all columns; +analyze table t2 all columns; +analyze table t3 all columns; +analyze table t4 all columns; +create definer='root'@'localhost' view v as select * from tc; +explain format = 'brief' with cte as (select /*+ MERGE() */ * from tc where tc.a < 60) select * from cte where cte.a <18; +show warnings; +explain format = 'brief' with cte as (select * from tc where tc.a < 60) select * from cte c1, cte c2 where c1.a <18; +show warnings; +explain format = 'brief' with cte as (select /*+ MERGE() */ * from v) select * from cte; +show warnings; +explain format = 'brief' WITH cte1 AS (SELECT /*+ MERGE() */ a FROM tc), cte2 AS (SELECT /*+ MERGE()*/ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +show warnings; +explain format = 'brief' WITH cte1 AS (SELECT a FROM tc), cte2 AS (SELECT /*+ MERGE() */ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +show warnings; +explain format = 'brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; +show warnings; +explain format = 'brief' WITH cte1 AS (SELECT * FROM t1) SELECT /*+ MERGE() */ * FROM cte1 join t2 on cte1.a = t2.b; +show warnings; +explain format = 'brief' with cte1 as (with cte3 as (select /*+ MERGE() */ * from t1),cte4 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3,cte4) ,cte2 as (select /*+ MERGE() */ * from t3) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select * from tc), cte2 as (with cte3 as (select /*+ MERGE() */ * from te) ,cte4 as (select * from tc) select * from cte3,cte4) select * from cte2; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (select /*+ MERGE() */ * from te) ,cte3 as (select /*+ MERGE() */ * from tc) select /*+ MERGE() */ * from cte2,cte3) select * from cte1; +show warnings; +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select /*+ MERGE() */ * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select /*+ MERGE() */ * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select /*+ MERGE() */ * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte2 as (with cte4 as (select * from tc) select * from te, cte4) select * from cte2; +show warnings; +explain format = 'brief' with cte2 as (with cte4 as (select /*+ merge() */ * from tc) select * from te, cte4) select * from cte2; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select /*+ MERGE() */ * from t1) ttt) select * from cte1; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select /*+ MERGE() */ * from t3) ttw; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select * from t3) ttw; +show warnings; + +# TestForceInlineCTE +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11)); +insert into t values (1), (5), (10), (15), (20), (30), (50); +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inline; +show warnings; +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline; +show warnings; +explain format='brief' with cte as (select * from t) select * from cte cte1, cte cte2; -- inline CTEs is used by multi consumers; +show warnings; +explain format='brief' with cte1 as (select * from t), cte2 as (select a from cte1 group by a) select * from cte1, cte2; -- multi inline CTEs; +show warnings; +explain format='brief' with recursive cte1(c1) as (select 1 union select c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +show warnings; +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +show warnings; +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +show warnings; +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +show warnings; +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inlined by single consumer; +show warnings; +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline, merge hint override session variable; +show warnings; +explain format='brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +show warnings; +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +show warnings; +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +show warnings; +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +show warnings; + +set tidb_cost_model_version=DEFAULT; +set tidb_opt_force_inline_cte=DEFAULT; + +# TestSingleConsumerCTE +drop table if exists t, t1, t2; +CREATE TABLE `t` (`a` int(11)); +create table t1 (c1 int primary key, c2 int, index c2 (c2)); +create table t2 (c1 int unique, c2 int); +insert into t values (1), (5), (10), (15), (20), (30), (50); +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 1) select * from cte1; -- non-recursive limit, inline cte1; +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 100 offset 100) select * from cte1; -- non-recursive limit, inline cte1; +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 0 offset 0) select * from cte1; -- non-recursive limit, inline cte1; +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union (with cte2 as (select 3) select * from cte2 union all select * from cte2) -- inline cte1, not inline cte2; +explain format='brief' with base1 as (WITH RECURSIVE cte(a) AS (with tmp as (select 1 as a) SELECT a from tmp UNION SELECT a+1 FROM cte) SELECT * FROM cte) select * from base1; -- issue #43318; +explain format='brief' with cte as (select 1) select * from cte; -- inline cte; +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union select * from cte2; -- inline cte1, cte2; +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- cannot be inlined; +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte; -- inline nested cte; +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte a, cte b; -- inline inner cte, cannot be inlined outer cte; +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte1, cte2; -- inline cte2, cte3, cannot be inlined cte1; +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte2; -- inline cte1, cte2, cte3; +explain format='brief' with cte1 as (select 1), cte2 as (select * from cte1) select * from cte2 a, cte2 b; -- inline cte1, cannot be inlined cte2; +explain format='brief' with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined; +explain format='brief' with x as (select * from (select a from t for update) s) select * from x where a = 1; +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- force inline cte while multi-consumer; +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select 1) select /*+ MERGE() */ * from cte union select * from cte; -- firstly inline cte, secondly cannot be inlined; +explain format='brief' with a as (select 8 as id from dual),maxa as (select max(id) as max_id from a),b as (with recursive temp as (select 1 as lvl from dual union all select lvl+1 from temp, maxa where lvl < max_id)select * from temp) select * from b; -- issue #47711, maxa cannot be inlined because it contains agg and in the recursive part of cte temp; +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select 1 as res from t1 union all select res+1 from tmp,b where res+1 < bb) select * from tmp) select * from c; -- inline a, cannot be inline b because b indirectly contains agg and in the recursive part of cte tmp; +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c; +create table test(a int); +explain WITH RECURSIVE CTE (x) AS (SELECT 1 UNION ALL SELECT distinct a FROM test), CTE1 AS (SELECT x FROM CTE UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain distinct and ref by CET1 recursive part cannot be inlined; +create view test_cte(a) as WITH RECURSIVE CTE (x) AS (SELECT 1 UNION ALL SELECT distinct a FROM test) , CTE1 AS (SELECT x FROM CTE UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; +explain select * from test_cte; -- CTE (inside of view) cannot be inlined by default; +create view test_inline_cte(a) as with CTE (x) as (select distinct a from test) select * from CTE; +explain select * from test_inline_cte; -- CTE (inside of view) cannot be inlined by default; +create view test_force_inline_cte(a) as with CTE (x) as (select /*+ merge() */ distinct a from test) select * from CTE; +explain select * from test_force_inline_cte; -- CTE (inside of view) can be inlined by force; +explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test limit 1) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain limit and ref by CET1 recursive part cannot be inlined; +explain WITH RECURSIVE CTE (x) AS (SELECT a FROM test order by a) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain order by and ref by CET1 recursive part cannot be inlined; + + +# TestPushdownDistinctEnableAggPushDownDisable +drop table if exists t; +create table t(a int, b int, c int, index(c)); +insert into t values (1, 1, 1), (1, 1, 3), (1, 2, 3), (2, 1, 3), (1, 2, NULL); +drop table if exists pt; +CREATE TABLE pt (a int, b int) PARTITION BY RANGE (a) ( + PARTITION p0 VALUES LESS THAN (2), + PARTITION p1 VALUES LESS THAN (100) + ); +drop table if exists tc; +CREATE TABLE `tc`(`timestamp` timestamp NULL DEFAULT NULL, KEY `idx_timestamp` (`timestamp`)) PARTITION BY RANGE ( UNIX_TIMESTAMP(`timestamp`) ) (PARTITION `p2020072312` VALUES LESS THAN (1595480400),PARTITION `p2020072313` VALUES LESS THAN (1595484000)); +drop table if exists ta; +create table ta(a int); +insert into ta values(1), (1); +drop table if exists tb; +create table tb(a int); +insert into tb values(1), (1); +set session sql_mode=''; +set session tidb_hashagg_partial_concurrency=1; +set session tidb_hashagg_final_concurrency=1; +set @@tidb_partition_prune_mode='static'; +set @@session.tidb_opt_distinct_agg_push_down = 1; +set session tidb_opt_agg_push_down = 0; +set tidb_cost_model_version=2; +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +explain format = 'brief' select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; +select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; + +set session sql_mode=DEFAULT; +set session tidb_hashagg_partial_concurrency=DEFAULT; +set session tidb_hashagg_final_concurrency=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +set @@session.tidb_opt_distinct_agg_push_down = DEFAULT; +set session tidb_opt_agg_push_down = DEFAULT; + +# TestNominalSort +drop table if exists t; +create table t (a int, b int, index idx_a(a), index idx_b(b)); +insert into t values(1, 1); +insert into t values(1, 2); +insert into t values(2, 4); +insert into t values(3, 5); +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; + +# TestNthPlanHintWithExplain +drop table if exists test.tt; +create table test.tt (a int,b int, index(a), index(b)); +insert into test.tt values (1, 1), (2, 2), (3, 4); +set @@tidb_partition_prune_mode='static'; +explain format = 'brief' select /*+nth_plan(1)*/ * from test.tt where a=1 and b=1; +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; +explain format = 'brief' select /*+nth_plan(3)*/ * from test.tt where a=1 and b=1; +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; + +## Currently, its output is the same as the second test case in the testdata, which is `/*+nth_plan(2)*/`. If this doesn't +## hold in the future, you may need to modify this. +explain format = 'brief' select * from test.tt where a=1 and b=1; + +set @@tidb_partition_prune_mode=DEFAULT; + +# TestEnumIndex +drop table if exists t; +create table t(e enum('c','b','a',''), index idx(e)); +insert ignore into t values(0),(1),(2),(3),(4); +explain format='brief' select e from t where e = 'b'; +--sorted_result +select e from t where e = 'b'; +explain format='brief' select e from t where e != 'b'; +--sorted_result +select e from t where e != 'b'; +explain format='brief' select e from t where e > 'b'; +--sorted_result +select e from t where e > 'b'; +explain format='brief' select e from t where e >= 'b'; +--sorted_result +select e from t where e >= 'b'; +explain format='brief' select e from t where e < 'b'; +--sorted_result +select e from t where e < 'b'; +explain format='brief' select e from t where e <= 'b'; +--sorted_result +select e from t where e <= 'b'; +explain format='brief' select e from t where e = 2; +--sorted_result +select e from t where e = 2; +explain format='brief' select e from t where e != 2; +--sorted_result +select e from t where e != 2; +explain format='brief' select e from t where e > 2; +--sorted_result +select e from t where e > 2; +explain format='brief' select e from t where e >= 2; +--sorted_result +select e from t where e >= 2; +explain format='brief' select e from t where e < 2; +--sorted_result +select e from t where e < 2; +explain format='brief' select e from t where e <= 2; +--sorted_result +select e from t where e <= 2; +explain format='brief' select e from t where e > ''; +--sorted_result +select e from t where e > ''; +explain format='brief' select e from t where e > 'd'; +--sorted_result +select e from t where e > 'd'; +explain format='brief' select e from t where e > -1; +--sorted_result +select e from t where e > -1; +explain format='brief' select e from t where e > 5; +--sorted_result +select e from t where e > 5; +explain format='brief' select e from t where e = ''; +--sorted_result +select e from t where e = ''; +explain format='brief' select e from t where e != ''; +--sorted_result +select e from t where e != ''; + +# TestIssue27233 +drop table if exists PK_S_MULTI_31; +CREATE TABLE `PK_S_MULTI_31` ( + `COL1` tinyint(45) NOT NULL, + `COL2` tinyint(45) NOT NULL, + PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into PK_S_MULTI_31 values(122,100),(124,-22),(124,34),(127,103); +explain format='brief' SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; +--sorted_result +SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; + +# TestSelectionPartialPushDown +drop table if exists t1, t2; +create table t1(a int, b int as (a+1) virtual); +create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a)); +-- echo ## Make sure row_count(tikv_selection) == row_count(table_reader) and row_count(table_reader) > row_count(tidb_selection) +explain format='brief' select * from t1 where a > 1 and b > 1; +-- echo ## Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) +explain format='brief' select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1; + +# TestIssue28316 +drop table if exists t; +create table t(a int); +explain format='brief' select * from t where t.a < 3 and t.a < 3; + +# TestSkewDistinctAgg +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11), `b` int(11), `c` int(11), `d` date); +insert into t (a,b,c,d) value(1,4,5,'2019-06-01'); +insert into t (a,b,c,d) value(2,null,1,'2019-07-01'); +insert into t (a,b,c,d) value(3,4,5,'2019-08-01'); +insert into t (a,b,c,d) value(3,6,2,'2019-09-01'); +insert into t (a,b,c,d) value(10,4,null,'2020-06-01'); +insert into t (a,b,c,d) value(20,null,1,'2020-07-01'); +insert into t (a,b,c,d) value(30,4,5,'2020-08-01'); +insert into t (a,b,c,d) value(30,6,5,'2020-09-01'); +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +set @@tidb_opt_skew_distinct_agg=1; +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +select count(distinct b), sum(c) from t group by a order by 1,2; +select count(distinct b) from t group by date_format(d,'%Y') order by 1; +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y') order by 1,2,3; +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +select avg(distinct b), count(a), sum(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +explain format='brief' select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y'); +explain format='brief' select d, a, count(*), count(b), count(distinct c) from t group by d, a; +explain format='brief' select d, sum(a), count(b), avg(distinct c) from t group by d; + +set tidb_cost_model_version=DEFAULT; +set @@tidb_opt_skew_distinct_agg=DEFAULT; + +# TestHJBuildAndProbeHint +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +create table t3(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; + +set tidb_cost_model_version=DEFAULT; + +# TestHJBuildAndProbeHint4StaticPartitionTable +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int, b int) partition by hash(a) partitions 4; +create table t2(a int, b int) partition by hash(a) partitions 5; +create table t3(a int, b int) partition by hash(b) partitions 3; +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +set @@tidb_partition_prune_mode="static"; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; + +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; + +# TestNoDecorrelateHint +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3, ta, tb, tc, td; +create table t1(a int, b int); +create table t2(a int primary key, b int); +create table t3(a int, b int); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +create table ta(id int, code int, name varchar(20), index idx_ta_id(id),index idx_ta_name(name), index idx_ta_code(code)); +create table tb(id int, code int, name varchar(20), index idx_tb_id(id),index idx_tb_name(name)); +create table tc(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +create table td(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +explain format = 'brief' select /*+ no_decorrelate() */ * from t1; +--sorted_result +select /*+ no_decorrelate() */ * from t1; +show warnings; +explain format = 'brief' select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +--sorted_result +select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +show warnings; +explain format = 'brief' select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +--sorted_result +select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +show warnings; +explain format = 'brief' select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +--sorted_result +select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.b not in (select t3.b from t3) from t1; +--sorted_result +select t1.a, t1.b not in (select t3.b from t3) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +--sorted_result +select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +show warnings; +explain format = 'brief' select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +--sorted_result +select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +show warnings; +explain format = 'brief' select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +--sorted_result +select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +show warnings; +explain format = 'brief' select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +--sorted_result +select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +show warnings; +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +--sorted_result +select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +show warnings; +explain format = 'brief' select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +--sorted_result +select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +show warnings; +explain format = 'brief' select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +--sorted_result +select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +--sorted_result +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +show warnings; +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +--sorted_result +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +show warnings; +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +--sorted_result +SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +show warnings; +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +--sorted_result +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +show warnings; +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +--sorted_result +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +show warnings; +set tidb_cost_model_version=DEFAULT; + +# TestCountStarForTikv +drop table if exists t, t_pick_row_id; +set tidb_cost_model_version=1; +create table t (a int(11) not null, b varchar(10) not null, c date not null, d char(1) not null, e bigint not null, f datetime not null, g bool not null, h bool ); +create table t_pick_row_id (a char(20) not null); +explain format = 'brief' select count(*) from t; +explain format = 'brief' select count(1), count(3.1415), count(0), count(null) from t -- shouldn't be rewritten; +explain format = 'brief' select count(*) from t where a=1; +explain format = 'brief' select count(*) from t_pick_row_id; +explain format = 'brief' select t.b, t.c from (select count(*) as c from t) a, t where a.c=t.a -- shouldn't be rewritten; +explain format = 'brief' select * from t outTable where outTable.a > (select count(*) from t inn where inn.a = outTable.b) -- shouldn't be rewritten; +explain format = 'brief' select count(*) from t t1, t t2 where t1.a=t2.e -- shouldn't be rewritten; +explain format = 'brief' select count(distinct 1) from t -- shouldn't be rewritten; +explain format = 'brief' select count(1), count(a), count(b) from t -- shouldn't be rewritten; +explain format = 'brief' select a, count(*) from t group by a -- shouldn't be rewritten; +explain format = 'brief' select sum(a) from t -- sum shouldn't be rewritten; +set tidb_cost_model_version=DEFAULT; + +# TestIndexMergeOrderPushDown +drop table if exists t, tcommon, thash; +set tidb_cost_model_version=1; +create table t (a int, b int, c int, index idx(a, c), index idx2(b, c)); +create table tcommon (a int, b int, c int, primary key(a, c), index idx2(b, c)); +create table thash(a int, b int, c int, index idx_ac(a, c), index idx_bc(b, c)) PARTITION BY HASH (`a`) PARTITIONS 4; +explain format = 'brief' select * from t where a = 1 or b = 1 order by c limit 2; +show warnings; +explain format = 'brief' select * from t where a = 1 or b in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where a in (1, 2, 3) or b = 1 order by c limit 2; +show warnings; +explain format = 'brief' select * from t where a in (1, 2, 3) or b in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b = 1) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 and c = 2) or b in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b in (1, 2, 3) and c = 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 or b = 2) and c = 3 order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by b limit 2; +show warnings; +explain format = 'brief' select * from tcommon where a = 1 or b = 1 order by c limit 2; +show warnings; +explain format = 'brief' select * from tcommon where (a = 1 and c = 2) or (b = 1) order by c limit 2; +show warnings; +explain format = 'brief' select * from thash use index(idx_ac, idx_bc) where a = 1 or b = 1 order by c limit 2; +show warnings; +set tidb_cost_model_version=DEFAULT; + +# TestIndexMergeSinkLimit +drop table if exists t, t2, t3; +set tidb_cost_model_version=1; +CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ; +insert into t2 values(1,2,1),(2,1,1),(3,3,1); +create table t(a int, j json, index kj((cast(j as signed array)))); +insert into t values(1, '[1,2,3]'); +CREATE TABLE `t3` ( + `id` int(11) NOT NULL, + `aid` bigint(20) DEFAULT NULL, + `c1` varchar(255) DEFAULT NULL, + `c2` varchar(255) DEFAULT NULL, + `d` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, + KEY `aid_c1` (`aid`,`c1`), + KEY `aid_c2` (`aid`,`c2`) +); +## test sink limit to table side of union index merge case, because of table side selection +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; +show warnings; +## test sink limit to table side of intersection index merge case, because of table side selection +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; +show warnings; +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; +show warnings; +## test sink limit to index side of union index merge case, because of table side is pure table scan +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; +show warnings; +## test sink limit to table side of intersection index merge case, because of intersection case special +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; +show warnings; +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; +show warnings; +## index merge union case, sink limit into index side and embed another one inside index merge reader +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; +show warnings; +## index merge intersection case, embedding limit into index merge reader +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; +show warnings; +## index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; +show warnings; +## index merge union case, sink limit to table side, because selection exists on table side +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; +show warnings; +## index merge intersection case, sink limit to table side because selection exists on table side +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; +show warnings; +## index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; +show warnings; +set tidb_cost_model_version=DEFAULT; +## index merge union and intersection case from issue 48588 +explain select /*+ USE_INDEX_MERGE(t3, aid_c1, aid_c2) */ * from t3 where (aid = 1 and c1='aaa') or (aid = 1 and c2='bbb') limit 1; +show warnings; + +# TestIndexMergeIssue52947 +CREATE TABLE `tbl_43` ( + `col_304` binary(207) NOT NULL DEFAULT 'eIenHx\0\0\0\0\0\0\0\0\0\0\0\0', + PRIMARY KEY (`col_304`) /*T![clustered_index] CLUSTERED */, + UNIQUE KEY `idx_259` (`col_304`(5)), + UNIQUE KEY `idx_260` (`col_304`(2)), + KEY `idx_261` (`col_304`), + UNIQUE KEY `idx_262` (`col_304`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +insert into tbl_43 values("BCmuENPHzSOIMJLPB"),("LDOdXZYpOR"),("R"),("TloTqcHhdgpwvMsSoJ"),("UajN"),("mAwLZbiyq"),("swLIoWa"); +explain format = 'brief' select min(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +select min(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +explain format = 'brief' select max(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x; +select max(col_304) from (select /*+ use_index_merge( tbl_43 ) */ * from tbl_43 where not( tbl_43.col_304 between 'YEpfYfPVvhMlHGHSMKm' and 'PE' ) or tbl_43.col_304 in ( 'LUBGzGMA' ) and tbl_43.col_304 between 'HpsjfuSReCwBoh' and 'fta' or not( tbl_43.col_304 between 'MFWmuOsoyDv' and 'TSeMYpDXnFIyp' ) order by col_304) x;