Fix when we set a LIMIT to 0

This commit is contained in:
Guillaume Tassery 2020-05-11 19:18:07 +07:00
parent c25ffb5930
commit b0df037f25

View File

@ -676,8 +676,12 @@ static std::pair<UInt64, UInt64> getLimitLengthAndOffset(const ASTSelectQuery &
UInt64 offset = 0;
if (query.limitLength())
{
length = getLimitUIntValue(query.limitLength(), context, "LIMIT");
if (query.limitOffset())
if (query.limitOffset() && length)
offset = getLimitUIntValue(query.limitOffset(), context, "OFFSET");
}
else if (query.limitOffset())
offset = getLimitUIntValue(query.limitOffset(), context, "OFFSET");
return {length, offset};
}
@ -689,7 +693,7 @@ static UInt64 getLimitForSorting(const ASTSelectQuery & query, const Context & c
if (!query.distinct && !query.limitBy() && !query.limit_with_ties && !query.arrayJoinExpressionList() && query.limitLength())
{
auto [limit_length, limit_offset] = getLimitLengthAndOffset(query, context);
return limit_length != 0 ? limit_length + limit_offset : 0;
return limit_length + limit_offset;
}
return 0;
}
@ -2314,9 +2318,6 @@ void InterpreterSelectQuery::executePreLimit(QueryPipeline & pipeline, bool do_n
{
auto [limit_length, limit_offset] = getLimitLengthAndOffset(query, *context);
if (limit_length == 0)
limit_offset = 0;
if (do_not_skip_offset)
{
limit_length += limit_offset;
@ -2430,9 +2431,6 @@ void InterpreterSelectQuery::executeLimit(Pipeline & pipeline)
UInt64 limit_offset;
std::tie(limit_length, limit_offset) = getLimitLengthAndOffset(query, *context);
if (limit_length == 0)
limit_offset = 0;
pipeline.transform([&](auto & stream)
{
stream = std::make_shared<LimitBlockInputStream>(stream, limit_length, limit_offset, always_read_till_end, false, query.limit_with_ties, order_descr);
@ -2516,9 +2514,6 @@ void InterpreterSelectQuery::executeLimit(QueryPipeline & pipeline)
UInt64 limit_offset;
std::tie(limit_length, limit_offset) = getLimitLengthAndOffset(query, *context);
if (limit_length == 0)
limit_offset = 0;
SortDescription order_descr;
if (query.limit_with_ties)
{