diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java index 4d58990fbc..d21ee19df6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/hint/LeadingHint.java @@ -216,6 +216,10 @@ public class LeadingHint extends Hint { pair.second = relationIdTableNamePair.second; isUpdate = true; } + if (pair.second.equals(relationIdTableNamePair.second)) { + pair.first = relationIdTableNamePair.first; + isUpdate = true; + } } if (!isUpdate) { relationIdAndTableName.add(relationIdTableNamePair); diff --git a/regression-test/data/nereids_hint_tpch_p0/shape/q15.out b/regression-test/data/nereids_hint_tpch_p0/shape/q15.out index c059df5018..bb2463ee3f 100644 --- a/regression-test/data/nereids_hint_tpch_p0/shape/q15.out +++ b/regression-test/data/nereids_hint_tpch_p0/shape/q15.out @@ -5,23 +5,24 @@ PhysicalResultSink ----PhysicalDistribute[DistributionSpecGather] ------PhysicalQuickSort[LOCAL_SORT] --------PhysicalProject -----------hashJoin[INNER_JOIN] hashCondition=((supplier.s_suppkey = revenue0.supplier_no)) otherCondition=() -------------PhysicalProject ---------------PhysicalOlapScan[supplier] +----------hashJoin[INNER_JOIN] hashCondition=((revenue0.total_revenue = max(total_revenue))) otherCondition=() ------------PhysicalDistribute[DistributionSpecHash] --------------PhysicalProject -----------------hashJoin[INNER_JOIN] hashCondition=((revenue0.total_revenue = max(total_revenue))) otherCondition=() -------------------hashAgg[GLOBAL] ---------------------PhysicalDistribute[DistributionSpecGather] -----------------------hashAgg[LOCAL] -------------------------PhysicalProject ---------------------------hashAgg[GLOBAL] -----------------------------PhysicalDistribute[DistributionSpecHash] -------------------------------hashAgg[LOCAL] ---------------------------------PhysicalProject -----------------------------------filter((lineitem.l_shipdate < '1996-04-01') and (lineitem.l_shipdate >= '1996-01-01')) -------------------------------------PhysicalOlapScan[lineitem] -------------------PhysicalDistribute[DistributionSpecReplicated] +----------------hashJoin[INNER_JOIN] hashCondition=((supplier.s_suppkey = revenue0.supplier_no)) otherCondition=() +------------------PhysicalProject +--------------------PhysicalOlapScan[supplier] +------------------PhysicalDistribute[DistributionSpecHash] +--------------------PhysicalProject +----------------------hashAgg[GLOBAL] +------------------------PhysicalDistribute[DistributionSpecHash] +--------------------------hashAgg[LOCAL] +----------------------------PhysicalProject +------------------------------filter((lineitem.l_shipdate < '1996-04-01') and (lineitem.l_shipdate >= '1996-01-01')) +--------------------------------PhysicalOlapScan[lineitem] +------------PhysicalDistribute[DistributionSpecHash] +--------------hashAgg[GLOBAL] +----------------PhysicalDistribute[DistributionSpecGather] +------------------hashAgg[LOCAL] --------------------PhysicalProject ----------------------hashAgg[GLOBAL] ------------------------PhysicalDistribute[DistributionSpecHash] @@ -31,7 +32,7 @@ PhysicalResultSink --------------------------------PhysicalOlapScan[lineitem] Hint log: -Used: leading(revenue0 supplier ) +Used: leading(supplier revenue0 ) UnUsed: SyntaxError: diff --git a/regression-test/suites/nereids_hint_tpch_p0/shape/q15.groovy b/regression-test/suites/nereids_hint_tpch_p0/shape/q15.groovy index 23cf07c71e..7fed555135 100644 --- a/regression-test/suites/nereids_hint_tpch_p0/shape/q15.groovy +++ b/regression-test/suites/nereids_hint_tpch_p0/shape/q15.groovy @@ -37,7 +37,7 @@ suite("q15") { qt_select """ explain shape plan select - /*+ leading(revenue0 supplier) */ + /*+ leading(supplier revenue0) */ s_suppkey, s_name, s_address, diff --git a/regression-test/suites/nereids_p0/hint/fix_leading.groovy b/regression-test/suites/nereids_p0/hint/fix_leading.groovy index 172b02f9e5..4681fa16e0 100644 --- a/regression-test/suites/nereids_p0/hint/fix_leading.groovy +++ b/regression-test/suites/nereids_p0/hint/fix_leading.groovy @@ -184,4 +184,42 @@ suite("fix_leading") { // check brace problem qt_select6_1 """explain shape plan select /*+ leading(t1 {{t2 t3}{t4 t5}} t6) */ count(*) from t1 join t2 on c1 = c2 join t3 on c1 = c3 join t4 on c1 = c4 join t5 on c1 = c5 join t6 on c1 = c6;""" + // check filter in duplicated aliasName + explain { + sql """shape plan SELECT + t1.c2 AS c4 + FROM + ( + SELECT + /*+ leading( { tbl2 tbl3 } tbl1 ) */ + tbl3.c3 AS c4, + 4 AS c2 + FROM + t1 AS tbl1 + INNER JOIN t2 AS tbl2 ON tbl2.c2 >= tbl1.c1 + OR tbl2.c2 < (5 * 1) + INNER JOIN t3 AS tbl3 ON tbl2.c2 >= tbl2.c2 + WHERE + ( + tbl1.c1 <> tbl3.c3 + ) + ORDER BY + 2, + 4, + 1, + 3 ASC + LIMIT + 5 OFFSET 10 + ) AS t1 + INNER JOIN t4 AS tbl2 ON tbl2.c4 != (7 * 1) + WHERE + NOT ( + t1.c2 > tbl2.c4 + ) + ORDER BY + 1 DESC + LIMIT + 5;""" + contains("Used: leading({ tbl2 tbl3 } tbl1 )") + } }