From a87cb431591ca2bd4304889771504cf8a3cf1ae9 Mon Sep 17 00:00:00 2001 From: my0 Date: Fri, 17 Sep 2021 10:24:34 +0800 Subject: [PATCH] Fix view merge bug when there is a rand() function in select items of view. --- src/sql/rewrite/ob_transform_groupby_placement.cpp | 6 ++++++ src/sql/rewrite/ob_transform_view_merge.cpp | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/sql/rewrite/ob_transform_groupby_placement.cpp b/src/sql/rewrite/ob_transform_groupby_placement.cpp index bd41f5a740..a57294239a 100644 --- a/src/sql/rewrite/ob_transform_groupby_placement.cpp +++ b/src/sql/rewrite/ob_transform_groupby_placement.cpp @@ -1548,6 +1548,7 @@ int ObTransformGroupByPlacement::check_groupby_pullup_validity(ObDMLStmt* stmt, { int ret = OB_SUCCESS; bool can_pullup = false; + bool has_rand = false; if (OB_ISNULL(stmt) || OB_ISNULL(table)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("param has null", K(stmt), K(table), K(ret)); @@ -1574,6 +1575,11 @@ int ObTransformGroupByPlacement::check_groupby_pullup_validity(ObDMLStmt* stmt, LOG_WARN("failed to check null propagate select expr", K(ret)); } else if (!can_pullup) { // do nothing + } else if (OB_FAIL(sub_stmt->has_rand(has_rand))) { + LOG_WARN("failed to check stmt has rand func", K(ret)); + // stmt不能包含rand函数 https://work.aone.alibaba-inc.com/issue/35875561 + } else if (!(can_pullup = !has_rand)) { + // do nothing } else if (OB_FALSE_IT(helper.need_merge_ = sub_stmt->get_stmt_hint().enable_view_merge())) { } else if (OB_FAIL(valid_views.push_back(helper))) { LOG_WARN("failed to push back group stmt index", K(ret)); diff --git a/src/sql/rewrite/ob_transform_view_merge.cpp b/src/sql/rewrite/ob_transform_view_merge.cpp index 7a11095d77..475777dcb5 100644 --- a/src/sql/rewrite/ob_transform_view_merge.cpp +++ b/src/sql/rewrite/ob_transform_view_merge.cpp @@ -346,7 +346,15 @@ int ObTransformViewMerge::check_can_be_unnested( LOG_WARN("NULL expr", K(ret)); } else if (expr->has_flag(CNT_SUB_QUERY)) { can_be = false; - } else { /*do nothing*/ + } + } + // stmt不能包含rand函数 https://work.aone.alibaba-inc.com/issue/35875561 + if (OB_SUCC(ret) && can_be) { + bool has_rand = false; + if (OB_FAIL(child_stmt->has_rand(has_rand))) { + LOG_WARN("failed to get rand flag", K(ret)); + } else { + can_be = !has_rand; } } } -- GitLab