ClickHouse/src/Interpreters/PredicateExpressionsOptimizer.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include <Interpreters/Context_fwd.h>
2019-12-18 03:56:03 +00:00
#include <Interpreters/DatabaseAndTableWithAlias.h>
namespace DB
{
class ASTSelectQuery;
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
*/
2021-06-01 12:20:52 +00:00
class PredicateExpressionsOptimizer : WithContext
{
2019-12-18 03:56:03 +00:00
public:
2021-06-01 12:20:52 +00:00
PredicateExpressionsOptimizer(ContextPtr 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 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
}