2013-06-01 07:43:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-10 21:24:40 +00:00
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2013-06-20 12:12:27 +00:00
|
|
|
#include <DB/Interpreters/Limits.h>
|
2016-12-22 08:51:34 +00:00
|
|
|
#include <DB/Interpreters/SetVariants.h>
|
2013-06-01 07:43:57 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-12-23 08:01:35 +00:00
|
|
|
/** This class is intended for implementation of SELECT DISTINCT clause and
|
|
|
|
* leaves only unique rows in the stream.
|
|
|
|
*
|
|
|
|
* To optimize the SELECT DISTINCT ... LIMIT clause we can
|
|
|
|
* set limit_hint to non zero value. So we stop emitting new rows after
|
|
|
|
* count of already emitted rows will reach the limit_hint.
|
2013-06-01 07:43:57 +00:00
|
|
|
*/
|
|
|
|
class DistinctBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
{
|
|
|
|
public:
|
2016-12-23 08:01:35 +00:00
|
|
|
/// Empty columns_ means all collumns.
|
2016-12-22 20:50:12 +00:00
|
|
|
DistinctBlockInputStream(BlockInputStreamPtr input_, const Limits & limits, size_t limit_hint_, Names columns_);
|
2013-06-01 07:43:57 +00:00
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
String getName() const override { return "Distinct"; }
|
2013-06-01 07:43:57 +00:00
|
|
|
|
2016-11-10 21:24:40 +00:00
|
|
|
String getID() const override;
|
2013-06-01 07:43:57 +00:00
|
|
|
|
|
|
|
protected:
|
2015-01-21 04:17:02 +00:00
|
|
|
Block readImpl() override;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2016-11-10 21:24:40 +00:00
|
|
|
private:
|
|
|
|
bool checkLimits() const;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2016-12-22 17:00:23 +00:00
|
|
|
ConstColumnPlainPtrs getKeyColumns(const Block & block) const;
|
|
|
|
|
2016-12-22 08:51:34 +00:00
|
|
|
template <typename Method>
|
2016-12-22 17:00:23 +00:00
|
|
|
void buildFilter(
|
2016-12-22 08:51:34 +00:00
|
|
|
Method & method,
|
|
|
|
const ConstColumnPlainPtrs & key_columns,
|
|
|
|
IColumn::Filter & filter,
|
2017-01-12 15:34:41 +00:00
|
|
|
size_t rows,
|
|
|
|
SetVariants & variants) const;
|
2016-12-22 08:51:34 +00:00
|
|
|
|
2014-03-28 15:57:06 +00:00
|
|
|
|
2016-12-22 08:51:34 +00:00
|
|
|
Names columns_names;
|
|
|
|
SetVariants data;
|
|
|
|
Sizes key_sizes;
|
2016-12-22 20:50:12 +00:00
|
|
|
size_t limit_hint;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2016-12-23 08:01:35 +00:00
|
|
|
/// Restrictions on the maximum size of the output data.
|
2013-06-20 12:12:27 +00:00
|
|
|
size_t max_rows;
|
|
|
|
size_t max_bytes;
|
2014-02-17 23:56:45 +00:00
|
|
|
OverflowMode overflow_mode;
|
2013-06-01 07:43:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|