From cf8e2df00e9a7912d3c54eafacf31e26a8bcfadf Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 28 Aug 2023 12:14:23 +0000 Subject: [PATCH] Fix aggregation result error in subquery with union --- .../dml/ob_aggr_expr_push_up_analyzer.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/sql/resolver/dml/ob_aggr_expr_push_up_analyzer.cpp b/src/sql/resolver/dml/ob_aggr_expr_push_up_analyzer.cpp index d7c565a989..caf90b8fda 100644 --- a/src/sql/resolver/dml/ob_aggr_expr_push_up_analyzer.cpp +++ b/src/sql/resolver/dml/ob_aggr_expr_push_up_analyzer.cpp @@ -243,10 +243,17 @@ ObSelectResolver *ObAggrExprPushUpAnalyzer::fetch_final_aggr_resolver(ObDMLResol || T_HAVING_SCOPE == cur_resolver->get_parent_namespace_resolver()->get_current_scope() || (T_ORDER_SCOPE == cur_resolver->get_parent_namespace_resolver()->get_current_scope() && T_WHERE_SCOPE != cur_resolver->get_current_scope()))) { - if (cur_resolver->is_select_resolver() && static_cast(cur_resolver)->is_in_set_query()) { - //当前resolver是位于union等关键字标识的set query中,aggr function不再铺上给union上层的查询 - //例如:SELECT (SELECT MAX(t1.b) from t2 union select 1 from t2 where 12 < 3) FROM t1 GROUP BY t1.a; - //MAX(t1.b)中引用了第一层的属性,但是MAX(t1.b)整个表达式保留在union的左支中 + if (lib::is_oracle_mode() && cur_resolver->is_select_resolver()) { + /* + * bug fix: + * + * SELECT (SELECT COUNT(t1.a) from dual) FROM t1 GROUP BY t1.a; + * * + * SELECT (SELECT COUNT(t1.a) union select 1 where 1>2) FROM t1 GROUP BY t1.a; + * * + * For oracle, aggr func always belongs to the subquery, does not need to push up. + * For mysql, aggr func belongs to the upper level, whether there is a "union" or not. + */ } else { ObDMLResolver *next_resolver = cur_resolver->get_parent_namespace_resolver(); final_resolver = fetch_final_aggr_resolver(next_resolver, min_level_resolver);