2020-06-16 18:23:01 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Processors/QueryPlan/ITransformingStep.h>
|
|
|
|
#include <Core/SortDescription.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-06-22 10:18:28 +00:00
|
|
|
/// Executes LIMIT. See LimitTransform.
|
2020-06-16 18:23:01 +00:00
|
|
|
class LimitStep : public ITransformingStep
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LimitStep(
|
|
|
|
const DataStream & input_stream_,
|
|
|
|
size_t limit_, size_t offset_,
|
2020-06-22 10:18:28 +00:00
|
|
|
bool always_read_till_end_ = false, /// Read all data even if limit is reached. Needed for totals.
|
|
|
|
bool with_ties_ = false, /// Limit with ties.
|
2020-06-16 18:23:01 +00:00
|
|
|
SortDescription description_ = {});
|
|
|
|
|
|
|
|
String getName() const override { return "Limit"; }
|
|
|
|
|
2021-09-14 16:28:41 +00:00
|
|
|
void transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override;
|
2020-06-16 18:23:01 +00:00
|
|
|
|
2021-04-16 16:36:59 +00:00
|
|
|
void describeActions(JSONBuilder::JSONMap & map) const override;
|
2020-06-27 14:02:24 +00:00
|
|
|
void describeActions(FormatSettings & settings) const override;
|
2020-06-24 12:09:01 +00:00
|
|
|
|
2020-07-29 12:29:20 +00:00
|
|
|
size_t getLimitForSorting() const
|
|
|
|
{
|
|
|
|
if (limit > std::numeric_limits<UInt64>::max() - offset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return limit + offset;
|
|
|
|
}
|
2020-07-28 14:13:31 +00:00
|
|
|
|
2020-07-29 11:06:00 +00:00
|
|
|
bool withTies() const { return with_ties; }
|
|
|
|
|
2020-06-16 18:23:01 +00:00
|
|
|
private:
|
2022-06-27 11:16:52 +00:00
|
|
|
void updateOutputStream() override
|
|
|
|
{
|
|
|
|
output_stream = createOutputStream(input_streams.front(), input_streams.front().header, getDataStreamTraits());
|
|
|
|
}
|
|
|
|
|
2020-06-16 18:23:01 +00:00
|
|
|
size_t limit;
|
|
|
|
size_t offset;
|
|
|
|
bool always_read_till_end;
|
|
|
|
|
|
|
|
bool with_ties;
|
|
|
|
const SortDescription description;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|