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
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Из потока блоков оставляет только уникальные строки.
|
|
|
|
|
* Для реализации SELECT DISTINCT ... .
|
|
|
|
|
* Если указан ненулевой limit - прекращает выдавать строки после того, как накопилось limit строк
|
|
|
|
|
* - для оптимизации SELECT DISTINCT ... LIMIT ... .
|
|
|
|
|
*/
|
|
|
|
|
class DistinctBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-03-28 15:57:06 +00:00
|
|
|
|
/// Пустой columns_ значит все столбцы.
|
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,
|
|
|
|
|
size_t rows) const;
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|