fix set partition wise dop bug

This commit is contained in:
chimyue 2024-12-13 05:48:45 +00:00 committed by ob-robot
parent 47917cf1ce
commit d2b62f476b
8 changed files with 43 additions and 35 deletions

View File

@ -660,10 +660,10 @@ void ObPhysicalPlan::update_plan_expired_info(const ObAuditRecordData &record,
if (is_plan_unstable(sample_count, sample_exec_row_count, sample_exec_usec)) {
set_is_expired(true);
if (stat_.elapsed_time_ > SLOW_QUERY_TIME_FOR_PLAN_EXPIRE * stat_.execute_times_) {
LOG_INFO("plan expired for physical plan avg elapsed_time more than 5ms", K(stat_.plan_id_), K(stat_.elapsed_time_/stat_.execute_times_),
LOG_INFO("plan expired for physical plan avg elapsed_time more than 5ms", K(stat_.plan_id_),
K(stat_.elapsed_time_), K(stat_.execute_times_));
} else {
LOG_INFO("plan expired for physical plan avg elapsed_time no more than 5ms", K(stat_.plan_id_), K(stat_.elapsed_time_/stat_.execute_times_),
LOG_INFO("plan expired for physical plan avg elapsed_time no more than 5ms", K(stat_.plan_id_),
K(stat_.elapsed_time_), K(stat_.execute_times_));
}
}

View File

@ -773,7 +773,7 @@ int ObLogJoin::append_used_join_hint(ObIArray<const ObHint*> &used_hints)
if (OB_ISNULL(join_hint = log_join_hint->dist_method_hints_.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected NULL", K(ret), K(join_hint));
} else if (get_dist_method() != join_hint->get_dist_algo()) {
} else if (0 == (get_dist_method() & join_hint->get_dist_algo())) {
/* do nothing */
} else if (OB_FAIL(used_hints.push_back(join_hint))) {
LOG_WARN("failed to append pq distribute hint", K(ret));

View File

@ -938,13 +938,19 @@ int ObLogSet::compute_op_parallel_and_server_info()
need_re_est_child_cost_ = true;
}
} else if (DistAlgo::DIST_SET_PARTITION_WISE == get_distributed_algo()) {
ObLogicalOperator *child = get_child(first_child);
if (OB_ISNULL(child)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpect null child op", K(ret));
} else if (child->get_server_list().count() > 0 &&
get_parallel() > child->get_server_list().count()) {
int64_t reduce_parallel = child->get_server_list().count();
int64_t max_child_part_cnt = -1;
const ObLogicalOperator *child = NULL;
for (int64_t i = 0; OB_SUCC(ret) && i < get_num_of_child(); ++i) {
if (OB_ISNULL(child = get_child(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("set operator i-th child is null", K(ret), K(i));
} else {
max_child_part_cnt = child->get_part_cnt() > max_child_part_cnt ? child->get_part_cnt()
: max_child_part_cnt;
}
}
if (OB_SUCC(ret) && max_child_part_cnt > 0 && get_parallel() > max_child_part_cnt) {
int64_t reduce_parallel = max_child_part_cnt;
reduce_parallel = reduce_parallel < 2 ? 2 : reduce_parallel;
set_parallel(reduce_parallel);
need_re_est_child_cost_ = true;

View File

@ -2710,7 +2710,7 @@ int ObSelectLogPlan::get_distibute_union_all_method(const ObIArray<ObLogicalOper
bool is_set_partition_wise = false;
int64_t random_none_idx = OB_INVALID_INDEX;
largest_op = NULL;
DistAlgo hint_dist_methods = get_log_plan_hint().get_valid_set_dist_algo(&random_none_idx);
uint64_t hint_dist_methods = get_log_plan_hint().get_valid_set_dist_algo(&random_none_idx);
if (OB_ISNULL(select_stmt = get_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error", K(select_stmt), K(ret));
@ -2739,7 +2739,7 @@ int ObSelectLogPlan::get_distibute_union_all_method(const ObIArray<ObLogicalOper
}
int64_t max_child_parallel = ObGlobalHint::DEFAULT_PARALLEL;
int64_t first_child_part_cnt = 0;
int64_t first_child_server_cnt = 0;
int64_t max_child_part_cnt = 0;
const ObLogicalOperator *child = NULL;
for (int64_t i = 0; OB_SUCC(ret) && i < child_ops.count(); ++i) {
if (OB_ISNULL(child = child_ops.at(i))) {
@ -2748,9 +2748,12 @@ int ObSelectLogPlan::get_distibute_union_all_method(const ObIArray<ObLogicalOper
} else if (0 == i) {
max_child_parallel = child->get_parallel();
first_child_part_cnt = child->get_part_cnt();
first_child_server_cnt = child->get_server_list().count();
} else if (max_child_parallel < child->get_parallel()) {
max_child_parallel = child->get_parallel();
max_child_part_cnt = child->get_part_cnt();
} else {
max_child_parallel = child->get_parallel() > max_child_parallel ? child->get_parallel()
: max_child_parallel;
max_child_part_cnt = child->get_part_cnt() > max_child_part_cnt ? child->get_part_cnt()
: max_child_part_cnt;
}
}
if (OB_SUCC(ret) && (set_dist_methods & DistAlgo::DIST_BASIC_METHOD)) {
@ -2805,7 +2808,7 @@ int ObSelectLogPlan::get_distibute_union_all_method(const ObIArray<ObLogicalOper
} else if (!is_set_partition_wise) {
set_dist_methods &= ~DIST_SET_PARTITION_WISE;
OPT_TRACE("will not use set partition wise");
} else if (first_child_server_cnt <= max_child_parallel &&
} else if (max_child_part_cnt <= max_child_parallel &&
get_optimizer_context().get_query_ctx()->check_opt_compat_version(COMPAT_VERSION_4_3_5)) {
OPT_TRACE("will use set partition wise");
} else {
@ -3341,7 +3344,7 @@ int ObSelectLogPlan::get_recursive_union_all_distribute_method(ObLogicalOperator
ObSEArray<ObLogicalOperator*, 2> child_ops;
dist_set_method = DistAlgo::DIST_INVALID_METHOD;
uint64_t set_dist_methods = DistAlgo::DIST_BASIC_METHOD | DistAlgo::DIST_PULL_TO_LOCAL;
DistAlgo hint_dist_methods = get_log_plan_hint().get_valid_set_dist_algo();
uint64_t hint_dist_methods = get_log_plan_hint().get_valid_set_dist_algo();
if (!ignore_hint && DistAlgo::DIST_INVALID_METHOD != hint_dist_methods) {
set_dist_methods &= hint_dist_methods;
}

View File

@ -2532,16 +2532,8 @@ int ObPQSetHint::set_pq_set_hint(const DistAlgo dist_algo,
dist_methods_.at(1) = T_DISTRIBUTE_LOCAL;
break;
}
case DistAlgo::DIST_PARTITION_WISE: {
dist_methods_.at(0) = T_DISTRIBUTE_NONE;
dist_methods_.at(1) = T_DISTRIBUTE_NONE;
break;
}
case DistAlgo::DIST_EXT_PARTITION_WISE: {
dist_methods_.at(0) = T_DISTRIBUTE_NONE;
dist_methods_.at(1) = T_DISTRIBUTE_NONE;
break;
}
case DistAlgo::DIST_PARTITION_WISE:
case DistAlgo::DIST_EXT_PARTITION_WISE:
case DistAlgo::DIST_SET_PARTITION_WISE: {
dist_methods_.at(0) = T_DISTRIBUTE_NONE;
dist_methods_.at(1) = T_DISTRIBUTE_NONE;
@ -2649,10 +2641,10 @@ bool ObPQSetHint::is_valid_dist_methods(const ObIArray<ObItemType> &dist_methods
}
// DistAlgo::DIST_BASIC_METHOD indicate
DistAlgo ObPQSetHint::get_dist_algo(const ObIArray<ObItemType> &dist_methods,
uint64_t ObPQSetHint::get_dist_algo(const ObIArray<ObItemType> &dist_methods,
int64_t &random_none_idx)
{
DistAlgo dist_algo = DistAlgo::DIST_INVALID_METHOD;
uint64_t dist_algo = DistAlgo::DIST_INVALID_METHOD;
random_none_idx = OB_INVALID_INDEX;
if (dist_methods.empty()) {
dist_algo = DistAlgo::DIST_BASIC_METHOD;
@ -2714,6 +2706,11 @@ DistAlgo ObPQSetHint::get_dist_algo(const ObIArray<ObItemType> &dist_methods,
dist_algo = sql::get_dist_algo(tmp);
}
}
if (DistAlgo::DIST_PARTITION_WISE == dist_algo) {
dist_algo = DistAlgo::DIST_PARTITION_WISE
| DistAlgo::DIST_EXT_PARTITION_WISE
| DistAlgo::DIST_SET_PARTITION_WISE;
}
return dist_algo;
}

View File

@ -1127,7 +1127,9 @@ public:
ObIArray<ObTableInHint> &get_tables() { return tables_; }
const ObIArray<ObTableInHint> &get_tables() const { return tables_; }
DistAlgo get_dist_algo() const { return dist_algo_; }
uint64_t get_dist_algo() const { return DistAlgo::DIST_PARTITION_WISE == dist_algo_
? DistAlgo::DIST_PARTITION_WISE | DistAlgo::DIST_EXT_PARTITION_WISE
: dist_algo_; }
void set_dist_algo(DistAlgo dist_algo) { dist_algo_ = dist_algo; }
INHERIT_TO_STRING_KV("ObHint", ObHint, K_(tables), K_(dist_algo));
@ -1182,14 +1184,14 @@ class ObPQSetHint : public ObOptHint
virtual ~ObPQSetHint() {}
virtual int print_hint_desc(PlanText &plan_text) const override;
static bool is_valid_dist_methods(const ObIArray<ObItemType> &dist_methods);
static DistAlgo get_dist_algo(const ObIArray<ObItemType> &dist_methods,
static uint64_t get_dist_algo(const ObIArray<ObItemType> &dist_methods,
int64_t &random_none_idx);
static const char* get_dist_method_str(const ObItemType dist_method);
const ObIArray<ObItemType> &get_dist_methods() const { return dist_methods_; }
ObIArray<ObItemType> &get_dist_methods() { return dist_methods_; }
int set_pq_set_hint(const DistAlgo dist_algo, const int64_t child_num, const int64_t random_none_idx);
DistAlgo get_dist_algo(int64_t &random_none_idx) const { return get_dist_algo(dist_methods_, random_none_idx); }
uint64_t get_dist_algo(int64_t &random_none_idx) const { return get_dist_algo(dist_methods_, random_none_idx); }
const ObString &get_left_branch() const { return left_branch_; }
void set_left_branch(const ObString &left_branch) { return left_branch_.assign_ptr(left_branch.ptr(), left_branch.length()); }
INHERIT_TO_STRING_KV("ObHint", ObHint, K_(dist_methods), K_(left_branch));

View File

@ -2052,9 +2052,9 @@ SetAlgo ObLogPlanHint::get_valid_set_algo() const
return set_algo;
}
DistAlgo ObLogPlanHint::get_valid_set_dist_algo(int64_t *random_none_idx /* default NULL */ ) const
uint64_t ObLogPlanHint::get_valid_set_dist_algo(int64_t *random_none_idx /* default NULL */ ) const
{
DistAlgo set_dist_algo = DistAlgo::DIST_INVALID_METHOD;
uint64_t set_dist_algo = DistAlgo::DIST_INVALID_METHOD;
const ObPQSetHint *pq_set_hint = static_cast<const ObPQSetHint*>(get_normal_hint(T_PQ_SET));
if (NULL == pq_set_hint) {
set_dist_algo = is_outline_data_ ? DistAlgo::DIST_BASIC_METHOD

View File

@ -471,7 +471,7 @@ struct ObLogPlanHint
const LogJoinHint* get_join_hint(const ObRelIds &join_tables) const;
const ObIArray<LogJoinHint> &get_join_hints() const { return join_hints_; }
SetAlgo get_valid_set_algo() const;
DistAlgo get_valid_set_dist_algo(int64_t *random_none_idx = NULL) const;
uint64_t get_valid_set_dist_algo(int64_t *random_none_idx = NULL) const;
int check_valid_set_left_branch(const ObSelectStmt *select_stmt,
bool &hint_valid,
bool &need_swap) const;