diff options
author | Varun Gupta <varunraiko1803@gmail.com> | 2017-01-21 00:56:33 +0530 |
---|---|---|
committer | Varun Gupta <varunraiko1803@gmail.com> | 2017-01-21 00:56:33 +0530 |
commit | 213fc700b64a38d64efceef2a2ef8de9748a8ce5 (patch) | |
tree | 324e50bccf4710a5bb8effbd87d0842556f1c917 /sql | |
parent | 8a4d605500ae487d3dc515305662769645bb092f (diff) | |
download | mariadb-git-213fc700b64a38d64efceef2a2ef8de9748a8ce5.tar.gz |
MDEV-10232: Scalar result of subquery changes after adding an outer select stmt
In a subquery, we don't have to maintain order
Added a fix such that order is considered when there is a limit clause.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_select.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1bd101bbe6f..e37c1b8c280 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1619,7 +1619,8 @@ JOIN::optimize_inner() <fields> to ORDER BY <fields>. There are three exceptions: - if skip_sort_order is set (see above), then we can simply skip GROUP BY; - - if we are in a subquery, we don't have to maintain order + - if we are in a subquery, we don't have to maintain order unless there + is a limit clause in the subquery. - we can only rewrite ORDER BY if the ORDER BY fields are 'compatible' with the GROUP BY ones, i.e. either one is a prefix of another. We only check if the ORDER BY is a prefix of GROUP BY. In this case @@ -1631,7 +1632,7 @@ JOIN::optimize_inner() if (!order || test_if_subpart(group_list, order)) { if (skip_sort_order || - select_lex->master_unit()->item) // This is a subquery + (select_lex->master_unit()->item && select_limit == HA_POS_ERROR)) // This is a subquery order= NULL; else order= group_list; |