mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 07:01:59 +00:00
Fix bug for orderby withfill with limit clause
This commit is contained in:
parent
bf3187010b
commit
4adbdf364e
@ -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,
|
||||
* 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;
|
||||
if (!to_aggregation_stage &&
|
||||
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);
|
||||
has_prelimit = true;
|
||||
|
@ -0,0 +1,4 @@
|
||||
1 original
|
||||
2
|
||||
1 original
|
||||
2
|
15
tests/queries/0_stateless/01614_with_fill_with_limit.sql
Normal file
15
tests/queries/0_stateless/01614_with_fill_with_limit.sql
Normal 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;
|
Loading…
Reference in New Issue
Block a user