ClickHouse/src/Interpreters/PredicateRewriteVisitor.h

56 lines
1.6 KiB
C++
Raw Normal View History

2019-12-18 03:56:03 +00:00
#pragma once
#include <Interpreters/Context_fwd.h>
#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/InDepthNodeVisitor.h>
#include <Parsers/IAST_fwd.h>
2019-12-18 03:56:03 +00:00
namespace DB
{
2021-11-10 09:33:48 +00:00
class ASTSelectIntersectExceptQuery;
class ASTSelectQuery;
class ASTSelectWithUnionQuery;
2021-11-10 09:33:48 +00:00
2021-06-01 12:20:52 +00:00
class PredicateRewriteVisitorData : WithContext
2019-12-18 03:56:03 +00:00
{
public:
bool is_rewrite = false;
2019-12-18 03:56:03 +00:00
using TypeToVisit = ASTSelectWithUnionQuery;
void visit(ASTSelectWithUnionQuery & union_select_query, ASTPtr &);
static bool needChild(const ASTPtr & node, const ASTPtr &)
{
return !(node && node->as<TypeToVisit>());
}
PredicateRewriteVisitorData(
2021-06-01 12:20:52 +00:00
ContextPtr context_,
const ASTs & predicates_,
const TableWithColumnNamesAndTypes & table_columns_,
bool optimize_final_,
bool optimize_with_);
2019-12-18 03:56:03 +00:00
private:
const ASTs & predicates;
const TableWithColumnNamesAndTypes & table_columns;
2019-12-18 03:56:03 +00:00
bool optimize_final;
bool optimize_with;
2019-12-18 03:56:03 +00:00
void visitFirstInternalSelect(ASTSelectQuery & select_query, ASTPtr &);
void visitOtherInternalSelect(ASTSelectQuery & select_query, ASTPtr &);
2021-11-10 15:07:42 +00:00
void visit(ASTSelectIntersectExceptQuery & intersect_except_query, ASTPtr &);
2021-11-10 09:33:48 +00:00
bool rewriteSubquery(ASTSelectQuery & subquery, const Names & inner_columns);
2021-11-10 09:33:48 +00:00
2021-11-10 15:07:42 +00:00
void visitInternalSelect(size_t index, ASTSelectQuery & select_node, ASTPtr & node);
2019-12-18 03:56:03 +00:00
};
using PredicateRewriteMatcher = OneTypeMatcher<PredicateRewriteVisitorData, PredicateRewriteVisitorData::needChild>;
2019-12-18 03:56:03 +00:00
using PredicateRewriteVisitor = InDepthNodeVisitor<PredicateRewriteMatcher, true>;
2019-12-18 03:56:03 +00:00
}