From 1d304c75b3f2da9511a7b0e1af9377b39b13883c Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 4 Jul 2024 23:48:05 +0800 Subject: [PATCH] u Signed-off-by: Weizhen Wang --- pkg/bindinfo/tests/bind_test.go | 116 ++++++++++++++++++++++++++++- pkg/planner/core/find_best_task.go | 3 - 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/pkg/bindinfo/tests/bind_test.go b/pkg/bindinfo/tests/bind_test.go index 66ddefe3733f5..f6f47763dafd2 100644 --- a/pkg/bindinfo/tests/bind_test.go +++ b/pkg/bindinfo/tests/bind_test.go @@ -925,11 +925,125 @@ func testFuzzyBindingHints(t *testing.T) { binding string qTemplate string }{ + // use index + {`create global binding using select /*+ use_index(t1, c) */ * from *.t1 where a=1`, + `select * from %st1 where a=1000`}, + {`create global binding using select /*+ use_index(t1, c) */ * from *.t1 where d<1`, + `select * from %st1 where d<10000`}, + {`create global binding using select /*+ use_index(t1, c) */ * from *.t1, *.t2 where t1.d<1`, + `select * from %st1, t2 where t1.d<100`}, + {`create global binding using select /*+ use_index(t1, c) */ * from *.t1, *.t2 where t1.d<1`, + `select * from t1, %st2 where t1.d<100`}, + {`create global binding using select /*+ use_index(t1, c), use_index(t2, a) */ * from *.t1, *.t2 where t1.d<1`, + `select * from %st1, t2 where t1.d<100`}, + {`create global binding using select /*+ use_index(t1, c), use_index(t2, a) */ * from *.t1, *.t2 where t1.d<1`, + `select * from t1, %st2 where t1.d<100`}, + {`create global binding using select /*+ use_index(t1, c), use_index(t2, a) */ * from *.t1, *.t2, *.t3 where t1.d<1`, + `select * from %st1, t2, t3 where t1.d<100`}, + {`create global binding using select /*+ use_index(t1, c), use_index(t2, a) */ * from *.t1, *.t2, *.t3 where t1.d<1`, + `select * from t1, t2, %st3 where t1.d<100`}, - // join type hint + // ignore index + {`create global binding using select /*+ ignore_index(t1, b) */ * from *.t1 where b=1`, + `select * from %st1 where b=1000`}, + {`create global binding using select /*+ ignore_index(t1, b) */ * from *.t1 where b>1`, + `select * from %st1 where b>1000`}, + {`create global binding using select /*+ ignore_index(t1, b) */ * from *.t1 where b in (1,2)`, + `select * from %st1 where b in (1)`}, + {`create global binding using select /*+ ignore_index(t1, b) */ * from *.t1 where b in (1,2)`, + `select * from %st1 where b in (1,2,3,4,5)`}, + // order index hint + {`create global binding using select /*+ order_index(t1, a) */ a from *.t1 where a<10 order by a limit 10`, + `select a from %st1 where a<10000 order by a limit 10`}, + {`create global binding using select /*+ order_index(t1, b) */ b from *.t1 where b>10 order by b limit 1111`, + `select b from %st1 where b>2 order by b limit 10`}, + + // no order index hint + {`create global binding using select /*+ no_order_index(t1, c) */ c from *.t1 where c<10 order by c limit 10`, + `select c from %st1 where c<10000 order by c limit 10`}, + {`create global binding using select /*+ no_order_index(t1, d) */ d from *.t1 where d>10 order by d limit 1111`, + `select d from %st1 where d>2 order by d limit 10`}, + + // agg hint + {`create global binding using select /*+ hash_agg() */ count(*) from *.t1 group by a`, + `select count(*) from %st1 group by a`}, + {`create global binding using select /*+ stream_agg() */ count(*) from *.t1 group by b`, + `select count(*) from %st1 group by b`}, + + // to_cop hint + {`create global binding using select /*+ agg_to_cop() */ sum(a) from *.t1`, + `select sum(a) from %st1`}, + {`create global binding using select /*+ limit_to_cop() */ a from *.t1 limit 10`, + `select a from %st1 limit 101`}, + + // index merge hint + {`create global binding using select /*+ use_index_merge(t1, c, d) */ * from *.t1 where c=1 or d=1`, + `select * from %st1 where c=1000 or d=1000`}, + {`create global binding using select /*+ no_index_merge() */ * from *.t1 where a=1 or b=1`, + `select * from %st1 where a=1000 or b=1000`}, + + // join type hint + {`create global binding using select /*+ hash_join(t1) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from %st1, t2 where t1.a=t2.a`}, + {`create global binding using select /*+ hash_join(t2) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from t1, %st2 where t1.a=t2.a`}, + {`create global binding using select /*+ hash_join(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + {`create global binding using select /*+ hash_join_build(t1) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from t1, %st2 where t1.a=t2.a`}, + {`create global binding using select /*+ hash_join_probe(t1) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from t1, %st2 where t1.a=t2.a`}, + {`create global binding using select /*+ merge_join(t1) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from %st1, t2 where t1.a=t2.a`}, + {`create global binding using select /*+ merge_join(t2) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from t1, %st2 where t1.a=t2.a`}, + {`create global binding using select /*+ merge_join(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, {`create global binding using select /*+ inl_join(t1) */ * from *.t1, *.t2 where t1.a=t2.a`, `select * from %st1, t2 where t1.a=t2.a`}, + {`create global binding using select /*+ inl_join(t2) */ * from *.t1, *.t2 where t1.a=t2.a`, + `select * from t1, %st2 where t1.a=t2.a`}, + {`create global binding using select /*+ inl_join(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + + // no join type hint + {`create global binding using select /*+ no_hash_join(t1) */ * from *.t1, *.t2 where t1.b=t2.b`, + `select * from %st1, t2 where t1.b=t2.b`}, + {`create global binding using select /*+ no_hash_join(t2) */ * from *.t1, *.t2 where t1.c=t2.c`, + `select * from t1, %st2 where t1.c=t2.c`}, + {`create global binding using select /*+ no_hash_join(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + {`create global binding using select /*+ no_merge_join(t1) */ * from *.t1, *.t2 where t1.b=t2.b`, + `select * from %st1, t2 where t1.b=t2.b`}, + {`create global binding using select /*+ no_merge_join(t2) */ * from *.t1, *.t2 where t1.c=t2.c`, + `select * from t1, %st2 where t1.c=t2.c`}, + {`create global binding using select /*+ no_merge_join(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + {`create global binding using select /*+ no_index_join(t1) */ * from *.t1, *.t2 where t1.b=t2.b`, + `select * from %st1, t2 where t1.b=t2.b`}, + {`create global binding using select /*+ no_index_join(t2) */ * from *.t1, *.t2 where t1.c=t2.c`, + `select * from t1, %st2 where t1.c=t2.c`}, + {`create global binding using select /*+ no_index_join(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + + // join order hint + {`create global binding using select /*+ leading(t2) */ * from *.t1, *.t2 where t1.b=t2.b`, + `select * from %st1, t2 where t1.b=t2.b`}, + {`create global binding using select /*+ leading(t2) */ * from *.t1, *.t2 where t1.c=t2.c`, + `select * from t1, %st2 where t1.c=t2.c`}, + {`create global binding using select /*+ leading(t2, t1) */ * from *.t1, *.t2 where t1.c=t2.c`, + `select * from t1, %st2 where t1.c=t2.c`}, + {`create global binding using select /*+ leading(t1, t2) */ * from *.t1, *.t2 where t1.c=t2.c`, + `select * from t1, %st2 where t1.c=t2.c`}, + {`create global binding using select /*+ leading(t1) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + {`create global binding using select /*+ leading(t2) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + {`create global binding using select /*+ leading(t2,t3) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, + {`create global binding using select /*+ leading(t2,t3,t1) */ * from *.t1, *.t2, *.t3 where t1.a=t2.a and t3.b=t2.b`, + `select * from t1, %st2, t3 where t1.a=t2.a and t3.b=t2.b`}, } { removeAllBindings(tk, true) tk.MustExec(c.binding) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index df2f386b88d2b..c4e384b541260 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -279,9 +279,6 @@ func iteratePhysicalPlan4BaseLogical( if childTask != nil && childTask.Invalid() { return nil, 0, childCnts, nil } - if childTask == nil { - continue - } childTasks = append(childTasks, childTask) } // This check makes sure that there is no invalid child task.