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
|
|
|
|
{
|
2023-11-22 09:23:52 +00:00
|
|
|
/// has_one can be pre-compute during creating the filter description in some cases
|
2023-10-13 07:41:49 +00:00
|
|
|
Int64 has_one = -1;
|
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;
|
2023-10-13 07:41:49 +00:00
|
|
|
bool hasOne() { return has_one >= 0 ? has_one : hasOneImpl();}
|
|
|
|
protected:
|
2023-11-22 09:23:52 +00:00
|
|
|
/// Calculate if filter has a non-zero from the filter values, may update has_one
|
2023-10-13 07:41:49 +00:00
|
|
|
virtual bool hasOneImpl() = 0;
|
2022-02-15 11:26:16 +00:00
|
|
|
};
|
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); }
|
2023-10-13 07:41:49 +00:00
|
|
|
protected:
|
2023-10-13 08:16:54 +00:00
|
|
|
bool hasOneImpl() override { return data ? (has_one = !memoryIsZero(data->data(), 0, data->size())) : false; }
|
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(); }
|
2023-10-13 07:41:49 +00:00
|
|
|
protected:
|
|
|
|
bool hasOneImpl() override { return filter_indices && !filter_indices->empty(); }
|
2022-02-15 11:26:16 +00:00
|
|
|
};
|
2018-05-15 12:56:14 +00:00
|
|
|
|
|
|
|
struct ColumnWithTypeAndName;
|
|
|
|
|
2017-12-14 21:51:30 +00:00
|
|
|
}
|