mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 05:32:52 +00:00
3f57fc085b
Also remove it from some visitors.
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <Interpreters/Context_fwd.h>
|
|
#include <Interpreters/DatabaseAndTableWithAlias.h>
|
|
#include <Parsers/ASTSelectQuery.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
struct Settings;
|
|
|
|
/** Predicate optimization based on rewriting ast rules
|
|
* For more details : https://github.com/ClickHouse/ClickHouse/pull/2015#issuecomment-374283452
|
|
* The optimizer does two different optimizations
|
|
* - Move predicates from having to where
|
|
* - Push the predicate down from the current query to the having of the subquery
|
|
*/
|
|
class PredicateExpressionsOptimizer : WithConstContext
|
|
{
|
|
public:
|
|
PredicateExpressionsOptimizer(ContextConstPtr context_, const TablesWithColumns & tables_with_columns_, const Settings & settings_);
|
|
|
|
bool optimize(ASTSelectQuery & select_query);
|
|
|
|
private:
|
|
const bool enable_optimize_predicate_expression;
|
|
const bool enable_optimize_predicate_expression_to_final_subquery;
|
|
const bool allow_push_predicate_when_subquery_contains_with;
|
|
const TablesWithColumns & tables_with_columns;
|
|
|
|
std::vector<ASTs> extractTablesPredicates(const ASTPtr & where, const ASTPtr & prewhere);
|
|
|
|
bool tryRewritePredicatesToTables(ASTs & tables_element, const std::vector<ASTs> & tables_predicates);
|
|
|
|
bool tryRewritePredicatesToTable(
|
|
ASTPtr & table_element, const ASTs & table_predicates, const TableWithColumnNamesAndTypes & table_columns) const;
|
|
|
|
bool tryMovePredicatesFromHavingToWhere(ASTSelectQuery & select_query);
|
|
};
|
|
|
|
}
|