summaryrefslogtreecommitdiff
path: root/sql/sql_union.cc
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-08-04 14:36:01 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-08-06 10:55:03 +0530
commitab578bdf453c3cb0e9ca561cf373f64c96b22fda (patch)
tree72419bb4e1b55c503d13dbaaa60555eb93122b4e /sql/sql_union.cc
parent0e80f5a6934692dd7a47b6d31104fa194bbf18ec (diff)
downloadmariadb-git-ab578bdf453c3cb0e9ca561cf373f64c96b22fda.tar.gz
MDEV-9513: Assertion `join->group_list || !join->is_in_subquery()' failed in create_sort_index
Removing the ORDER BY clause from the UNION when UNION is inside an IN/ALL/ANY/EXISTS subquery. The rewrites are done for subqueries but this rewrite is not done for the fake_select of the UNION.
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r--sql/sql_union.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 38de2d592ed..0e623777ef0 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -388,6 +388,25 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
found_rows_for_union= first_sl->options & OPTION_FOUND_ROWS;
is_union_select= is_union() || fake_select_lex;
+ /*
+ If we are reading UNION output and the UNION is in the
+ IN/ANY/ALL/EXISTS subquery, then ORDER BY is redundant and hence should
+ be removed.
+ Example:
+ select ... col IN (select col2 FROM t1 union select col3 from t2 ORDER BY 1)
+
+ (as for ORDER BY ... LIMIT, it currently not supported inside
+ IN/ALL/ANY subqueries)
+ (For non-UNION this removal of ORDER BY clause is done in
+ check_and_do_in_subquery_rewrites())
+ */
+ if (is_union() && item &&
+ (item->is_in_predicate() || item->is_exists_predicate()))
+ {
+ global_parameters()->order_list.first= NULL;
+ global_parameters()->order_list.elements= 0;
+ }
+
/* Global option */
if (is_union_select)