Skip to content

Commit 343bbd1

Browse files
author
Maheedhar PV
committed
Bug#28240054 - SIG11 IN SELECT_LEX_UNIT::OUTER_SELECT() AT
SQL/SQL_LEX.H Problem: Removal of a subquery having a "group by" operation, which is used by an outer select results in server exit. In a query, the "group by" subquery can be considered redundant and removed assuming as there are no aggregate functions. But if the subquery is used by the outer context, it should not be removed. Fix: Do not remove the subquery if it is needed for the select list. Change-Id: I696461cb59734984fd7f7095be161999461470e1
1 parent b04e559 commit 343bbd1

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

sql/item_subselect.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights
1+
/* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights
22
reserved.
33
44
This program is free software; you can redistribute it and/or modify
@@ -2520,6 +2520,14 @@ bool Item_subselect::clean_up_after_removal(uchar *arg)
25202520
{
25212521
st_select_lex *root=
25222522
static_cast<st_select_lex*>(static_cast<void*>(arg));
2523+
2524+
/*
2525+
Do not remove this subquery if it is a part of the select
2526+
list.
2527+
*/
2528+
if (root != NULL && root->is_in_select_list(this))
2529+
return false;
2530+
25232531
st_select_lex *sl= unit->outer_select();
25242532

25252533
/*

sql/sql_lex.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -3974,6 +3974,19 @@ st_select_lex::type_enum st_select_lex::type(const THD *thd)
39743974
return SLT_UNION;
39753975
}
39763976

3977+
bool st_select_lex::is_in_select_list(Item *cand) {
3978+
List_iterator<Item> li(item_list);
3979+
Item *item;
3980+
while ((item = li++)) {
3981+
// Use a walker to detect if cand is present in this select item
3982+
3983+
if (item->walk(&Item::find_item_processor, Item::POSTFIX,
3984+
reinterpret_cast<uchar *>(cand)))
3985+
return true;
3986+
}
3987+
return false;
3988+
}
3989+
39773990

39783991
/**
39793992
A routine used by the parser to decide whether we are specifying a full

sql/sql_lex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -1034,7 +1034,7 @@ class st_select_lex: public st_select_lex_node
10341034
// drop UNCACHEABLE_EXPLAIN, because it is for internal usage only
10351035
return !(uncacheable & ~UNCACHEABLE_EXPLAIN);
10361036
}
1037-
1037+
bool is_in_select_list(Item *cand);
10381038
private:
10391039
bool m_non_agg_field_used;
10401040
bool m_agg_func_used;

0 commit comments

Comments
 (0)