#pragma once #include #include namespace DB { /// Executes LIMIT. See LimitTransform. class LimitStep : public ITransformingStep { public: LimitStep( const Header & input_header_, size_t limit_, size_t offset_, bool always_read_till_end_ = false, /// Read all data even if limit is reached. Needed for totals. bool with_ties_ = false, /// Limit with ties. SortDescription description_ = {}); String getName() const override { return "Limit"; } void transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override; void describeActions(JSONBuilder::JSONMap & map) const override; void describeActions(FormatSettings & settings) const override; size_t getLimitForSorting() const { if (limit > std::numeric_limits::max() - offset) return 0; return limit + offset; } bool withTies() const { return with_ties; } private: void updateOutputHeader() override { output_header = input_headers.front(); } size_t limit; size_t offset; bool always_read_till_end; bool with_ties; const SortDescription description; }; }