From d61b55b5e486d779ce27edea106c1e3afcf77554 Mon Sep 17 00:00:00 2001 From: xianyu-w <707512433@qq.com> Date: Fri, 25 Aug 2023 05:44:11 +0000 Subject: [PATCH] [CP] [CP] Fix RCTE plan bug --- src/sql/optimizer/ob_log_plan.cpp | 16 +++++++++++++--- src/sql/optimizer/ob_logical_operator.cpp | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 2406343f00..ef8ce81c4c 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -10370,6 +10370,7 @@ int ObLogPlan::add_candidate_plan(ObIArray ¤t_plans, } else if (new_plan.plan_tree_->get_contains_match_all_fake_cte() && !new_plan.plan_tree_->is_remote()) { should_add = false; + OPT_TRACE("containt match all fake cte, but not remote plan, will not add plan"); } for (int64_t i = current_plans.count() - 1; OB_SUCC(ret) && should_add && i >= 0; --i) { @@ -13388,9 +13389,18 @@ int ObLogPlan::allocate_material_for_recursive_cte_plan(ObIArrayget_type() && log_op_def::LOG_TABLE_SCAN != child_ops.at(i)->get_type() && - log_op_def::LOG_EXPR_VALUES != 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)); + log_op_def::LOG_EXPR_VALUES != child_ops.at(i)->get_type()) { + bool is_plan_root = child_ops.at(i)->is_plan_root(); + child_ops.at(i)->set_is_plan_root(false); + if (OB_FAIL(log_plan->allocate_material_as_top(child_ops.at(i)))) { + LOG_WARN("failed to allocate materialize as top", K(ret)); + } else if (is_plan_root) { + child_ops.at(i)->mark_is_plan_root(); + child_ops.at(i)->get_plan()->set_plan_root(child_ops.at(i)); + if (OB_FAIL(child_ops.at(i)->set_plan_root_output_exprs())) { + LOG_WARN("failed to set plan root output", K(ret)); + } + } } else { /*do nothing*/ } } } diff --git a/src/sql/optimizer/ob_logical_operator.cpp b/src/sql/optimizer/ob_logical_operator.cpp index 957ddb8555..8e19c4925e 100644 --- a/src/sql/optimizer/ob_logical_operator.cpp +++ b/src/sql/optimizer/ob_logical_operator.cpp @@ -1413,7 +1413,7 @@ int ObLogicalOperator::do_pre_traverse_operation(const TraverseOp &op, void *ctx } else if (OB_FAIL(allocate_expr_pre(*alloc_expr_context))) { LOG_WARN("failed to do allocate expr pre", K(ret)); } else { - LOG_TRACE("succeed to do allcoate expr pre", K(get_type()), K(get_name()), K(get_op_id()), K(ret)); + LOG_TRACE("succeed to do allocate expr pre", K(get_type()), K(get_name()), K(get_op_id()), K(ret)); } break; }