#pragma once #include #include #include #include #include namespace DB { using ConstraintsExpressions = std::vector; struct ConstraintsDescription { public: ConstraintsDescription() { update(); } explicit ConstraintsDescription(const ASTs & constraints_); ConstraintsDescription(const ConstraintsDescription & other); ConstraintsDescription & operator=(const ConstraintsDescription & other); ConstraintsDescription(ConstraintsDescription && other) noexcept; ConstraintsDescription & operator=(ConstraintsDescription && other) noexcept; bool empty() const { return constraints.empty(); } String toString() const; static ConstraintsDescription parse(const String & str); enum class ConstraintType : UInt8 { CHECK = 1, ASSUME = 2, ALWAYS_TRUE = CHECK | ASSUME, ALL = CHECK | ASSUME, }; ASTs filterConstraints(ConstraintType selection) const; const ASTs & getConstraints() const; const std::vector> & getConstraintData() const; std::vector getAtomicConstraintData() const; const ComparisonGraph & getGraph() const; ConstraintsExpressions getExpressions(ContextPtr context, const NamesAndTypesList & source_columns_) const; struct AtomId { size_t group_id; size_t atom_id; }; using AtomIds = std::vector; std::optional getAtomIds(const ASTPtr & ast) const; std::vector getAtomsById(const AtomIds & ids) const; class QueryTreeData { public: const QueryTreeNodes & getConstraints() const; const std::vector> & getConstraintData() const; std::optional getAtomIds(const QueryTreeNodePtrWithHash & node_with_hash) const; std::vector getAtomsById(const AtomIds & ids) const; const ComparisonGraph & getGraph() const; private: QueryTreeNodes constraints; std::vector> cnf_constraints; QueryTreeNodePtrWithHashMap query_node_to_atom_ids; std::unique_ptr> graph; friend ConstraintsDescription; }; QueryTreeData getQueryTreeData(const ContextPtr & context, const QueryTreeNodePtr & table_node) const; private: std::vector> buildConstraintData() const; std::unique_ptr> buildGraph() const; void update(); ASTs constraints; std::vector> cnf_constraints; std::map ast_to_atom_ids; std::unique_ptr> graph; }; }