Fix bug for orderby withfill with limit clause

This commit is contained in:
hexiaoting 2020-12-17 17:33:47 +08:00 committed by Nikita Mikhailov
parent bf3187010b
commit 4adbdf364e
3 changed files with 33 additions and 1 deletions

View File

@ -1029,10 +1029,23 @@ void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, const BlockInpu
/** Optimization - if there are several sources and there is LIMIT, then first apply the preliminary LIMIT, /** Optimization - if there are several sources and there is LIMIT, then first apply the preliminary LIMIT,
* limiting the number of rows in each up to `offset + limit`. * limiting the number of rows in each up to `offset + limit`.
*/ */
bool has_withfill = false;
if (query.orderBy())
{
SortDescription order_descr = getSortDescription(query, *context);
for (auto & desc : order_descr)
if (desc.with_fill)
{
has_withfill = true;
break;
}
}
bool has_prelimit = false; bool has_prelimit = false;
if (!to_aggregation_stage && if (!to_aggregation_stage &&
query.limitLength() && !query.limit_with_ties && !hasWithTotalsInAnySubqueryInFromClause(query) && query.limitLength() && !query.limit_with_ties && !hasWithTotalsInAnySubqueryInFromClause(query) &&
!query.arrayJoinExpressionList() && !query.distinct && !expressions.hasLimitBy() && !settings.extremes) !query.arrayJoinExpressionList() && !query.distinct && !expressions.hasLimitBy() && !settings.extremes &&
!has_withfill)
{ {
executePreLimit(query_plan, false); executePreLimit(query_plan, false);
has_prelimit = true; has_prelimit = true;

View File

@ -0,0 +1,4 @@
1 original
2
1 original
2

View File

@ -0,0 +1,15 @@
SELECT
toFloat32(number % 10) AS n,
'original' AS source
FROM numbers(10)
WHERE (number % 3) = 1
ORDER BY n ASC WITH FILL STEP 1
LIMIT 2;
SELECT
toFloat32(number % 10) AS n,
'original' AS source
FROM numbers(10)
WHERE (number % 3) = 1
ORDER BY n ASC WITH FILL STEP 1
LIMIT 2 WITH TIES;