#pragma once #include #include #include #include namespace DB { class ASTSelectIntersectExceptQuery; class ASTSelectQuery; class ASTSelectWithUnionQuery; class PredicateRewriteVisitorData : WithContext { public: bool is_rewrite = false; using TypeToVisit = ASTSelectWithUnionQuery; void visit(ASTSelectWithUnionQuery & union_select_query, ASTPtr &); static bool needChild(const ASTPtr & node, const ASTPtr &) { return !(node && node->as()); } PredicateRewriteVisitorData( ContextPtr context_, const ASTs & predicates_, const TableWithColumnNamesAndTypes & table_columns_, bool optimize_final_, bool optimize_with_); private: const ASTs & predicates; const TableWithColumnNamesAndTypes & table_columns; bool optimize_final; bool optimize_with; void visitFirstInternalSelect(ASTSelectQuery & select_query, ASTPtr &); void visitOtherInternalSelect(ASTSelectQuery & select_query, ASTPtr &); void visit(ASTSelectIntersectExceptQuery & intersect_except_query, ASTPtr &); bool rewriteSubquery(ASTSelectQuery & subquery, const Names & inner_columns); void visitInternalSelect(size_t index, ASTSelectQuery & select_node, ASTPtr & node); }; using PredicateRewriteMatcher = OneTypeMatcher; using PredicateRewriteVisitor = InDepthNodeVisitor; }