From b6c37b4cdace35feaee28a86ab038a9298a79768 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 8 Feb 2024 01:26:33 +0000 Subject: [PATCH] bugfix: disable minmax and count_to_exists rewrite when stmt has rownum --- src/sql/rewrite/ob_transform_count_to_exists.cpp | 5 +++++ src/sql/rewrite/ob_transform_min_max.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/sql/rewrite/ob_transform_count_to_exists.cpp b/src/sql/rewrite/ob_transform_count_to_exists.cpp index 7a1218957c..e27789c7f1 100644 --- a/src/sql/rewrite/ob_transform_count_to_exists.cpp +++ b/src/sql/rewrite/ob_transform_count_to_exists.cpp @@ -190,12 +190,17 @@ int ObTransformCountToExists::check_trans_valid(ObDMLStmt *stmt, ObRawExpr *expr ObRawExpr *sel_expr = NULL; bool is_sel_expr_valid = false; bool is_const_expr_valid = false; + bool has_rownum = false; if (OB_ISNULL(tmp_subquery = tmp_subquery_expr->get_ref_stmt())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); } else if (OB_ISNULL(sel_expr = tmp_subquery->get_select_item(0).expr_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null expr", K(ret)); + } else if (OB_FAIL(tmp_subquery->has_rownum(has_rownum))) { + LOG_WARN("failed to check if subquery has rownum", K(ret)); + } else if (has_rownum) { + // do nothing } else if (tmp_subquery_expr->get_ref_count() > 1 || tmp_subquery->has_having() || !tmp_subquery->is_scala_group_by()) { // only scalar group by subquery without having and referred by once can be transformed diff --git a/src/sql/rewrite/ob_transform_min_max.cpp b/src/sql/rewrite/ob_transform_min_max.cpp index 22196cd56a..57df69a9ea 100644 --- a/src/sql/rewrite/ob_transform_min_max.cpp +++ b/src/sql/rewrite/ob_transform_min_max.cpp @@ -85,6 +85,7 @@ int ObTransformMinMax::check_transform_validity(ObTransformerCtx &ctx, const ObAggFunRawExpr *expr = NULL; aggr_expr = NULL; is_valid = false; + bool has_rownum = false; if (OB_ISNULL(select_stmt)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected null", K(ret), K(select_stmt)); @@ -95,6 +96,10 @@ int ObTransformMinMax::check_transform_validity(ObTransformerCtx &ctx, select_stmt->get_aggr_item_size() != 1 || !select_stmt->is_scala_group_by()) { OPT_TRACE("not a simple query"); + } else if (OB_FAIL(select_stmt->has_rownum(has_rownum))) { + LOG_WARN("failed to check if select stmt has rownum", K(ret)); + } else if (has_rownum) { + OPT_TRACE("stmt has rownum"); } else if (OB_ISNULL(expr = select_stmt->get_aggr_items().at(0))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("params have null", K(ret), KP(expr));