2019-12-18 03:56:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
|
|
|
#include <Interpreters/DatabaseAndTableWithAlias.h>
|
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
2021-11-26 17:35:24 +00:00
|
|
|
#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;
|
2021-11-26 17:35:24 +00:00
|
|
|
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:
|
2020-01-04 04:31:45 +00:00
|
|
|
bool is_rewrite = false;
|
2019-12-18 03:56:03 +00:00
|
|
|
using TypeToVisit = ASTSelectWithUnionQuery;
|
|
|
|
|
|
|
|
void visit(ASTSelectWithUnionQuery & union_select_query, ASTPtr &);
|
|
|
|
|
2020-04-14 18:50:00 +00:00
|
|
|
static bool needChild(const ASTPtr & node, const ASTPtr &)
|
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
return !(node && node->as<TypeToVisit>());
|
2020-04-14 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
PredicateRewriteVisitorData(
|
2021-06-01 12:20:52 +00:00
|
|
|
ContextPtr context_,
|
2021-04-10 23:33:54 +00:00
|
|
|
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;
|
2021-03-24 12:48:29 +00:00
|
|
|
const TableWithColumnNamesAndTypes & table_columns;
|
2019-12-18 03:56:03 +00:00
|
|
|
bool optimize_final;
|
2020-07-24 09:00:18 +00:00
|
|
|
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
|
|
|
|
2021-03-24 12:48:29 +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
|
|
|
};
|
|
|
|
|
2020-04-14 18:50:00 +00:00
|
|
|
using PredicateRewriteMatcher = OneTypeMatcher<PredicateRewriteVisitorData, PredicateRewriteVisitorData::needChild>;
|
2019-12-18 03:56:03 +00:00
|
|
|
using PredicateRewriteVisitor = InDepthNodeVisitor<PredicateRewriteMatcher, true>;
|
2021-04-10 23:33:54 +00:00
|
|
|
|
2019-12-18 03:56:03 +00:00
|
|
|
}
|