[scn] fix failure of mittest after refresh feature scn
This commit is contained in:
@ -75,7 +75,6 @@ int ObSelectLogPlan::candi_allocate_group_by()
|
||||
bool having_has_rownum = false;
|
||||
const ObSelectStmt *stmt = NULL;
|
||||
ObLogicalOperator *best_plan = NULL;
|
||||
ObSEArray<ObRawExpr*, 4> reduce_exprs;
|
||||
ObSEArray<ObRawExpr*, 4> group_by_exprs;
|
||||
ObSEArray<ObRawExpr*, 4> rollup_exprs;
|
||||
ObSEArray<ObOrderDirection, 4> group_by_directions;
|
||||
@ -115,7 +114,6 @@ int ObSelectLogPlan::candi_allocate_group_by()
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(best_plan), K(ret));
|
||||
} else if (OB_FAIL(get_groupby_rollup_exprs(best_plan,
|
||||
reduce_exprs,
|
||||
group_by_exprs,
|
||||
rollup_exprs,
|
||||
group_by_directions,
|
||||
@ -135,8 +133,7 @@ int ObSelectLogPlan::candi_allocate_group_by()
|
||||
LOG_WARN("failed to allocate filter", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
} else {
|
||||
if (OB_FAIL(candi_allocate_normal_group_by(reduce_exprs,
|
||||
group_by_exprs,
|
||||
if (OB_FAIL(candi_allocate_normal_group_by(group_by_exprs,
|
||||
group_by_directions,
|
||||
rollup_exprs,
|
||||
rollup_directions,
|
||||
@ -156,7 +153,6 @@ int ObSelectLogPlan::candi_allocate_group_by()
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::get_groupby_rollup_exprs(const ObLogicalOperator *top,
|
||||
ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
ObIArray<ObRawExpr *> &group_by_exprs,
|
||||
common::ObIArray<ObRawExpr *> &rollup_exprs,
|
||||
ObIArray<ObOrderDirection> &group_directions,
|
||||
@ -164,8 +160,8 @@ int ObSelectLogPlan::get_groupby_rollup_exprs(const ObLogicalOperator *top,
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// gather all group by columns
|
||||
ObSEArray<ObRawExpr *, 8> candi_group_exprs;
|
||||
const ObSelectStmt *stmt = get_stmt();
|
||||
reduce_exprs.reuse();
|
||||
if (OB_ISNULL(stmt) || OB_ISNULL(top)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), K(stmt), K(top));
|
||||
@ -186,7 +182,7 @@ int ObSelectLogPlan::get_groupby_rollup_exprs(const ObLogicalOperator *top,
|
||||
&& !group_expr->has_flag(CNT_SUB_QUERY)
|
||||
&& !group_expr->get_expr_levels().has_member(stmt->get_current_level()))) {
|
||||
//no need to group a const expr, skip it
|
||||
} else if (OB_FAIL(reduce_exprs.push_back(group_expr))) {
|
||||
} else if (OB_FAIL(candi_group_exprs.push_back(group_expr))) {
|
||||
LOG_WARN("failed to push array", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
@ -194,7 +190,7 @@ int ObSelectLogPlan::get_groupby_rollup_exprs(const ObLogicalOperator *top,
|
||||
if (OB_FAIL(ObOptimizerUtil::simplify_exprs(top->get_fd_item_set(),
|
||||
top->get_output_equal_sets(),
|
||||
top->get_output_const_exprs(),
|
||||
reduce_exprs,
|
||||
candi_group_exprs,
|
||||
group_by_exprs))) {
|
||||
LOG_WARN("failed to simplify group exprs", K(ret));
|
||||
} else if (OB_FAIL(ObOptimizerUtil::find_stmt_expr_direction(*stmt,
|
||||
@ -218,14 +214,13 @@ int ObSelectLogPlan::get_groupby_rollup_exprs(const ObLogicalOperator *top,
|
||||
} // do nothing
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
LOG_TRACE("succeed to get group by exprs and rollup exprs", K(reduce_exprs), K(group_by_exprs), K(rollup_exprs));
|
||||
LOG_TRACE("succeed to get group by exprs and rollup exprs", K(group_by_exprs), K(rollup_exprs));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
const ObIArray<ObOrderDirection> &group_directions,
|
||||
const ObIArray<ObRawExpr*> &rollup_exprs,
|
||||
const ObIArray<ObOrderDirection> &rollup_directions,
|
||||
@ -243,8 +238,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
groupby_helper))) {
|
||||
LOG_WARN("failed to init group by helper", K(ret));
|
||||
} else if (groupby_helper.can_three_stage_pushdown_) {
|
||||
if (OB_FAIL(candi_allocate_three_stage_group_by(reduce_exprs,
|
||||
group_by_exprs,
|
||||
if (OB_FAIL(candi_allocate_three_stage_group_by(group_by_exprs,
|
||||
group_directions,
|
||||
rollup_exprs,
|
||||
rollup_directions,
|
||||
@ -255,8 +249,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
groupby_plans))) {
|
||||
LOG_WARN("failed to candi allocate three stage group by", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(candi_allocate_normal_group_by(reduce_exprs,
|
||||
group_by_exprs,
|
||||
} else if (OB_FAIL(candi_allocate_normal_group_by(group_by_exprs,
|
||||
group_directions,
|
||||
rollup_exprs,
|
||||
rollup_directions,
|
||||
@ -271,8 +264,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
LOG_TRACE("succeed to allocate group by using hint", K(groupby_plans.count()), K(groupby_helper));
|
||||
} else if (OB_FAIL(get_log_plan_hint().check_status())) {
|
||||
LOG_WARN("failed to generate plans with hint", K(ret));
|
||||
} else if (OB_FAIL(candi_allocate_normal_group_by(reduce_exprs,
|
||||
group_by_exprs,
|
||||
} else if (OB_FAIL(candi_allocate_normal_group_by(group_by_exprs,
|
||||
group_directions,
|
||||
rollup_exprs,
|
||||
rollup_directions,
|
||||
@ -304,8 +296,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
}
|
||||
|
||||
// create three-stage push down plan
|
||||
int ObSelectLogPlan::candi_allocate_three_stage_group_by(const ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
int ObSelectLogPlan::candi_allocate_three_stage_group_by(const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
const ObIArray<ObOrderDirection> &group_directions,
|
||||
const ObIArray<ObRawExpr*> &rollup_exprs,
|
||||
const ObIArray<ObOrderDirection> &rollup_directions,
|
||||
@ -328,14 +319,13 @@ int ObSelectLogPlan::candi_allocate_three_stage_group_by(const ObIArray<ObRawExp
|
||||
if (OB_ISNULL(candidate_plan.plan_tree_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (candidate_plan.plan_tree_->is_distributed() && !reduce_exprs.empty() &&
|
||||
OB_FAIL(candidate_plan.plan_tree_->check_sharding_compatible_with_reduce_expr(reduce_exprs,
|
||||
} else if (candidate_plan.plan_tree_->is_distributed() && !group_by_exprs.empty() &&
|
||||
OB_FAIL(candidate_plan.plan_tree_->check_sharding_compatible_with_reduce_expr(group_by_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) {
|
||||
bool can_ignore_merge_plan = !(groupby_plans.empty() || groupby_helper.force_use_merge_);
|
||||
if (OB_FAIL(create_merge_group_plan(reduce_exprs,
|
||||
group_by_exprs,
|
||||
if (OB_FAIL(create_merge_group_plan(group_by_exprs,
|
||||
group_directions,
|
||||
rollup_exprs,
|
||||
rollup_directions,
|
||||
@ -389,12 +379,19 @@ int ObSelectLogPlan::get_valid_aggr_algo(const ObIArray<ObRawExpr*> &group_by_ex
|
||||
//group_concat and distinct aggregation hold all input rows temporary,
|
||||
//too much memory consumption for hash aggregate.
|
||||
use_hash_valid = false;
|
||||
} else if (OB_FAIL(session->get_sys_variable(share::SYS_VAR_OB_ENABLE_HASH_GROUP_BY, val))) {
|
||||
LOG_WARN("Get sys variable error", K(ret));
|
||||
} else if (!val.get_bool()) {
|
||||
if (!ignore_hint && groupby_helper.force_use_hash_) {
|
||||
// has use_hash_aggregation hint
|
||||
} else {
|
||||
use_hash_valid = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
const ObIArray<ObOrderDirection> &group_directions,
|
||||
const ObIArray<ObRawExpr*> &rollup_exprs,
|
||||
const ObIArray<ObOrderDirection> &rollup_directions,
|
||||
@ -421,8 +418,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < best_plans.count(); i++) {
|
||||
candidate_plan = best_plans.at(i);
|
||||
if (OB_FAIL(create_hash_group_plan(reduce_exprs,
|
||||
group_by_exprs,
|
||||
if (OB_FAIL(create_hash_group_plan(group_by_exprs,
|
||||
rollup_exprs,
|
||||
aggr_items,
|
||||
having_exprs,
|
||||
@ -445,7 +441,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
bool is_needed = false;
|
||||
bool is_plan_valid = true;
|
||||
if (OB_FAIL(should_create_rollup_pushdown_plan(candidate_plan.plan_tree_,
|
||||
reduce_exprs,
|
||||
group_by_exprs,
|
||||
rollup_exprs,
|
||||
groupby_helper,
|
||||
is_needed))) {
|
||||
@ -459,8 +455,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
candidate_plan.plan_tree_))) {
|
||||
LOG_WARN("failed to create rollup pushdown plan", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(create_merge_group_plan(reduce_exprs,
|
||||
group_by_exprs,
|
||||
} else if (OB_FAIL(create_merge_group_plan(group_by_exprs,
|
||||
group_directions,
|
||||
rollup_exprs,
|
||||
rollup_directions,
|
||||
@ -484,7 +479,7 @@ int ObSelectLogPlan::candi_allocate_normal_group_by(const ObIArray<ObRawExpr*> &
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::should_create_rollup_pushdown_plan(ObLogicalOperator *top,
|
||||
const ObIArray<ObRawExpr *> &reduce_exprs,
|
||||
const ObIArray<ObRawExpr *> &group_by_exprs,
|
||||
const ObIArray<ObRawExpr *> &rollup_exprs,
|
||||
GroupingOpHelper &groupby_helper,
|
||||
bool &is_needed)
|
||||
@ -499,7 +494,7 @@ int ObSelectLogPlan::should_create_rollup_pushdown_plan(ObLogicalOperator *top,
|
||||
} else if (rollup_exprs.empty() || !groupby_helper.can_rollup_pushdown_) {
|
||||
// do nothing
|
||||
} else if (top->is_distributed() &&
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(group_by_exprs,
|
||||
is_partition_wise))) {
|
||||
LOG_WARN("failed to check is partition wise", K(ret));
|
||||
} else if (!top->is_distributed() || is_partition_wise ) {
|
||||
@ -635,8 +630,7 @@ LOG_WARN("failed to set rollup id expr", K(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::create_hash_group_plan(const ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
int ObSelectLogPlan::create_hash_group_plan(const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
const ObIArray<ObRawExpr*> &rollup_exprs,
|
||||
const ObIArray<ObAggFunRawExpr*> &aggr_items,
|
||||
const ObIArray<ObRawExpr*> &having_exprs,
|
||||
@ -652,7 +646,7 @@ int ObSelectLogPlan::create_hash_group_plan(const ObIArray<ObRawExpr*> &reduce_e
|
||||
LOG_WARN("get unexpected null", K(top), K(get_stmt()), K(ret));
|
||||
} else if (OB_FALSE_IT(origin_child_card = top->get_card())) {
|
||||
} else if (top->is_distributed() &&
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(group_by_exprs,
|
||||
is_partition_wise))) {
|
||||
LOG_WARN("failed to check if sharding compatible", K(ret));
|
||||
} else if (!top->is_distributed() || is_partition_wise) {
|
||||
@ -699,166 +693,165 @@ int ObSelectLogPlan::create_hash_group_plan(const ObIArray<ObRawExpr*> &reduce_e
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
|
||||
// allocate exchange
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExchangeInfo exch_info;
|
||||
if (OB_FAIL(get_grouping_style_exchange_info(group_by_exprs,
|
||||
top->get_output_equal_sets(),
|
||||
exch_info))) {
|
||||
LOG_WARN("failed to get grouping style exchange info", K(ret));
|
||||
} else if (OB_FAIL(allocate_exchange_as_top(top, exch_info))) {
|
||||
LOG_WARN("failed to allocate exchange as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
// allocate final group by
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(allocate_group_by_as_top(top,
|
||||
AggregateAlgo::HASH_AGGREGATE,
|
||||
group_by_exprs,
|
||||
rollup_exprs,
|
||||
aggr_items,
|
||||
having_exprs,
|
||||
is_from_povit,
|
||||
groupby_helper.group_ndv_,
|
||||
origin_child_card))) {
|
||||
LOG_WARN("failed to allocate scala group by as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
// allocate exchange
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExchangeInfo exch_info;
|
||||
if (OB_FAIL(get_grouping_style_exchange_info(group_by_exprs,
|
||||
top->get_output_equal_sets(),
|
||||
exch_info))) {
|
||||
LOG_WARN("failed to get grouping style exchange info", K(ret));
|
||||
} else if (OB_FAIL(allocate_exchange_as_top(top, exch_info))) {
|
||||
LOG_WARN("failed to allocate exchange as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
// allocate final group by
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(allocate_group_by_as_top(top,
|
||||
AggregateAlgo::HASH_AGGREGATE,
|
||||
group_by_exprs,
|
||||
rollup_exprs,
|
||||
aggr_items,
|
||||
having_exprs,
|
||||
is_from_povit,
|
||||
groupby_helper.group_ndv_,
|
||||
origin_child_card))) {
|
||||
LOG_WARN("failed to allocate scala group by as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::allocate_topk_for_hash_group_plan(ObLogicalOperator *&top)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSEArray<ObRawExpr*, 16> order_by_exprs;
|
||||
ObSEArray<ObOrderDirection, 16> directions;
|
||||
const ObSelectStmt *select_stmt = NULL;
|
||||
const ObGlobalHint &global_hint = get_optimizer_context().get_global_hint();
|
||||
if (OB_ISNULL(top) || OB_ISNULL(select_stmt = get_stmt())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(top), K(select_stmt), K(ret));
|
||||
} else if (!select_stmt->is_match_topk()) {
|
||||
/*do nothing*/
|
||||
} else if (OB_FAIL(get_order_by_exprs(top, order_by_exprs, &directions))) {
|
||||
LOG_WARN("failed to get order by exprs", K(ret));
|
||||
} else if (order_by_exprs.empty()) {
|
||||
// no need order by, directly allocate topk
|
||||
if (OB_FAIL(allocate_topk_as_top(top,
|
||||
select_stmt->get_limit_expr(),
|
||||
select_stmt->get_offset_expr(),
|
||||
global_hint.sharding_minimum_row_count_,
|
||||
global_hint.topk_precision_))) {
|
||||
LOG_WARN("failed to allocate topk as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
} else {
|
||||
// allocate sort
|
||||
ObSEArray<OrderItem, 8> sort_keys;
|
||||
ObSEArray<OrderItem, 8> topk_sort_keys;
|
||||
if (OB_FAIL(make_order_items(order_by_exprs, directions, sort_keys))) {
|
||||
LOG_WARN("failed to make order items", K(ret));
|
||||
} else if (OB_FAIL(clone_sort_keys_for_topk(sort_keys,
|
||||
topk_sort_keys))) {
|
||||
LOG_WARN("failed to clone sort keys for topk", K(ret));
|
||||
} else if (OB_FAIL(allocate_topk_sort_as_top(top,
|
||||
topk_sort_keys,
|
||||
select_stmt->get_limit_expr(),
|
||||
select_stmt->get_offset_expr(),
|
||||
global_hint.sharding_minimum_row_count_,
|
||||
global_hint.topk_precision_))) {
|
||||
LOG_WARN("failed to allocate topk sort as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
return ret;
|
||||
int ret = OB_SUCCESS;
|
||||
ObSEArray<ObRawExpr*, 16> order_by_exprs;
|
||||
ObSEArray<ObOrderDirection, 16> directions;
|
||||
const ObSelectStmt *select_stmt = NULL;
|
||||
const ObGlobalHint &global_hint = get_optimizer_context().get_global_hint();
|
||||
if (OB_ISNULL(top) || OB_ISNULL(select_stmt = get_stmt())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(top), K(select_stmt), K(ret));
|
||||
} else if (!select_stmt->is_match_topk()) {
|
||||
/*do nothing*/
|
||||
} else if (OB_FAIL(get_order_by_exprs(top, order_by_exprs, &directions))) {
|
||||
LOG_WARN("failed to get order by exprs", K(ret));
|
||||
} else if (order_by_exprs.empty()) {
|
||||
// no need order by, directly allocate topk
|
||||
if (OB_FAIL(allocate_topk_as_top(top,
|
||||
select_stmt->get_limit_expr(),
|
||||
select_stmt->get_offset_expr(),
|
||||
global_hint.sharding_minimum_row_count_,
|
||||
global_hint.topk_precision_))) {
|
||||
LOG_WARN("failed to allocate topk as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
} else {
|
||||
// allocate sort
|
||||
ObSEArray<OrderItem, 8> sort_keys;
|
||||
ObSEArray<OrderItem, 8> topk_sort_keys;
|
||||
if (OB_FAIL(make_order_items(order_by_exprs, directions, sort_keys))) {
|
||||
LOG_WARN("failed to make order items", K(ret));
|
||||
} else if (OB_FAIL(clone_sort_keys_for_topk(sort_keys,
|
||||
topk_sort_keys))) {
|
||||
LOG_WARN("failed to clone sort keys for topk", K(ret));
|
||||
} else if (OB_FAIL(allocate_topk_sort_as_top(top,
|
||||
topk_sort_keys,
|
||||
select_stmt->get_limit_expr(),
|
||||
select_stmt->get_offset_expr(),
|
||||
global_hint.sharding_minimum_row_count_,
|
||||
global_hint.topk_precision_))) {
|
||||
LOG_WARN("failed to allocate topk sort as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::allocate_topk_sort_as_top(ObLogicalOperator *&top,
|
||||
const ObIArray<OrderItem> &sort_keys,
|
||||
ObRawExpr *limit_expr,
|
||||
ObRawExpr *offset_expr,
|
||||
int64_t minimum_row_count,
|
||||
int64_t topk_precision)
|
||||
const ObIArray<OrderItem> &sort_keys,
|
||||
ObRawExpr *limit_expr,
|
||||
ObRawExpr *offset_expr,
|
||||
int64_t minimum_row_count,
|
||||
int64_t topk_precision)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObLogSort *sort = NULL;
|
||||
if (OB_ISNULL(top) || OB_ISNULL(limit_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(top), K(limit_expr), K(ret));
|
||||
} else if (OB_ISNULL(sort = static_cast<ObLogSort*>(get_log_op_factory().allocate(*this, LOG_SORT)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_ERROR("failed to allocate sort for order by", K(ret));
|
||||
} else {
|
||||
sort->set_child(ObLogicalOperator::first_child, top);
|
||||
sort->set_topk_limit_expr(limit_expr);
|
||||
sort->set_topk_offset_expr(offset_expr);
|
||||
sort->set_minimal_row_count(minimum_row_count);
|
||||
sort->set_topk_precision(topk_precision);
|
||||
if (OB_FAIL(sort->set_sort_keys(sort_keys))) {
|
||||
LOG_WARN("failed to set sort keys", K(ret));
|
||||
} else if (OB_FAIL(sort->compute_property())) {
|
||||
LOG_WARN("failed to compute property", K(ret));
|
||||
} else {
|
||||
top = sort;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
int ret = OB_SUCCESS;
|
||||
ObLogSort *sort = NULL;
|
||||
if (OB_ISNULL(top) || OB_ISNULL(limit_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(top), K(limit_expr), K(ret));
|
||||
} else if (OB_ISNULL(sort = static_cast<ObLogSort*>(get_log_op_factory().allocate(*this, LOG_SORT)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_ERROR("failed to allocate sort for order by", K(ret));
|
||||
} else {
|
||||
sort->set_child(ObLogicalOperator::first_child, top);
|
||||
sort->set_topk_limit_expr(limit_expr);
|
||||
sort->set_topk_offset_expr(offset_expr);
|
||||
sort->set_minimal_row_count(minimum_row_count);
|
||||
sort->set_topk_precision(topk_precision);
|
||||
if (OB_FAIL(sort->set_sort_keys(sort_keys))) {
|
||||
LOG_WARN("failed to set sort keys", K(ret));
|
||||
} else if (OB_FAIL(sort->compute_property())) {
|
||||
LOG_WARN("failed to compute property", K(ret));
|
||||
} else {
|
||||
top = sort;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::clone_sort_keys_for_topk(const ObIArray<OrderItem> &sort_keys,
|
||||
ObIArray<OrderItem> &topk_sort_keys)
|
||||
ObIArray<OrderItem> &topk_sort_keys)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < sort_keys.count(); ++i) {
|
||||
ObRawExpr *new_sort_expr = NULL;
|
||||
if (OB_FAIL(ObOptimizerUtil::clone_expr_for_topk(get_optimizer_context().get_expr_factory(),
|
||||
sort_keys.at(i).expr_,
|
||||
new_sort_expr))) {
|
||||
LOG_WARN("failed to copy expr", K(ret));
|
||||
} else if (OB_ISNULL(new_sort_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(new_sort_expr), K(ret));
|
||||
} else {
|
||||
OrderItem new_order_item;
|
||||
new_order_item.expr_ = new_sort_expr;
|
||||
new_order_item.order_type_ = sort_keys.at(i).order_type_;
|
||||
if (OB_FAIL(topk_sort_keys.push_back(new_order_item))) {
|
||||
LOG_WARN("failed to push back order_item", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
int ret = OB_SUCCESS;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < sort_keys.count(); ++i) {
|
||||
ObRawExpr *new_sort_expr = NULL;
|
||||
if (OB_FAIL(ObOptimizerUtil::clone_expr_for_topk(get_optimizer_context().get_expr_factory(),
|
||||
sort_keys.at(i).expr_,
|
||||
new_sort_expr))) {
|
||||
LOG_WARN("failed to copy expr", K(ret));
|
||||
} else if (OB_ISNULL(new_sort_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(new_sort_expr), K(ret));
|
||||
} else {
|
||||
OrderItem new_order_item;
|
||||
new_order_item.expr_ = new_sort_expr;
|
||||
new_order_item.order_type_ = sort_keys.at(i).order_type_;
|
||||
if (OB_FAIL(topk_sort_keys.push_back(new_order_item))) {
|
||||
LOG_WARN("failed to push back order_item", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::allocate_topk_as_top(ObLogicalOperator *&top,
|
||||
ObRawExpr *topk_limit_count,
|
||||
ObRawExpr *topk_limit_offset,
|
||||
int64_t minimum_row_count,
|
||||
int64_t topk_precision)
|
||||
ObRawExpr *topk_limit_count,
|
||||
ObRawExpr *topk_limit_offset,
|
||||
int64_t minimum_row_count,
|
||||
int64_t topk_precision)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObLogTopk *topk_op = NULL;
|
||||
if (OB_ISNULL(top)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (OB_ISNULL(topk_op = static_cast<ObLogTopk*>(log_op_factory_.allocate(
|
||||
*this, log_op_def::LOG_TOPK)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed to allocate topk operator", K(ret));
|
||||
} else {
|
||||
topk_op->set_child(ObLogicalOperator::first_child, top);
|
||||
topk_op->set_topk_params(topk_limit_count, topk_limit_offset,
|
||||
minimum_row_count, topk_precision);
|
||||
if (OB_FAIL(topk_op->compute_property())) {
|
||||
LOG_WARN("failed to compute property", K(ret));
|
||||
} else {
|
||||
top = topk_op;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
int ret = OB_SUCCESS;
|
||||
ObLogTopk *topk_op = NULL;
|
||||
if (OB_ISNULL(top)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (OB_ISNULL(topk_op = static_cast<ObLogTopk*>(log_op_factory_.allocate(
|
||||
*this, log_op_def::LOG_TOPK)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed to allocate topk operator", K(ret));
|
||||
} else {
|
||||
topk_op->set_child(ObLogicalOperator::first_child, top);
|
||||
topk_op->set_topk_params(topk_limit_count, topk_limit_offset,
|
||||
minimum_row_count, topk_precision);
|
||||
if (OB_FAIL(topk_op->compute_property())) {
|
||||
LOG_WARN("failed to compute property", K(ret));
|
||||
} else {
|
||||
top = topk_op;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::create_merge_group_plan(const ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
int ObSelectLogPlan::create_merge_group_plan(const ObIArray<ObRawExpr*> &group_by_exprs,
|
||||
const ObIArray<ObOrderDirection> &group_directions,
|
||||
const ObIArray<ObRawExpr*> &rollup_exprs,
|
||||
const ObIArray<ObOrderDirection> &rollup_directions,
|
||||
@ -933,7 +926,7 @@ int ObSelectLogPlan::create_merge_group_plan(const ObIArray<ObRawExpr*> &reduce_
|
||||
// if need sort and no further op needs the output order, not generate merge groupby
|
||||
is_plan_valid = false;
|
||||
} else if (top->is_distributed() &&
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(group_by_exprs,
|
||||
is_partition_wise))) {
|
||||
LOG_WARN("failed to check if sharding compatiable with reduce expr", K(ret));
|
||||
} else if (!top->is_distributed() || is_partition_wise) {
|
||||
@ -1057,8 +1050,6 @@ int ObSelectLogPlan::generate_merge_group_sort_keys(ObLogicalOperator *top,
|
||||
if (OB_ISNULL(expr = rollup_exprs.at(i))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (T_FUN_SYS_REMOVE_CONST == expr->get_expr_type()) {
|
||||
/*do nothing*/
|
||||
} else if (OB_FAIL(ObOptimizerUtil::is_const_expr(expr,
|
||||
top->get_output_const_exprs(),
|
||||
is_const))) {
|
||||
@ -1174,7 +1165,6 @@ int ObSelectLogPlan::candi_allocate_distinct()
|
||||
bool is_unique = false;
|
||||
const ObSelectStmt *stmt = NULL;
|
||||
ObLogicalOperator *best_plan = NULL;
|
||||
ObSEArray<ObRawExpr*, 8> reduce_exprs;
|
||||
ObSEArray<ObRawExpr*, 8> distinct_exprs;
|
||||
ObSEArray<ObRawExpr*, 8> candi_subquery_exprs;
|
||||
|
||||
@ -1190,7 +1180,7 @@ int ObSelectLogPlan::candi_allocate_distinct()
|
||||
} else if (OB_ISNULL(best_plan)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (OB_FAIL(get_distinct_exprs(best_plan, reduce_exprs, distinct_exprs))) {
|
||||
} else if (OB_FAIL(get_distinct_exprs(best_plan, distinct_exprs))) {
|
||||
LOG_WARN("failed to get select columns", K(ret));
|
||||
} else if (distinct_exprs.empty()) {
|
||||
// if all the distinct exprs are const, we add limit operator instead of distinct operator
|
||||
@ -1235,7 +1225,6 @@ int ObSelectLogPlan::candi_allocate_distinct()
|
||||
candidate_plan = best_candidates.at(i);
|
||||
if (OB_FAIL(create_hash_distinct_plan(candidate_plan.plan_tree_,
|
||||
distinct_helper,
|
||||
reduce_exprs,
|
||||
distinct_exprs))) {
|
||||
LOG_WARN("failed to create hash distinct plan", K(ret));
|
||||
} else if (OB_FAIL(distinct_plans.push_back(candidate_plan))) {
|
||||
@ -1253,7 +1242,6 @@ int ObSelectLogPlan::candi_allocate_distinct()
|
||||
candidate_plan = candidates_.candidate_plans_.at(i);
|
||||
if (OB_FAIL(create_merge_distinct_plan(candidate_plan.plan_tree_,
|
||||
distinct_helper,
|
||||
reduce_exprs,
|
||||
distinct_exprs,
|
||||
distinct_directions,
|
||||
is_plan_valid,
|
||||
@ -1278,17 +1266,16 @@ int ObSelectLogPlan::candi_allocate_distinct()
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::get_distinct_exprs(const ObLogicalOperator *top,
|
||||
ObIArray<ObRawExpr *> &reduce_exprs,
|
||||
ObIArray<ObRawExpr *> &distinct_exprs)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObSelectStmt *select_stmt = get_stmt();
|
||||
reduce_exprs.reuse();
|
||||
if (OB_ISNULL(select_stmt) || OB_ISNULL(top)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(select_stmt), K(top), K(ret));
|
||||
} else {
|
||||
ObRawExpr *select_expr = NULL;
|
||||
ObSEArray<ObRawExpr *, 8> candi_exprs;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < select_stmt->get_select_item_size(); ++i) {
|
||||
bool is_const = false;
|
||||
select_expr = select_stmt->get_select_item(i).expr_;
|
||||
@ -1302,7 +1289,7 @@ int ObSelectLogPlan::get_distinct_exprs(const ObLogicalOperator *top,
|
||||
LOG_WARN("failed to check whether is const expr", K(ret));
|
||||
} else if (is_const) {
|
||||
//skip it
|
||||
} else if (OB_FAIL(reduce_exprs.push_back(select_expr))) {
|
||||
} else if (OB_FAIL(candi_exprs.push_back(select_expr))) {
|
||||
LOG_WARN("push expr to distinct exprs failed", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
@ -1311,7 +1298,7 @@ int ObSelectLogPlan::get_distinct_exprs(const ObLogicalOperator *top,
|
||||
} else if (OB_FAIL(ObOptimizerUtil::simplify_exprs(top->get_fd_item_set(),
|
||||
top->get_output_equal_sets(),
|
||||
top->get_output_const_exprs(),
|
||||
reduce_exprs,
|
||||
candi_exprs,
|
||||
distinct_exprs))) {
|
||||
LOG_WARN("failed to simplify exprs", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
@ -1321,7 +1308,6 @@ int ObSelectLogPlan::get_distinct_exprs(const ObLogicalOperator *top,
|
||||
|
||||
int ObSelectLogPlan::create_hash_distinct_plan(ObLogicalOperator *&top,
|
||||
GroupingOpHelper &distinct_helper,
|
||||
ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
ObIArray<ObRawExpr*> &distinct_exprs)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -1331,7 +1317,7 @@ int ObSelectLogPlan::create_hash_distinct_plan(ObLogicalOperator *&top,
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(top), K(ret));
|
||||
} else if (top->is_distributed() &&
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(distinct_exprs,
|
||||
is_partition_wise))) {
|
||||
LOG_WARN("failed to check sharding compatible with reduce expr", K(ret));
|
||||
} else if (!top->is_distributed() || is_partition_wise) {
|
||||
@ -1367,7 +1353,6 @@ int ObSelectLogPlan::create_hash_distinct_plan(ObLogicalOperator *&top,
|
||||
|
||||
int ObSelectLogPlan::create_merge_distinct_plan(ObLogicalOperator *&top,
|
||||
GroupingOpHelper &distinct_helper,
|
||||
ObIArray<ObRawExpr*> &reduce_exprs,
|
||||
ObIArray<ObRawExpr*> &distinct_exprs,
|
||||
ObIArray<ObOrderDirection> &directions,
|
||||
bool &is_plan_valid,
|
||||
@ -1412,7 +1397,7 @@ int ObSelectLogPlan::create_merge_distinct_plan(ObLogicalOperator *&top,
|
||||
// if no further order needed, not generate merge style distinct
|
||||
is_plan_valid = false;
|
||||
} else if (top->is_distributed() &&
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(reduce_exprs,
|
||||
OB_FAIL(top->check_sharding_compatible_with_reduce_expr(distinct_exprs,
|
||||
is_partition_wise))) {
|
||||
LOG_WARN("failed to check sharding compatiable with reduce exprs", K(ret));
|
||||
} else if (!top->is_distributed() || is_partition_wise) {
|
||||
@ -2220,6 +2205,10 @@ int ObSelectLogPlan::create_recursive_union_all_plan(ObLogicalOperator *left_chi
|
||||
} else if (is_basic) {
|
||||
if (DistAlgo::DIST_BASIC_METHOD & set_dist_methods) {
|
||||
dist_set_method = DistAlgo::DIST_BASIC_METHOD;
|
||||
if (right_child->is_local() &&
|
||||
OB_FAIL(adjust_recursive_cte_plan(right_child->get_child_list()))) {
|
||||
LOG_WARN("failed to adjust recursive cte plan", K(ret));
|
||||
}
|
||||
}
|
||||
} else if (DistAlgo::DIST_PULL_TO_LOCAL & set_dist_methods) {
|
||||
// pull to local
|
||||
@ -2227,6 +2216,9 @@ int ObSelectLogPlan::create_recursive_union_all_plan(ObLogicalOperator *left_chi
|
||||
if (left_child->is_sharding()) {
|
||||
left_exch_info.dist_method_ = ObPQDistributeMethod::LOCAL;
|
||||
}
|
||||
if (OB_FAIL(adjust_recursive_cte_plan(right_child->get_child_list()))) {
|
||||
LOG_WARN("failed to adjust recurisve cte plan", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
if (OB_SUCC(ret) && DistAlgo::DIST_INVALID_METHOD != dist_set_method) {
|
||||
if (OB_FAIL(ObOptimizerUtil::check_need_sort(order_items,
|
||||
@ -2252,6 +2244,43 @@ int ObSelectLogPlan::create_recursive_union_all_plan(ObLogicalOperator *left_chi
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::adjust_recursive_cte_plan(ObIArray<ObLogicalOperator*> &child_ops)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObLogPlan *log_plan = NULL;
|
||||
ObExchangeInfo exch_info;
|
||||
int64_t fake_cte_pos = -1;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && fake_cte_pos == -1 && i < child_ops.count(); i++) {
|
||||
if (OB_ISNULL(child_ops.at(i))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (child_ops.at(i)->get_contains_fake_cte()) {
|
||||
fake_cte_pos = i;
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
if (OB_SUCC(ret) && fake_cte_pos != -1) {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < child_ops.count(); i++) {
|
||||
if (OB_ISNULL(child_ops.at(i)) || OB_ISNULL(log_plan = child_ops.at(i)->get_plan())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (i == fake_cte_pos) {
|
||||
if (OB_FAIL(SMART_CALL(adjust_recursive_cte_plan(child_ops.at(i)->get_child_list())))) {
|
||||
LOG_WARN("failed to adjust recursive cte plan", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
} else if (child_ops.at(i)->is_sharding() &&
|
||||
OB_FAIL(log_plan->allocate_exchange_as_top(child_ops.at(i),
|
||||
exch_info))) {
|
||||
LOG_WARN("failed to allocate exchange", K(ret));
|
||||
} else if (log_op_def::LOG_MATERIAL != child_ops.at(i)->get_type() &&
|
||||
log_op_def::LOG_TABLE_SCAN != child_ops.at(i)->get_type() &&
|
||||
OB_FAIL(log_plan->allocate_material_as_top(child_ops.at(i)))) {
|
||||
LOG_WARN("failed to allocate materialize as top", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::allocate_recursive_union_all_as_top(ObLogicalOperator *left_child,
|
||||
ObLogicalOperator *right_child,
|
||||
DistAlgo dist_set_method,
|
||||
@ -2572,8 +2601,11 @@ bool ObSelectLogPlan::is_set_partition_wise_valid(const ObLogicalOperator &left_
|
||||
const ObLogicalOperator &right_plan)
|
||||
{
|
||||
bool is_valid = true;
|
||||
if ((left_plan.is_exchange_allocated() || right_plan.is_exchange_allocated()) &&
|
||||
(left_plan.get_contains_pw_merge_op() || right_plan.get_contains_pw_merge_op())) {
|
||||
if (left_plan.is_exchange_allocated() && !right_plan.is_exchange_allocated() &&
|
||||
right_plan.get_contains_merge_op()) {
|
||||
is_valid = false;
|
||||
} else if (!left_plan.is_exchange_allocated() &&
|
||||
right_plan.is_exchange_allocated() && left_plan.get_contains_merge_op()) {
|
||||
is_valid = false;
|
||||
} else { /*do nothing*/ }
|
||||
return is_valid;
|
||||
@ -2632,11 +2664,6 @@ int ObSelectLogPlan::generate_merge_set_plans(const EqualSets &equal_sets,
|
||||
ObSEArray<ObSEArray<MergeKeyInfo*, 8>, 8> right_merge_keys;
|
||||
bool force_merge = MERGE_SET == get_log_plan_hint().get_valid_set_algo();
|
||||
bool can_ignore_merge_plan = !(no_hash_plans || (!ignore_hint && force_merge));
|
||||
bool no_swap = false;
|
||||
bool swap = false;
|
||||
if (OB_FAIL(get_allowed_branch_order(ignore_hint, set_op, no_swap, swap))) {
|
||||
LOG_WARN("failed to get allowed branch order", K(ret));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < left_candidate_list.count(); i++) {
|
||||
merge_key_list.reuse();
|
||||
if (OB_FAIL(init_merge_set_structure(allocator,
|
||||
@ -2663,27 +2690,28 @@ int ObSelectLogPlan::generate_merge_set_plans(const EqualSets &equal_sets,
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < left_candidate_list.count(); i++) {
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < right_candidate_list.count(); j++) {
|
||||
if (no_swap && OB_FAIL(inner_generate_merge_set_plans(equal_sets,
|
||||
left_set_keys,
|
||||
right_set_keys,
|
||||
left_merge_keys.at(i),
|
||||
set_op,
|
||||
left_candidate_list.at(i),
|
||||
right_candidate_list.at(j),
|
||||
ignore_hint,
|
||||
no_hash_plans,
|
||||
merge_set_plans))) {
|
||||
if (OB_FAIL(inner_generate_merge_set_plans(equal_sets,
|
||||
left_set_keys,
|
||||
right_set_keys,
|
||||
left_merge_keys.at(i),
|
||||
set_op,
|
||||
left_candidate_list.at(i),
|
||||
right_candidate_list.at(j),
|
||||
ignore_hint,
|
||||
no_hash_plans,
|
||||
merge_set_plans))) {
|
||||
LOG_WARN("failed to generate merge set plans", K(ret));
|
||||
} else if (swap && OB_FAIL(inner_generate_merge_set_plans(equal_sets,
|
||||
right_set_keys,
|
||||
left_set_keys,
|
||||
right_merge_keys.at(j),
|
||||
set_op,
|
||||
right_candidate_list.at(j),
|
||||
left_candidate_list.at(i),
|
||||
ignore_hint,
|
||||
no_hash_plans,
|
||||
merge_set_plans))) {
|
||||
} else if (ObSelectStmt::EXCEPT != set_op &&
|
||||
OB_FAIL(inner_generate_merge_set_plans(equal_sets,
|
||||
right_set_keys,
|
||||
left_set_keys,
|
||||
right_merge_keys.at(j),
|
||||
set_op,
|
||||
right_candidate_list.at(j),
|
||||
left_candidate_list.at(i),
|
||||
ignore_hint,
|
||||
no_hash_plans,
|
||||
merge_set_plans))) {
|
||||
LOG_WARN("failed to inner generate merge set plans", K(ret));
|
||||
} else { /*do nothing*/}
|
||||
}
|
||||
@ -3027,31 +3055,6 @@ int ObSelectLogPlan::create_merge_set_plan(const EqualSets &equal_sets,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::get_allowed_branch_order(const bool ignore_hint,
|
||||
const ObSelectStmt::SetOperator set_op,
|
||||
bool &no_swap,
|
||||
bool &swap)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
no_swap = true;
|
||||
swap = ObSelectStmt::EXCEPT != set_op;
|
||||
bool hint_valid = false;
|
||||
bool need_swap = false;
|
||||
if (ignore_hint) {
|
||||
/* do nothing */
|
||||
} else if (OB_FAIL(get_log_plan_hint().check_valid_set_left_branch(get_stmt(),
|
||||
hint_valid,
|
||||
need_swap))) {
|
||||
LOG_WARN("failed to check valid set left branch", K(ret));
|
||||
} else if (!hint_valid) {
|
||||
/* do nothing */
|
||||
} else {
|
||||
no_swap &= !need_swap;
|
||||
swap &= need_swap;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectLogPlan::generate_hash_set_plans(const EqualSets &equal_sets,
|
||||
const ObIArray<ObRawExpr*> &left_set_keys,
|
||||
const ObIArray<ObRawExpr*> &right_set_keys,
|
||||
@ -3062,27 +3065,24 @@ int ObSelectLogPlan::generate_hash_set_plans(const EqualSets &equal_sets,
|
||||
ObIArray<CandidatePlan> &hash_set_plans)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool no_swap = false;
|
||||
bool swap = false;
|
||||
if (OB_FAIL(get_allowed_branch_order(ignore_hint, set_op, no_swap, swap))) {
|
||||
LOG_WARN("failed to get allowed branch order", K(ret));
|
||||
} else if (no_swap && OB_FAIL(inner_generate_hash_set_plans(equal_sets,
|
||||
left_set_keys,
|
||||
right_set_keys,
|
||||
set_op,
|
||||
left_best_plans,
|
||||
right_best_plans,
|
||||
ignore_hint,
|
||||
hash_set_plans))) {
|
||||
if (OB_FAIL(inner_generate_hash_set_plans(equal_sets,
|
||||
left_set_keys,
|
||||
right_set_keys,
|
||||
set_op,
|
||||
left_best_plans,
|
||||
right_best_plans,
|
||||
ignore_hint,
|
||||
hash_set_plans))) {
|
||||
LOG_WARN("failed to generate hash set plans", K(ret));
|
||||
} else if (swap && OB_FAIL(inner_generate_hash_set_plans(equal_sets,
|
||||
right_set_keys,
|
||||
left_set_keys,
|
||||
set_op,
|
||||
right_best_plans,
|
||||
left_best_plans,
|
||||
ignore_hint,
|
||||
hash_set_plans))) {
|
||||
} else if (ObSelectStmt::EXCEPT != set_op &&
|
||||
OB_FAIL(inner_generate_hash_set_plans(equal_sets,
|
||||
right_set_keys,
|
||||
left_set_keys,
|
||||
set_op,
|
||||
right_best_plans,
|
||||
left_best_plans,
|
||||
ignore_hint,
|
||||
hash_set_plans))) {
|
||||
LOG_WARN("failed to generate hash set plans", K(ret));
|
||||
} else { /*do nothing*/ }
|
||||
return ret;
|
||||
@ -4095,7 +4095,7 @@ int ObSelectLogPlan::get_sort_keys_for_window_function(const ObLogicalOperator *
|
||||
ObSEArray<ObOrderDirection, 8> part_directions;
|
||||
ObSEArray<OrderItem, 8> output_sort_keys;
|
||||
bool is_const = false;
|
||||
int64_t prefix_count = -1;
|
||||
bool input_ordering_used = false;
|
||||
bool input_ordering_all_used = false;
|
||||
sort_keys.reuse();
|
||||
if (OB_ISNULL(top) || OB_ISNULL(win_expr)) {
|
||||
@ -4112,7 +4112,7 @@ int ObSelectLogPlan::get_sort_keys_for_window_function(const ObLogicalOperator *
|
||||
ordering,
|
||||
top->get_output_equal_sets(),
|
||||
top->get_output_const_exprs(),
|
||||
prefix_count,
|
||||
input_ordering_used,
|
||||
input_ordering_all_used,
|
||||
part_directions))) {
|
||||
LOG_WARN("failed to adjust exprs by ordering", K(ret));
|
||||
@ -4809,11 +4809,9 @@ int ObSelectLogPlan::get_late_materialization_operator(ObLogicalOperator *top,
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
} else if (log_op_def::LOG_TABLE_SCAN != child_scan->get_type()) {
|
||||
/*do nothing*/
|
||||
} else if (OB_FALSE_IT(table_scan = static_cast<ObLogTableScan *>(child_scan))) {
|
||||
} else if (NULL != table_scan->get_limit_expr() || NULL != table_scan->get_offset_expr()) {
|
||||
table_scan = NULL;
|
||||
} else {
|
||||
sort_op = static_cast<ObLogSort *>(child_sort);
|
||||
table_scan = static_cast<ObLogTableScan *>(child_scan);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user