From afc4047103911cb554b1df22a0ac86cdfe056a9c Mon Sep 17 00:00:00 2001 From: AA-tuliwei-BB <1123152962@qq.com> Date: Fri, 23 Aug 2024 11:45:27 +0000 Subject: [PATCH] fix transform aggr subquery with window funtion bug --- .../rewrite/ob_transform_aggr_subquery.cpp | 33 +++++++++++++++++-- src/sql/rewrite/ob_transform_aggr_subquery.h | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/sql/rewrite/ob_transform_aggr_subquery.cpp b/src/sql/rewrite/ob_transform_aggr_subquery.cpp index 3d07dc7b69..07fcc02777 100644 --- a/src/sql/rewrite/ob_transform_aggr_subquery.cpp +++ b/src/sql/rewrite/ob_transform_aggr_subquery.cpp @@ -358,12 +358,18 @@ int ObTransformAggrSubquery::gather_transform_params(ObDMLStmt &stmt, trans_param.ja_query_ref_ = static_cast(child_expr); ObSelectStmt *subquery = trans_param.ja_query_ref_->get_ref_stmt(); bool is_valid = false; + bool ja_query_ref_valid = false; bool hint_allowed = false; int64_t limit_value = 0; OPT_TRACE("try to pullup JA subquery", child_expr); - if (ObOptimizerUtil::find_item(no_rewrite_exprs_, child_expr)) { + // check ja query ref's exec param + if (OB_FAIL(check_ja_query_ref_param_validity(*trans_param.ja_query_ref_, ja_query_ref_valid))) { + LOG_WARN("failed to check ja query ref param validity", K(ret)); + } else if (!ja_query_ref_valid) { + OPT_TRACE("exec param expr of ja query ref is not valid, can not transform"); + } else if (ObOptimizerUtil::find_item(no_rewrite_exprs_, child_expr)) { LOG_TRACE("subquery in select expr and can use index"); - OPT_TRACE("subquery in select expr and can use index, no need transfrom"); + OPT_TRACE("subquery in select expr and can use index, no need transform"); } else if (OB_FAIL(check_hint_allowed_unnest(stmt, *subquery, ctx_->trans_list_loc_ + transform_params.count(), pullup_strategy, @@ -445,6 +451,29 @@ int ObTransformAggrSubquery::gather_transform_params(ObDMLStmt &stmt, return ret; } +int ObTransformAggrSubquery::check_ja_query_ref_param_validity(ObQueryRefRawExpr &ja_query_ref, bool &is_valid) { + int ret = OB_SUCCESS; + is_valid = true; + const ObIArray ¶ms = ja_query_ref.get_exec_params(); + for (int64_t i = 0; OB_SUCC(ret) && is_valid && i < params.count(); ++i) { + ObExecParamRawExpr *exec_param = params.at(i); + ObRawExpr *outer_expr = NULL; + if (OB_ISNULL(exec_param)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("exec param expr is null", K(ret)); + } else if (OB_ISNULL(outer_expr = exec_param->get_ref_expr())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("outer expr is null", K(ret)); + } else if (outer_expr->has_flag(CNT_WINDOW_FUNC) || + outer_expr->has_flag(CNT_ROWNUM) || + outer_expr->has_flag(CNT_RAND_FUNC) || + outer_expr->has_flag(CNT_STATE_FUNC)) { + is_valid = false; + } + } + return ret; +} + /** * @brief ObTransformAggrSubquery::check_aggr_first_validity * check the valiaidty of the subquery diff --git a/src/sql/rewrite/ob_transform_aggr_subquery.h b/src/sql/rewrite/ob_transform_aggr_subquery.h index dd0bfe4b11..48e6fb0a3e 100644 --- a/src/sql/rewrite/ob_transform_aggr_subquery.h +++ b/src/sql/rewrite/ob_transform_aggr_subquery.h @@ -131,6 +131,8 @@ private: const bool is_select_item_expr, ObIArray ¶ms); + int check_ja_query_ref_param_validity(ObQueryRefRawExpr &ja_query_ref, bool &is_valid); + int check_aggr_first_validity(ObDMLStmt &stmt, ObQueryRefRawExpr &query_ref, const bool is_vector_assign,