ClickHouse/src/Interpreters/PredicateExpressionsOptimizer.h

43 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
2019-04-09 16:49:52 +00:00
#include <Parsers/ASTSelectQuery.h>
2019-12-18 03:56:03 +00:00
#include <Interpreters/DatabaseAndTableWithAlias.h>
namespace DB
{
class Context;
struct Settings;
/** Predicate optimization based on rewriting ast rules
2019-09-23 16:18:19 +00:00
* 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
{
2019-12-18 03:56:03 +00:00
public:
PredicateExpressionsOptimizer(const Context & context_, const TablesWithColumns & tables_with_columns_, const Settings & settings_);
2019-12-18 03:56:03 +00:00
bool optimize(ASTSelectQuery & select_query);
2019-12-18 03:56:03 +00:00
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 Context & context;
const TablesWithColumns & tables_with_columns;
2019-12-18 03:56:03 +00:00
std::vector<ASTs> extractTablesPredicates(const ASTPtr & where, const ASTPtr & prewhere);
2019-12-18 03:56:03 +00:00
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);
};
2018-08-14 21:48:39 +00:00
}