2017-12-14 21:51:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Columns/IColumn.h>
|
2022-02-15 11:26:16 +00:00
|
|
|
#include <Columns/ColumnsCommon.h>
|
2023-10-12 07:40:41 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
2017-12-14 21:51:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-15 00:01:59 +00:00
|
|
|
/// Support methods for implementation of WHERE, PREWHERE and HAVING.
|
|
|
|
|
|
|
|
|
|
|
|
/// Analyze if the column for filter is constant thus filter is always false or always true.
|
|
|
|
struct ConstantFilterDescription
|
2017-12-14 21:51:30 +00:00
|
|
|
{
|
|
|
|
bool always_false = false;
|
|
|
|
bool always_true = false;
|
2017-12-15 00:01:59 +00:00
|
|
|
|
2022-02-15 11:26:16 +00:00
|
|
|
ConstantFilterDescription() = default;
|
2017-12-15 00:01:59 +00:00
|
|
|
explicit ConstantFilterDescription(const IColumn & column);
|
|
|
|
};
|
|
|
|
|
2022-02-15 11:26:16 +00:00
|
|
|
struct IFilterDescription
|
|
|
|
{
|
2022-02-15 12:12:25 +00:00
|
|
|
virtual ColumnPtr filter(const IColumn & column, ssize_t result_size_hint) const = 0;
|
2022-02-15 11:26:16 +00:00
|
|
|
virtual size_t countBytesInFilter() const = 0;
|
|
|
|
virtual ~IFilterDescription() = default;
|
|
|
|
};
|
2017-12-15 00:01:59 +00:00
|
|
|
|
|
|
|
/// Obtain a filter from non constant Column, that may have type: UInt8, Nullable(UInt8).
|
2022-02-15 11:26:16 +00:00
|
|
|
struct FilterDescription final : public IFilterDescription
|
2017-12-15 00:01:59 +00:00
|
|
|
{
|
2017-12-14 21:51:30 +00:00
|
|
|
const IColumn::Filter * data = nullptr; /// Pointer to filter when it is not always true or always false.
|
|
|
|
ColumnPtr data_holder; /// If new column was generated, it will be owned by holder.
|
|
|
|
|
2017-12-15 00:01:59 +00:00
|
|
|
explicit FilterDescription(const IColumn & column);
|
2022-02-15 11:26:16 +00:00
|
|
|
|
2022-02-15 12:12:25 +00:00
|
|
|
ColumnPtr filter(const IColumn & column, ssize_t result_size_hint) const override { return column.filter(*data, result_size_hint); }
|
2022-02-15 11:26:16 +00:00
|
|
|
size_t countBytesInFilter() const override { return DB::countBytesInFilter(*data); }
|
2017-12-14 21:51:30 +00:00
|
|
|
};
|
|
|
|
|
2022-02-15 11:26:16 +00:00
|
|
|
struct SparseFilterDescription final : public IFilterDescription
|
|
|
|
{
|
2023-10-12 07:40:41 +00:00
|
|
|
const ColumnUInt64 * filter_indices = nullptr;
|
2022-02-15 11:26:16 +00:00
|
|
|
explicit SparseFilterDescription(const IColumn & column);
|
|
|
|
|
2022-02-15 12:12:25 +00:00
|
|
|
ColumnPtr filter(const IColumn & column, ssize_t) const override { return column.index(*filter_indices, 0); }
|
2022-02-15 11:26:16 +00:00
|
|
|
size_t countBytesInFilter() const override { return filter_indices->size(); }
|
|
|
|
};
|
2018-05-15 12:56:14 +00:00
|
|
|
|
|
|
|
struct ColumnWithTypeAndName;
|
|
|
|
|
2017-12-14 21:51:30 +00:00
|
|
|
}
|