2011-09-04 21:23:19 +00:00
|
|
|
#pragma once
|
2010-03-12 18:25:35 +00:00
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2019-04-19 13:38:25 +00:00
|
|
|
#include <Common/SharedBlockRowRef.h>
|
2010-03-12 18:25:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** Implements the LIMIT relational operation.
|
2010-03-12 18:25:35 +00:00
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class LimitBlockInputStream : public IBlockInputStream
|
2010-03-12 18:25:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-13 22:19:04 +00:00
|
|
|
/** If always_read_till_end = false (by default), then after reading enough data,
|
|
|
|
* returns an empty block, and this causes the query to be canceled.
|
|
|
|
* If always_read_till_end = true - reads all the data to the end, but ignores them. This is necessary in rare cases:
|
|
|
|
* when otherwise, due to the cancellation of the request, we would not have received the data for GROUP BY WITH TOTALS from the remote server.
|
2019-03-08 14:36:40 +00:00
|
|
|
* If use_limit_as_total_rows_approx = true, then addTotalRowsApprox is called to use the limit in progress & stats
|
2019-08-22 23:16:00 +00:00
|
|
|
* with_ties = true, when query has WITH TIES modifier. If so, description should be provided
|
2019-04-19 15:45:42 +00:00
|
|
|
* description lets us know which row we should check for equality
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2019-04-19 13:38:25 +00:00
|
|
|
LimitBlockInputStream(
|
|
|
|
const BlockInputStreamPtr & input, UInt64 limit_, UInt64 offset_,
|
|
|
|
bool always_read_till_end_ = false, bool use_limit_as_total_rows_approx = false,
|
|
|
|
bool with_ties_ = false, const SortDescription & description_ = {});
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
String getName() const override { return "Limit"; }
|
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override { return children.at(0)->getHeader(); }
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override;
|
2012-10-20 02:10:47 +00:00
|
|
|
|
2010-03-12 18:25:35 +00:00
|
|
|
private:
|
2019-02-10 15:17:45 +00:00
|
|
|
UInt64 limit;
|
2019-02-10 16:22:38 +00:00
|
|
|
UInt64 offset;
|
|
|
|
UInt64 pos = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool always_read_till_end;
|
2019-04-19 13:38:25 +00:00
|
|
|
bool with_ties;
|
|
|
|
const SortDescription description;
|
2019-04-19 15:45:42 +00:00
|
|
|
SharedBlockRowRef ties_row_ref;
|
2010-03-12 18:25:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|