summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2023-03-01 22:49:27 -0800
committerIgor Babaev <igor@askmonty.org>2023-03-02 07:51:33 -0800
commitccec9b1de95a66b7597bc30e0a60bd61866f225d (patch)
tree00dda7a1273427b667703ebabb6222cc7fd8af87 /sql/item.cc
parenta6a906d76697d5487418d51b251a3070ac6e8c80 (diff)
downloadmariadb-git-ccec9b1de95a66b7597bc30e0a60bd61866f225d.tar.gz
MDEV-30706 Different results of selects from view and CTE with same definition
MDEV-30668 Set function aggregated in outer select used in view definition This patch fixes two bugs concerning views whose specifications contain subqueries with set functions aggregated in outer selects. Due to the first bug those such views that have implicit grouping were considered as mergeable. This led to wrong result sets for selects from these views. Due to the second bug the aggregation select was determined incorrectly and this led to bogus error messages. The patch added several test cases for these two bugs and for four other duplicate bugs. The patch also enables view-protocol for many other test cases. Approved by Oleksandr Byelkin <sanja@mariadb.com>
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/sql/item.cc b/sql/item.cc
index ca6697422cc..be7780cb015 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5655,7 +5655,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
max_arg_level for the function if it's needed.
*/
if (thd->lex->in_sum_func &&
- thd->lex == context->select_lex->parent_lex &&
+ last_checked_context->select_lex->parent_lex ==
+ context->select_lex->parent_lex &&
thd->lex->in_sum_func->nest_level >= select->nest_level)
{
Item::Type ref_type= (*reference)->type();
@@ -5681,7 +5682,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
(Item_ident*) (*reference) :
0), false);
if (thd->lex->in_sum_func &&
- thd->lex == context->select_lex->parent_lex &&
+ last_checked_context->select_lex->parent_lex ==
+ context->select_lex->parent_lex &&
thd->lex->in_sum_func->nest_level >= select->nest_level)
{
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
@@ -6017,7 +6019,6 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
if (!thd->lex->current_select->no_wrap_view_item &&
thd->lex->in_sum_func &&
- thd->lex == select->parent_lex &&
thd->lex->in_sum_func->nest_level ==
select->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
@@ -8051,7 +8052,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
max_arg_level for the function if it's needed.
*/
if (thd->lex->in_sum_func &&
- thd->lex == context->select_lex->parent_lex &&
+ last_checked_context->select_lex->parent_lex ==
+ context->select_lex->parent_lex &&
thd->lex->in_sum_func->nest_level >=
last_checked_context->select_lex->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
@@ -8075,7 +8077,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
max_arg_level for the function if it's needed.
*/
if (thd->lex->in_sum_func &&
- thd->lex == context->select_lex->parent_lex &&
+ last_checked_context->select_lex->parent_lex ==
+ context->select_lex->parent_lex &&
thd->lex->in_sum_func->nest_level >=
last_checked_context->select_lex->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
@@ -8090,7 +8093,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
1. outer reference (will be fixed later by the fix_inner_refs function);
2. an unnamed reference inside an aggregate function.
*/
- if (!((*ref)->type() == REF_ITEM &&
+ if (!set_properties_only &&
+ !((*ref)->type() == REF_ITEM &&
((Item_ref *)(*ref))->ref_type() == OUTER_REF) &&
(((*ref)->with_sum_func() && name.str &&
!(current_sel->get_linkage() != GLOBAL_OPTIONS_TYPE &&