ClickHouse/src/Storages/MergeTree/PartitionPruner.h

43 lines
1.3 KiB
C++
Raw Normal View History

2020-10-22 06:18:10 +00:00
#pragma once
#include <unordered_map>
#include <Storages/KeyDescription.h>
#include <Storages/MergeTree/IMergeTreeDataPart.h>
#include <Storages/MergeTree/KeyCondition.h>
namespace DB
{
2020-11-06 03:50:58 +00:00
/// Pruning partitions in verbatim way using KeyCondition
2020-10-22 06:18:10 +00:00
class PartitionPruner
{
private:
std::unordered_map<String, bool> partition_filter_map;
/// partition_key is adjusted here (with substitution from modulo to moduloLegacy).
KeyDescription partition_key;
2020-10-22 06:18:10 +00:00
KeyCondition partition_condition;
bool useless;
using DataPart = IMergeTreeDataPart;
using DataPartPtr = std::shared_ptr<const DataPart>;
public:
PartitionPruner(const StorageMetadataPtr & metadata, const SelectQueryInfo & query_info, ContextPtr context, bool strict)
: partition_key(MergeTreePartition::adjustPartitionKey(metadata, context))
2020-10-22 06:18:10 +00:00
, partition_condition(
2020-11-06 11:18:42 +00:00
query_info, context, partition_key.column_names, partition_key.expression, true /* single_point */, strict)
, useless(strict ? partition_condition.anyUnknownOrAlwaysTrue() : partition_condition.alwaysUnknownOrTrue())
2020-10-22 06:18:10 +00:00
{
}
bool canBePruned(const DataPart & part);
2020-10-22 06:18:10 +00:00
bool isUseless() const { return useless; }
2021-04-08 08:19:04 +00:00
2021-04-16 09:42:23 +00:00
const KeyCondition & getKeyCondition() const { return partition_condition; }
2020-10-22 06:18:10 +00:00
};
}