From 4942b97c45e91cae4666e3218fb774cdb29d9b1b Mon Sep 17 00:00:00 2001 From: obdev Date: Sun, 31 Jul 2022 20:29:55 +0800 Subject: [PATCH] [CP] fix allocate gi above window function bug --- src/sql/optimizer/ob_log_group_by.cpp | 29 +++++++++++++++++++--- src/sql/optimizer/ob_log_group_by.h | 1 + src/sql/optimizer/ob_log_window_function.h | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/sql/optimizer/ob_log_group_by.cpp b/src/sql/optimizer/ob_log_group_by.cpp index a41452df67..df4a2f491f 100644 --- a/src/sql/optimizer/ob_log_group_by.cpp +++ b/src/sql/optimizer/ob_log_group_by.cpp @@ -27,6 +27,7 @@ #include "ob_raw_expr_push_down_aggr_expr.h" #include "ob_select_log_plan.h" #include "common/ob_smart_call.h" +#include "ob_log_window_function.h" using namespace oceanbase; using namespace sql; @@ -277,15 +278,15 @@ int ObLogGroupBy::allocate_groupby_below(const ObIArray& distinct_ex // 2. distint expr is pushed down, such as count(distinct c1) // a partition should not be processed by two px tasks, other the distinct result // will be mis-estimated - bool find_exchange = false; + bool child_can_pullup_gi = true; if (OB_ISNULL(child = child_group_by->get_child(first_child))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(child), K(ret)); } else if (OB_FAIL(child_group_by->get_sharding_info().copy_with_part_keys(child->get_sharding_info()))) { LOG_WARN("failed to copy sharding info", K(ret)); - } else if (OB_FAIL(child_has_exchange(child, find_exchange))) { + } else if (OB_FAIL(check_can_pullup_gi(child, child_can_pullup_gi))) { LOG_WARN("fail to find tsc recursive"); - } else if (!find_exchange) { + } else if (child_can_pullup_gi) { child_group_by->set_is_partition_wise(true); child_group_by->set_is_block_gi_allowed(!should_push_distinct); } else { /*do nothing*/ @@ -306,7 +307,27 @@ int ObLogGroupBy::allocate_groupby_below(const ObIArray& distinct_ex return ret; } -int ObLogGroupBy::get_group_rollup_exprs(common::ObIArray& group_rollup_exprs) const +// child has allocate exchange or parallel window function, can not pullup gi +int ObLogGroupBy::check_can_pullup_gi(const ObLogicalOperator *op, bool &can_pullup) +{ + int ret = OB_SUCCESS; + if (OB_ISNULL(op) || !can_pullup) { + /*do nothing*/ + } else if (log_op_def::LOG_EXCHANGE == op->get_type() || + (log_op_def::LOG_WINDOW_FUNCTION == op->get_type() && + static_cast(op)->is_parallel())) { + can_pullup = false; + } else { + for (int i = 0; OB_SUCC(ret) && can_pullup && i < op->get_num_of_child(); ++i) { + if (OB_FAIL(SMART_CALL(check_can_pullup_gi(op->get_child(i), can_pullup)))) { + LOG_WARN("fail to find tsc recursive", K(ret)); + } + } + } + return ret; +} + +int ObLogGroupBy::get_group_rollup_exprs(common::ObIArray &group_rollup_exprs) const { int ret = OB_SUCCESS; if (OB_FAIL(append(group_rollup_exprs, group_exprs_))) { diff --git a/src/sql/optimizer/ob_log_group_by.h b/src/sql/optimizer/ob_log_group_by.h index 9b21e35b4f..4e00668287 100644 --- a/src/sql/optimizer/ob_log_group_by.h +++ b/src/sql/optimizer/ob_log_group_by.h @@ -95,6 +95,7 @@ public: int allocate_groupby_below(const ObIArray& distinct_exprs, const bool can_push, ObLogicalOperator*& exchange_point, common::ObIArray >& group_push_down_replaced_exprs); + int check_can_pullup_gi(const ObLogicalOperator *op, bool &can_pullup); int should_push_down_group_by(AllocExchContext& ctx, ObIArray& distinct_exprs, bool& should_push_groupby, bool& should_push_distinct); virtual uint64_t hash(uint64_t seed) const override; diff --git a/src/sql/optimizer/ob_log_window_function.h b/src/sql/optimizer/ob_log_window_function.h index 2c170e68fc..3d2d7a44c7 100644 --- a/src/sql/optimizer/ob_log_window_function.h +++ b/src/sql/optimizer/ob_log_window_function.h @@ -46,7 +46,7 @@ public: virtual int allocate_granule_pre(AllocGIContext& ctx) override; int get_win_partition_intersect_exprs(ObIArray& win_exprs, ObIArray& win_part_exprs); virtual int inner_append_not_produced_exprs(ObRawExprUniqueSet& raw_exprs) const override; - bool is_parallel() + bool is_parallel() const { return is_parallel_; }