summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2021-04-18 22:58:34 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2021-04-21 12:36:57 +0300
commit10dd7dec61e22f31bc6f6f3761311fa64be87322 (patch)
tree564f95b91f3d520234b16cf504f46610378babd1 /sql/sql_select.cc
parenta2db12d8c94d89ff701e4d996e717539ff2e56fd (diff)
downloadmariadb-git-bb-10.6-refactor-limit-review.tar.gz
MDEV-25441 WITH TIES is not respected with SQL_BUFFER_RESULT and constant in ORDER BYbb-10.6-refactor-limit-review
Pushing LIMIT to temp aggregation table is possible, but not when WITH TIES is used. In a degenerate case with constant ORDER BY, the constant gets removed and the code assumed the limit is push-able. Ensure that if WITH TIES is present, that this does not happen.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index d3c86019e70..32bda234137 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3816,10 +3816,16 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
when there is ORDER BY or GROUP BY or there is no GROUP BY, but
there are aggregate functions, because in all these cases we need
all result rows.
+
+ We also can not push limit if the limit is WITH TIES, as we do not know
+ how many rows we will actually have. This can happen if ORDER BY was
+ a constant and removed (during remove_const), thus we have an "unlimited"
+ WITH TIES.
*/
ha_rows table_rows_limit= ((order == NULL || skip_sort_order) &&
!table_group &&
- !select_lex->with_sum_func) ? select_limit
+ !select_lex->with_sum_func &&
+ !unit->lim.is_with_ties()) ? select_limit
: HA_POS_ERROR;
if (!(tab->tmp_table_param= new TMP_TABLE_PARAM(tmp_table_param)))