From e6a185d65785affbf974a7224cd011c4b3fed62b Mon Sep 17 00:00:00 2001 From: minghong Date: Tue, 30 Jul 2024 18:09:26 +0800 Subject: [PATCH] fmt --- .../rules/rewrite/PullUpJoinFromUnion.java | 14 +-- .../trees/plans/logical/LogicalOlapScan.java | 2 +- .../shape/query23_2.out | 88 +++++++++++++++ .../shape/query23_2.groovy | 102 ++++++++++++++++++ 4 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query23_2.out create mode 100644 regression-test/suites/nereids_tpcds_shape_sf100_p0/shape/query23_2.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnion.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnion.java index e441bf3ad5c3f0..1f68d53f079c08 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnion.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnion.java @@ -90,7 +90,7 @@ public Rule build() { break; } } - if (commonChild == null) { + if (commonChild == null || commonChild.isEmpty()) { return null; } @@ -181,8 +181,8 @@ private Plan constructNewJoinUnion( commonChild, joinSlotToProject, constantAlias, missSlotMap, originChildSlotToUnion); // 2. construct join union - LogicalJoin originalJoin = commonChild.iterator().next().first; - Plan newChild = commonChild.iterator().next().second; + LogicalJoin originalJoin = commonChild.get(0).first; + Plan newChild = commonChild.get(0).second; Plan newJoin = constructNewJoin(originalJoin, newUnion, newChild); // 3. map the output to origin output @@ -379,7 +379,8 @@ private boolean tryMapJoinSlotToUnion(LogicalUnion union, List"), "selectedIndexId", selectedIndexId, diff --git a/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query23_2.out b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query23_2.out new file mode 100644 index 00000000000000..b293afdff730a9 --- /dev/null +++ b/regression-test/data/nereids_tpcds_shape_sf100_p0/shape/query23_2.out @@ -0,0 +1,88 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !ds_shape_23_2 -- +PhysicalCteAnchor ( cteId=CTEId#0 ) +--PhysicalCteProducer ( cteId=CTEId#0 ) +----PhysicalProject +------filter((cnt > 4)) +--------hashAgg[GLOBAL] +----------PhysicalDistribute[DistributionSpecHash] +------------hashAgg[LOCAL] +--------------PhysicalProject +----------------hashJoin[INNER_JOIN broadcast] hashCondition=((store_sales.ss_item_sk = item.i_item_sk)) otherCondition=() build RFs:RF1 i_item_sk->[ss_item_sk] +------------------PhysicalProject +--------------------hashJoin[INNER_JOIN broadcast] hashCondition=((store_sales.ss_sold_date_sk = date_dim.d_date_sk)) otherCondition=() build RFs:RF0 d_date_sk->[ss_sold_date_sk] +----------------------PhysicalProject +------------------------PhysicalOlapScan[store_sales] apply RFs: RF0 RF1 +----------------------PhysicalProject +------------------------filter(d_year IN (2000, 2001, 2002, 2003)) +--------------------------PhysicalOlapScan[date_dim] +------------------PhysicalProject +--------------------PhysicalOlapScan[item] +--PhysicalCteAnchor ( cteId=CTEId#2 ) +----PhysicalCteProducer ( cteId=CTEId#2 ) +------PhysicalProject +--------NestedLoopJoin[INNER_JOIN](cast(ssales as DOUBLE) > cast((0.9500 * tpcds_cmax) as DOUBLE)) +----------PhysicalProject +------------hashAgg[GLOBAL] +--------------PhysicalDistribute[DistributionSpecHash] +----------------hashAgg[LOCAL] +------------------PhysicalProject +--------------------filter(( not ss_customer_sk IS NULL)) +----------------------PhysicalOlapScan[store_sales] +----------PhysicalProject +------------hashAgg[GLOBAL] +--------------PhysicalDistribute[DistributionSpecGather] +----------------hashAgg[LOCAL] +------------------PhysicalProject +--------------------hashAgg[GLOBAL] +----------------------PhysicalDistribute[DistributionSpecHash] +------------------------hashAgg[LOCAL] +--------------------------PhysicalProject +----------------------------hashJoin[INNER_JOIN broadcast] hashCondition=((store_sales.ss_sold_date_sk = date_dim.d_date_sk)) otherCondition=() build RFs:RF2 d_date_sk->[ss_sold_date_sk] +------------------------------PhysicalProject +--------------------------------filter(( not ss_customer_sk IS NULL)) +----------------------------------PhysicalOlapScan[store_sales] apply RFs: RF2 +------------------------------PhysicalProject +--------------------------------filter(d_year IN (2000, 2001, 2002, 2003)) +----------------------------------PhysicalOlapScan[date_dim] +----PhysicalResultSink +------PhysicalTopN[MERGE_SORT] +--------PhysicalDistribute[DistributionSpecGather] +----------PhysicalTopN[LOCAL_SORT] +------------PhysicalProject +--------------hashJoin[INNER_JOIN shuffle] hashCondition=((cs_bill_customer_sk = customer.c_customer_sk)) otherCondition=() build RFs:RF5 cs_bill_customer_sk->[c_customer_sk] +----------------PhysicalProject +------------------PhysicalOlapScan[customer] apply RFs: RF5 +----------------PhysicalProject +------------------PhysicalUnion +--------------------hashAgg[GLOBAL] +----------------------PhysicalDistribute[DistributionSpecHash] +------------------------hashAgg[LOCAL] +--------------------------PhysicalProject +----------------------------hashJoin[LEFT_SEMI_JOIN shuffle] hashCondition=((catalog_sales.cs_item_sk = frequent_ss_items.item_sk)) otherCondition=() +------------------------------hashJoin[LEFT_SEMI_JOIN shuffle] hashCondition=((catalog_sales.cs_bill_customer_sk = best_ss_customer.c_customer_sk)) otherCondition=() +--------------------------------PhysicalProject +----------------------------------hashJoin[INNER_JOIN broadcast] hashCondition=((catalog_sales.cs_sold_date_sk = date_dim.d_date_sk)) otherCondition=() build RFs:RF3 d_date_sk->[cs_sold_date_sk] +------------------------------------PhysicalProject +--------------------------------------PhysicalOlapScan[catalog_sales] apply RFs: RF3 +------------------------------------PhysicalProject +--------------------------------------filter((date_dim.d_moy = 5) and (date_dim.d_year = 2000)) +----------------------------------------PhysicalOlapScan[date_dim] +--------------------------------PhysicalCteConsumer ( cteId=CTEId#2 ) +------------------------------PhysicalCteConsumer ( cteId=CTEId#0 ) +--------------------hashAgg[GLOBAL] +----------------------PhysicalDistribute[DistributionSpecHash] +------------------------hashAgg[LOCAL] +--------------------------PhysicalProject +----------------------------hashJoin[LEFT_SEMI_JOIN shuffle] hashCondition=((web_sales.ws_item_sk = frequent_ss_items.item_sk)) otherCondition=() +------------------------------hashJoin[LEFT_SEMI_JOIN shuffle] hashCondition=((web_sales.ws_bill_customer_sk = best_ss_customer.c_customer_sk)) otherCondition=() +--------------------------------PhysicalProject +----------------------------------hashJoin[INNER_JOIN broadcast] hashCondition=((web_sales.ws_sold_date_sk = date_dim.d_date_sk)) otherCondition=() build RFs:RF4 d_date_sk->[ws_sold_date_sk] +------------------------------------PhysicalProject +--------------------------------------PhysicalOlapScan[web_sales] apply RFs: RF4 +------------------------------------PhysicalProject +--------------------------------------filter((date_dim.d_moy = 5) and (date_dim.d_year = 2000)) +----------------------------------------PhysicalOlapScan[date_dim] +--------------------------------PhysicalCteConsumer ( cteId=CTEId#2 ) +------------------------------PhysicalCteConsumer ( cteId=CTEId#0 ) + diff --git a/regression-test/suites/nereids_tpcds_shape_sf100_p0/shape/query23_2.groovy b/regression-test/suites/nereids_tpcds_shape_sf100_p0/shape/query23_2.groovy new file mode 100644 index 00000000000000..d0495ebf6f31a5 --- /dev/null +++ b/regression-test/suites/nereids_tpcds_shape_sf100_p0/shape/query23_2.groovy @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +suite("query23_2") { + String db = context.config.getDbNameByFile(new File(context.file.parent)) + multi_sql """ + use ${db}; + set enable_nereids_planner=true; + set enable_nereids_distribute_planner=false; + set enable_fallback_to_original_planner=false; + set exec_mem_limit=21G; + set be_number_for_test=3; + set enable_runtime_filter_prune=false; + set parallel_pipeline_task_num=8; + set forbid_unknown_col_stats=false; + set enable_stats=true; + set runtime_filter_type=8; + set broadcast_row_count_limit = 30000000; + set enable_nereids_timeout = false; + set enable_pipeline_engine = true; + set disable_nereids_rules='PRUNE_EMPTY_PARTITION'; + set push_topn_to_agg = true; + set topn_opt_limit_threshold=1024; + """ + + def ds = """ +with frequent_ss_items as + (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt + from store_sales + ,date_dim + ,item + where ss_sold_date_sk = d_date_sk + and ss_item_sk = i_item_sk + and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) + group by substr(i_item_desc,1,30),i_item_sk,d_date + having count(*) >4), + max_store_sales as + (select max(csales) tpcds_cmax + from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales + from store_sales + ,customer + ,date_dim + where ss_customer_sk = c_customer_sk + and ss_sold_date_sk = d_date_sk + and d_year in (2000,2000+1,2000+2,2000+3) + group by c_customer_sk) t), + best_ss_customer as + (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales + from store_sales + ,customer + where ss_customer_sk = c_customer_sk + group by c_customer_sk + having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select + * + from max_store_sales)) + select c_last_name,c_first_name,sales + from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales + from catalog_sales + ,customer + ,date_dim + where d_year = 2000 + and d_moy = 5 + and cs_sold_date_sk = d_date_sk + and cs_item_sk in (select item_sk from frequent_ss_items) + and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) + and cs_bill_customer_sk = c_customer_sk + group by c_last_name,c_first_name + union all + select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales + from web_sales + ,customer + ,date_dim + where d_year = 2000 + and d_moy = 5 + and ws_sold_date_sk = d_date_sk + and ws_item_sk in (select item_sk from frequent_ss_items) + and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) + and ws_bill_customer_sk = c_customer_sk + group by c_last_name,c_first_name) t2 + order by c_last_name,c_first_name,sales + limit 100;""" + qt_ds_shape_23_2 """ + explain shape plan + ${ds} + """ +}