修复distinct, group by, windown function partition wise计划不优问题

This commit is contained in:
zzg19950727 2024-07-15 11:23:58 +00:00 committed by ob-robot
parent d124cba5eb
commit 4ac1481a69
7 changed files with 47 additions and 12 deletions

View File

@ -3307,7 +3307,7 @@ static struct VarsInit{
}();
[&] (){
ObSysVars[234].default_value_ = "4.3.2.0" ;
ObSysVars[234].default_value_ = "4.3.3.0" ;
ObSysVars[234].info_ = "enabling a series of optimizer features based on an OceanBase release number" ;
ObSysVars[234].name_ = "optimizer_features_enable" ;
ObSysVars[234].data_type_ = ObVarcharType ;

View File

@ -3343,7 +3343,7 @@
"optimizer_features_enable": {
"id": 10150,
"name": "optimizer_features_enable",
"default_value": "4.3.2.0",
"default_value": "4.3.3.0",
"base_value": "",
"data_type": "varchar",
"info": "enabling a series of optimizer features based on an OceanBase release number",

View File

@ -5347,7 +5347,10 @@ int ObLogPlan::create_scala_group_plan(const ObIArray<ObAggFunRawExpr*> &aggr_it
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(groupby_helper.distinct_exprs_,
is_partition_wise))) {
LOG_WARN("failed to check if sharding compatible with distinct expr", K(ret));
} else if (groupby_helper.can_three_stage_pushdown_ && !is_partition_wise) {
} else if (groupby_helper.can_three_stage_pushdown_ &&
!(is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
OPT_TRACE("generate three stage group plan");
if (NULL == groupby_helper.aggr_code_expr_ &&
OB_FAIL(prepare_three_stage_info(dummy_exprs, dummy_exprs, groupby_helper))) {

View File

@ -6526,4 +6526,15 @@ int ObLogicalOperator::check_op_orderding_used_by_parent(bool &used)
}
}
return ret;
}
bool ObLogicalOperator::is_parallel_more_than_part_cnt() const
{
if (NULL == strong_sharding_) {
return false;
} else if (strong_sharding_->get_part_cnt() < 1) {
return false;
} else {
return get_parallel() > strong_sharding_->get_part_cnt();
}
}

View File

@ -1074,6 +1074,7 @@ public:
{
exchange_allocated_ = exchange_allocated;
}
bool is_parallel_more_than_part_cnt() const;
virtual bool is_gi_above() const { return false; }
inline void set_phy_plan_type(ObPhyPlanType phy_plan_type)
{

View File

@ -340,7 +340,10 @@ int ObSelectLogPlan::candi_allocate_three_stage_group_by(const ObIArray<ObRawExp
OB_FAIL(candidate_plan.plan_tree_->check_sharding_compatible_with_reduce_expr(reduce_exprs,
is_partition_wise))) {
LOG_WARN("failed to check if sharding compatible with distinct expr", K(ret));
} else if (!candidate_plan.plan_tree_->is_distributed() || is_partition_wise) {
} else if (!candidate_plan.plan_tree_->is_distributed() ||
(is_partition_wise &&
!(candidate_plan.plan_tree_->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
bool part_sort_valid = !groupby_helper.force_normal_sort_ && !group_by_exprs.empty();
bool normal_sort_valid = !groupby_helper.force_part_sort_;
if (OB_FAIL(update_part_sort_method(part_sort_valid, normal_sort_valid))) {
@ -565,7 +568,9 @@ int ObSelectLogPlan::should_create_rollup_pushdown_plan(ObLogicalOperator *top,
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
is_partition_wise))) {
LOG_WARN("failed to check is partition wise", K(ret));
} else if (!top->is_distributed() || is_partition_wise ) {
} else if (!top->is_distributed() || (is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
// do nothing
} else if (NULL == groupby_helper.rollup_id_expr_ &&
OB_FAIL(ObRawExprUtils::build_pseudo_rollup_id(get_optimizer_context().get_expr_factory(),
@ -727,7 +732,9 @@ int ObSelectLogPlan::create_hash_group_plan(const ObIArray<ObRawExpr*> &reduce_e
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
is_partition_wise))) {
LOG_WARN("failed to check if sharding compatible", K(ret));
} else if (!top->is_distributed() || is_partition_wise) {
} else if (!top->is_distributed() || (is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
if (OB_FAIL(allocate_group_by_as_top(top,
AggregateAlgo::HASH_AGGREGATE,
group_by_exprs,
@ -1075,7 +1082,9 @@ int ObSelectLogPlan::inner_create_merge_group_plan(const ObIArray<ObRawExpr*> &r
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
is_partition_wise))) {
LOG_WARN("failed to check if sharding compatible with reduce expr", K(ret));
} else if (!top->is_distributed() || is_partition_wise) {
} else if (!top->is_distributed() || (is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
if (OB_FAIL(try_allocate_sort_as_top(top, sort_keys, need_sort, prefix_pos, part_cnt))) {
LOG_WARN("failed to allocate sort as top", K(ret));
} else if (OB_FAIL(allocate_group_by_as_top(top,
@ -1558,7 +1567,10 @@ int ObSelectLogPlan::create_hash_distinct_plan(ObLogicalOperator *&top,
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
is_partition_wise))) {
LOG_WARN("failed to check sharding compatible with reduce expr", K(ret));
} else if (!top->is_distributed() || is_partition_wise) {
} else if (!top->is_distributed() ||
(is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
OPT_TRACE("is basic distinct:", !top->is_distributed());
OPT_TRACE("is partition wise distinct", is_partition_wise);
if (OB_FAIL(allocate_distinct_as_top(top,
@ -1645,7 +1657,10 @@ int ObSelectLogPlan::create_merge_distinct_plan(ObLogicalOperator *&top,
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
is_partition_wise))) {
LOG_WARN("failed to check sharding compatible with reduce exprs", K(ret));
} else if (!top->is_distributed() || is_partition_wise) {
} else if (!top->is_distributed() ||
(is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
OPT_TRACE("is basic distinct:", !top->is_distributed());
OPT_TRACE("is partition wise distinct", is_partition_wise);
if (OB_FAIL(try_allocate_sort_as_top(top, sort_keys, need_sort, prefix_pos))) {
@ -6015,7 +6030,9 @@ int ObSelectLogPlan::create_none_dist_win_func(ObLogicalOperator *top,
LOG_WARN("failed to check match window function parallel", K(ret));
} else if (WinDistAlgo::WIN_DIST_NONE == win_func_helper.win_dist_method_
|| !top->is_distributed()
|| is_partition_wise) {
|| (is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
LOG_TRACE("begin to create none dist window function", K(top->is_distributed()),
K(single_part_parallel), K(is_partition_wise), K(need_sort), K(part_cnt),
K(win_func_helper.force_hash_sort_), K(win_func_helper.force_normal_sort_));
@ -6267,7 +6284,9 @@ int ObSelectLogPlan::create_hash_dist_win_func(ObLogicalOperator *top,
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(win_func_helper.partition_exprs_,
is_partition_wise))) {
LOG_WARN("failed to check if sharding compatible", K(ret));
} else if (!top->is_distributed() || is_partition_wise) {
} else if (!top->is_distributed() || (is_partition_wise &&
!(top->is_parallel_more_than_part_cnt() &&
get_optimizer_context().get_query_ctx()->optimizer_features_enable_version_ > COMPAT_VERSION_4_3_2))) {
LOG_TRACE("ignore allocate hash window function for local or partition wise",
K(top->is_distributed()), K(is_partition_wise));
} else {

View File

@ -222,7 +222,8 @@ struct ObGlobalHint {
#define COMPAT_VERSION_4_3_0 (oceanbase::common::cal_version(4, 3, 0, 0))
#define COMPAT_VERSION_4_3_1 (oceanbase::common::cal_version(4, 3, 1, 0))
#define COMPAT_VERSION_4_3_2 (oceanbase::common::cal_version(4, 3, 2, 0))
#define LASTED_COMPAT_VERSION COMPAT_VERSION_4_3_2
#define COMPAT_VERSION_4_3_3 (oceanbase::common::cal_version(4, 3, 3, 0))
#define LASTED_COMPAT_VERSION COMPAT_VERSION_4_3_3
static bool is_valid_opt_features_version(uint64_t version)
{ return COMPAT_VERSION_4_0 <= version && LASTED_COMPAT_VERSION >= version; }