diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-08-10 21:38:55 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-08-10 21:38:55 +0300 |
commit | 1c587481966abc7a9ad5309d0a91ca920f7a5657 (patch) | |
tree | 28b936bd807cab0ba7b82e4cc9ec963fa6de6307 /sql/sql_union.cc | |
parent | 17be2b47ba32535e69e28da9a444e528ba8ab155 (diff) | |
parent | eae968f62d285de97ed607c87bc131cd863d5d03 (diff) | |
download | mariadb-git-1c587481966abc7a9ad5309d0a91ca920f7a5657.tar.gz |
Merge 10.4 into 10.5
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r-- | sql/sql_union.cc | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 3360c3c18cb..f1df76508d7 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2017, Oracle and/or its affiliates. - Copyright (c) 2010, 2017, Corporation + Copyright (c) 2010, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1364,6 +1364,25 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, found_rows_for_union= first_sl->options & OPTION_FOUND_ROWS; is_union_select= is_unit_op() || fake_select_lex || single_tvc; + /* + 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 (item && is_unit_op() && + (item->is_in_predicate() || item->is_exists_predicate())) + { + global_parameters()->order_list.first= NULL; + global_parameters()->order_list.elements= 0; + } + /* will only optimize once */ if (!bag_set_op_optimized && !is_recursive) { @@ -1390,6 +1409,7 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, break; } } + /* Global option */ if (is_union_select || is_recursive) |