aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MergeTree/MergeTreeIndexHypothesisMergedCondition.h
blob: 3ab82f4d3ee08d9f69259e29423ce317412ef8c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once

#include <Storages/MergeTree/MergeTreeIndices.h>
#include <Storages/MergeTree/MergeTreeData.h>
#include <Interpreters/ComparisonGraph.h>

namespace DB
{

/// MergedCondition for Indexhypothesis.
class MergeTreeIndexhypothesisMergedCondition : public IMergeTreeIndexMergedCondition
{
public:
    MergeTreeIndexhypothesisMergedCondition(
        const SelectQueryInfo & query, const ConstraintsDescription & constraints, size_t granularity_);

    void addIndex(const MergeTreeIndexPtr & index) override;
    bool alwaysUnknownOrTrue() const override;
    bool mayBeTrueOnGranule(const MergeTreeIndexGranules & granules) const override;

private:
    void addConstraints(const ConstraintsDescription & constraints_description);
    std::unique_ptr<ComparisonGraph<ASTPtr>> buildGraph(const std::vector<bool> & values) const;
    const ComparisonGraph<ASTPtr> * getGraph(const std::vector<bool> & values) const;

    ASTPtr expression_ast;
    std::unique_ptr<CNFQuery> expression_cnf;

    /// Part analysis can be done in parallel.
    /// So, we have shared answer and graph cache.
    mutable std::mutex cache_mutex;
    mutable std::unordered_map<std::vector<bool>, std::unique_ptr<ComparisonGraph<ASTPtr>>> graph_cache;
    mutable std::unordered_map<std::vector<bool>, bool> answer_cache;

    std::vector<std::vector<ASTPtr>> index_to_compare_atomic_hypotheses;
    std::vector<std::vector<CNFQuery::OrGroup>> index_to_atomic_hypotheses;
    ASTs atomic_constraints;
};

}