From 9ae25b9413ff93b37066f2f35202475cad8e02f7 Mon Sep 17 00:00:00 2001 From: jingtaoye35 <1255153887@qq.com> Date: Wed, 3 Jan 2024 16:18:03 +0000 Subject: [PATCH] [CP] fix exec_param nested problem --- src/sql/optimizer/ob_log_plan.cpp | 51 +++++++++--------------- src/sql/optimizer/ob_log_plan.h | 2 - src/sql/optimizer/ob_select_log_plan.cpp | 15 +++---- 3 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index e2eab7fe61..05dfc57451 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -7830,7 +7830,7 @@ int ObLogPlan::candi_allocate_order_by(bool &need_limit, /*do nothing*/ } else if (OB_FAIL(get_stmt()->get_order_exprs(candi_subquery_exprs))) { LOG_WARN("failed to get exprs", K(ret)); - } else if (OB_FAIL(candi_allocate_subplan_filter_for_exprs(candi_subquery_exprs))) { + } else if (OB_FAIL(candi_allocate_subplan_filter(candi_subquery_exprs))) { LOG_WARN("failed to allocate subplan filter for exprs", K(ret)); } else if (OB_FAIL(candidates_.get_best_plan(best_plan))) { LOG_WARN("failed to get best plan", K(ret)); @@ -8965,28 +8965,6 @@ int ObLogPlan::candi_allocate_subplan_filter_for_where() return ret; } -int ObLogPlan::candi_allocate_subplan_filter_for_exprs(ObIArray &exprs) -{ - int ret = OB_SUCCESS; - ObSEArray subqueries; - ObSEArray nested_subquery_exprs; - if (OB_FAIL(ObTransformUtils::extract_query_ref_expr(exprs, - subqueries, - false))) { - LOG_WARN("failed to extract query ref expr", K(ret)); - } else if (OB_FAIL(ObOptimizerUtil::get_nested_exprs(subqueries, - nested_subquery_exprs))) { - LOG_WARN("failed to get nested subquery exprs", K(ret)); - } else if (!nested_subquery_exprs.empty() && - OB_FAIL(candi_allocate_subplan_filter(nested_subquery_exprs))) { - LOG_WARN("failed to allocate subplan filter for order by exprs", K(ret)); - } else if (!exprs.empty() && - OB_FAIL(candi_allocate_subplan_filter(exprs))) { - LOG_WARN("failed to allocate subplan filter for order by exprs", K(ret)); - } else { /*do nothing*/ } - return ret; -} - int ObLogPlan::candi_allocate_subplan_filter(const ObIArray &subquery_exprs, const ObIArray *filters, const bool is_update_set, @@ -9002,15 +8980,24 @@ int ObLogPlan::candi_allocate_subplan_filter(const ObIArray &subquer ObSEArray onetime_exprs; ObSEArray new_filters; OPT_TRACE_TITLE("start generate subplan filter"); - if (OB_FAIL(generate_subplan_filter_info(subquery_exprs, - subplans, - query_refs, - params, - onetime_exprs, - initplan_idxs, - onetime_idxs, - for_cursor_expr, - for_on_condition))) { + ObSEArray subqueries; + ObSEArray nested_subquery_exprs; + if (OB_FAIL(ObTransformUtils::extract_query_ref_expr(subquery_exprs, subqueries, false))) { + LOG_WARN("failed to extract query ref expr", K(ret)); + } else if (OB_FAIL(ObOptimizerUtil::get_nested_exprs(subqueries, nested_subquery_exprs))) { + LOG_WARN("failed to get nested subquery exprs", K(ret)); + } else if (!nested_subquery_exprs.empty() && + OB_FAIL(SMART_CALL(candi_allocate_subplan_filter(nested_subquery_exprs)))) { + LOG_WARN("failed to allocate subplan filter for order by exprs", K(ret)); + } else if (OB_FAIL(generate_subplan_filter_info(subquery_exprs, + subplans, + query_refs, + params, + onetime_exprs, + initplan_idxs, + onetime_idxs, + for_cursor_expr, + for_on_condition))) { LOG_WARN("failed to generated subplan filter info", K(ret)); } else if (NULL != filters && OB_FAIL(adjust_exprs_with_onetime(*filters, new_filters))) { LOG_WARN("failed to transform filters with onetime", K(ret)); diff --git a/src/sql/optimizer/ob_log_plan.h b/src/sql/optimizer/ob_log_plan.h index 9cdcb308a2..6ea3e5fb23 100644 --- a/src/sql/optimizer/ob_log_plan.h +++ b/src/sql/optimizer/ob_log_plan.h @@ -1004,8 +1004,6 @@ public: int candi_allocate_subplan_filter_for_where(); - int candi_allocate_subplan_filter_for_exprs(ObIArray &exprs); - int candi_allocate_subplan_filter(const ObIArray &subquery_exprs, const ObIArray *filters = NULL, const bool is_update_set = false, diff --git a/src/sql/optimizer/ob_select_log_plan.cpp b/src/sql/optimizer/ob_select_log_plan.cpp index c4c9a24981..a40007bffc 100644 --- a/src/sql/optimizer/ob_select_log_plan.cpp +++ b/src/sql/optimizer/ob_select_log_plan.cpp @@ -92,7 +92,7 @@ int ObSelectLogPlan::candi_allocate_group_by() OB_FAIL(append(candi_subquery_exprs, stmt->get_rollup_exprs())) || OB_FAIL(append(candi_subquery_exprs, stmt->get_aggr_items()))) { LOG_WARN("failed to append exprs", K(ret)); - } else if (OB_FAIL(candi_allocate_subplan_filter_for_exprs(candi_subquery_exprs))) { + } else if (OB_FAIL(candi_allocate_subplan_filter(candi_subquery_exprs))) { LOG_WARN("failed to allocate subplan filter for exprs", K(ret)); } else if (stmt->is_scala_group_by()) { if (OB_FAIL(ObOptimizerUtil::classify_subquery_exprs(stmt->get_having_exprs(), @@ -1391,7 +1391,7 @@ int ObSelectLogPlan::candi_allocate_distinct() LOG_WARN("get unexpected null", K(ret)); } else if (OB_FAIL(get_distinct_exprs(best_plan, reduce_exprs, distinct_exprs))) { LOG_WARN("failed to get select columns", K(ret)); - } else if (OB_FAIL(candi_allocate_subplan_filter_for_exprs(distinct_exprs))) { + } else if (OB_FAIL(candi_allocate_subplan_filter(distinct_exprs))) { LOG_WARN("failed to allocate subplan filter for exprs", K(ret)); } else if (distinct_exprs.empty()) { // if all the distinct exprs are const, we add limit operator instead of distinct operator @@ -4631,13 +4631,8 @@ int ObSelectLogPlan::candi_allocate_subplan_filter_for_select_item() LOG_WARN("null stmt", K(select_stmt), K(ret)); } else if (OB_FAIL(select_stmt->get_select_exprs(select_exprs))) { LOG_WARN("failed to get select exprs", K(ret)); - } else if (OB_FAIL(ObOptimizerUtil::get_subquery_exprs(select_exprs, - subquery_exprs))) { - LOG_WARN("failed to get subquery exprs", K(ret)); - } else if (subquery_exprs.empty()) { - /*do nothing*/ - } else if (OB_FAIL(candi_allocate_subplan_filter(subquery_exprs))) { - LOG_WARN("failed to allocate subplan filter for select item", K(ret)); + } else if (OB_FAIL(candi_allocate_subplan_filter(select_exprs))) { + LOG_WARN("failed to candi allocate subplan filter for exprs", K(ret)); } else { LOG_TRACE("succeed to allocate subplan filter for select item", K(select_stmt->get_stmt_id())); } @@ -4748,7 +4743,7 @@ int ObSelectLogPlan::candi_allocate_window_function() LOG_WARN("unexpected params", K(ret), K(stmt), K(stmt->has_window_function())); } else if (OB_FAIL(append(candi_subquery_exprs, stmt->get_window_func_exprs()))) { LOG_WARN("failed to append exprs", K(ret)); - } else if (OB_FAIL(candi_allocate_subplan_filter_for_exprs(candi_subquery_exprs))) { + } else if (OB_FAIL(candi_allocate_subplan_filter(candi_subquery_exprs))) { LOG_WARN("failed to do allocate subplan filter", K(ret)); } else if (OB_FAIL(candi_allocate_window_function_with_hint(stmt->get_window_func_exprs(), stmt->get_qualify_filters(),