fix three-stage group by generate normal group by as scalar group by

This commit is contained in:
ChangerR
2023-02-24 14:47:16 +00:00
committed by ob-robot
parent de212c4e62
commit e058f14334
2 changed files with 16 additions and 3 deletions

View File

@ -6256,8 +6256,13 @@ int ObLogPlan::create_three_stage_group_plan(const ObIArray<ObRawExpr*> &group_b
// 3. prepare to allocate the third group by
if (OB_SUCC(ret)) {
const bool is_scalar_aggr = group_by_exprs.empty() && rollup_exprs.empty();
third_aggr_algo = is_scalar_aggr ? SCALAR_AGGREGATE : second_aggr_algo;
if (helper.is_scalar_group_by_) {
third_aggr_algo = SCALAR_AGGREGATE;
} else if (group_by_exprs.empty()) {
third_aggr_algo = MERGE_AGGREGATE;
} else {
third_aggr_algo = second_aggr_algo;
}
third_rollup_status = !rollup_exprs.empty() ? ROLLUP_COLLECTOR : NONE_ROLLUP;
third_exch_info.is_rollup_hybrid_ = !rollup_exprs.empty();
@ -6643,15 +6648,20 @@ int ObLogPlan::init_groupby_helper(const ObIArray<ObRawExpr*> &group_exprs,
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = NULL;
ObLogicalOperator *best_plan = NULL;
const ObSelectStmt* stmt = NULL;
ObSEArray<ObRawExpr*, 4> group_rollup_exprs;
bool push_group = false;
groupby_helper.force_use_hash_ = get_log_plan_hint().use_hash_aggregate();
groupby_helper.force_use_merge_ = get_log_plan_hint().use_merge_aggregate();
if (OB_FAIL(candidates_.get_best_plan(best_plan))) {
LOG_WARN("failed to get best plan", K(ret));
} else if (OB_ISNULL(best_plan)) {
} else if (OB_ISNULL(best_plan) ||
OB_ISNULL(get_stmt()) ||
OB_UNLIKELY(!get_stmt()->is_select_stmt()) ||
OB_ISNULL(stmt = static_cast<const ObSelectStmt*>(get_stmt()))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FALSE_IT(groupby_helper.is_scalar_group_by_ = stmt->is_scala_group_by())) {
} else if (OB_FAIL(append(group_rollup_exprs, group_exprs)) ||
OB_FAIL(append(group_rollup_exprs, rollup_exprs))) {
LOG_WARN("failed to append group rollup exprs", K(ret));

View File

@ -496,6 +496,7 @@ public:
can_rollup_pushdown_(false),
force_use_hash_(false),
force_use_merge_(false),
is_scalar_group_by_(false),
distinct_exprs_(),
aggr_code_expr_(NULL),
non_distinct_aggr_items_(),
@ -514,6 +515,7 @@ public:
bool can_rollup_pushdown_;
bool force_use_hash_; // has use_hash_aggregation/use_hash_distinct hint
bool force_use_merge_; // has no_use_hash_aggregation/no_use_hash_distinct hint
bool is_scalar_group_by_;
ObSEArray<ObRawExpr*, 8> distinct_exprs_;
// context for three stage group by push down
@ -537,6 +539,7 @@ public:
K_(can_rollup_pushdown),
K_(force_use_hash),
K_(force_use_merge),
K_(is_scalar_group_by),
K_(distinct_exprs));
};