From 12c258ebca7b425b3c1b4d3d6232cc664d58fc1f Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 14 Jun 2023 19:21:08 +0800 Subject: [PATCH] planner: add more test cases for quick binding (#44670) ref pingcap/tidb#39199 --- executor/adapter.go | 2 +- .../clustertablestest/cluster_tables_test.go | 59 ++++++++++++++----- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index 4bd74267e384a..e2a036102e794 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -1756,7 +1756,7 @@ func getEncodedPlan(stmtCtx *stmtctx.StatementContext, genHint bool) (encodedPla // so we have to iterate all hints from the customer and keep some other necessary hints. switch tableHint.HintName.L { case "memory_quota", "use_toja", "no_index_merge", "max_execution_time", - plannercore.HintIgnoreIndex, plannercore.HintReadFromStorage, + plannercore.HintIgnoreIndex, plannercore.HintReadFromStorage, plannercore.HintMerge, plannercore.HintSemiJoinRewrite, plannercore.HintNoDecorrelate: hints = append(hints, tableHint) } diff --git a/infoschema/test/clustertablestest/cluster_tables_test.go b/infoschema/test/clustertablestest/cluster_tables_test.go index 08a1ff83825d2..64643a1a1fa34 100644 --- a/infoschema/test/clustertablestest/cluster_tables_test.go +++ b/infoschema/test/clustertablestest/cluster_tables_test.go @@ -899,19 +899,18 @@ func TestQuickBinding(t *testing.T) { expectedHint string dmlAndSubqueryTemplates []string } - //defaultDMLAndSubqueryTemplates := []string{ - // //"select a from (%v) tx where tx.a<1", // TODO: support sub query - // "insert into t1 %v", - // // TODO: more templates - //} + subQueryTemp := []string{ + "select a from (?) tx where tx.c<100", + "select * from (?) tx1, (?) tx2 where tx1.c<100 and tx2.c<100", + } testCases := []testCase{ // access path selection with use_index / ignore_index - {`select /*+ use_index(t1, k_a) */ * from t1 where b=?`, "use_index(@`sel_1` `test`.`t1` `k_a`), no_order_index(@`sel_1` `test`.`t1` `k_a`)", nil}, - {`select /*+ use_index(t1, k_bc) */ * from t1 where a=?`, "use_index(@`sel_1` `test`.`t1` `k_bc`), no_order_index(@`sel_1` `test`.`t1` `k_bc`)", nil}, - {`select /*+ use_index(t1, primary) */ * from t1 where a=? and b=?`, "use_index(@`sel_1` `test`.`t1` ), no_order_index(@`sel_1` `test`.`t1` `primary`)", nil}, - {`select /*+ ignore_index(t1, k_a, k_bc) */ * from t1 where a=? and b=?`, "use_index(@`sel_1` `test`.`t1` ), no_order_index(@`sel_1` `test`.`t1` `primary`), ignore_index(`t1` `k_a`, `k_bc`)", nil}, - {`select /*+ use_index(t1) */ * from t1 where a=? and b=?`, "use_index(@`sel_1` `test`.`t1` ), no_order_index(@`sel_1` `test`.`t1` `primary`)", nil}, - {`select /*+ use_index(t2) */ * from t2 where a=? and b=?`, "use_index(@`sel_1` `test`.`t2` )", nil}, + {`select /*+ use_index(t1, k_a) */ * from t1 where b=?`, "use_index(@`sel_1` `test`.`t1` `k_a`), no_order_index(@`sel_1` `test`.`t1` `k_a`)", subQueryTemp}, + {`select /*+ use_index(t1, k_bc) */ * from t1 where a=?`, "use_index(@`sel_1` `test`.`t1` `k_bc`), no_order_index(@`sel_1` `test`.`t1` `k_bc`)", subQueryTemp}, + {`select /*+ use_index(t1, primary) */ * from t1 where a=? and b=?`, "use_index(@`sel_1` `test`.`t1` ), no_order_index(@`sel_1` `test`.`t1` `primary`)", subQueryTemp}, + {`select /*+ ignore_index(t1, k_a, k_bc) */ * from t1 where a=? and b=?`, "use_index(@`sel_1` `test`.`t1` ), no_order_index(@`sel_1` `test`.`t1` `primary`), ignore_index(`t1` `k_a`, `k_bc`)", subQueryTemp}, + {`select /*+ use_index(t1) */ * from t1 where a=? and b=?`, "use_index(@`sel_1` `test`.`t1` ), no_order_index(@`sel_1` `test`.`t1` `primary`)", subQueryTemp}, + {`select /*+ use_index(t2) */ * from t2 where a=? and b=?`, "use_index(@`sel_1` `test`.`t2` )", subQueryTemp}, // aggregation {`select /*+ hash_agg(), use_index(t1, primary), agg_to_cop() */ count(*) from t1 where a