style fixes

This commit is contained in:
Nikolai Kochetov 2018-04-20 22:38:34 +03:00
parent a6375d6155
commit 233ac6c599
5 changed files with 15 additions and 16 deletions

View File

@ -1019,7 +1019,7 @@ void ExpressionActionsChain::finalize()
std::unordered_map<String, size_t> required_output_indexes; std::unordered_map<String, size_t> required_output_indexes;
for (size_t j = 0; j < required_output.size(); ++j) for (size_t j = 0; j < required_output.size(); ++j)
required_output_indexes[required_output[j]] = j; required_output_indexes[required_output[j]] = j;
auto & can_remove_required_output = steps[i].can_remove_required_output; auto & can_remove_required_output = steps[i].not_need_in_future_steps;
if (i + 1 < static_cast<int>(steps.size())) if (i + 1 < static_cast<int>(steps.size()))
{ {

View File

@ -232,7 +232,10 @@ struct ExpressionActionsChain
ExpressionActionsPtr actions; ExpressionActionsPtr actions;
NameSet additional_input; NameSet additional_input;
Names required_output; Names required_output;
std::vector<std::shared_ptr<bool>> can_remove_required_output; /// Has the same size with required_output, is filled in finalize() /// Columns which are used only for current steps and not used in next actions (and can be removed from block).
/// Example: filter column for where actions.
/// If not empty, has the same size with required_output; is filled in finalize().
std::vector<bool *> not_need_in_future_steps;
Step(const ExpressionActionsPtr & actions_ = nullptr, const Names & required_output_ = Names()) Step(const ExpressionActionsPtr & actions_ = nullptr, const Names & required_output_ = Names())
: actions(actions_), required_output(required_output_) {} : actions(actions_), required_output(required_output_) {}

View File

@ -2429,7 +2429,7 @@ bool ExpressionAnalyzer::appendJoin(ExpressionActionsChain & chain, bool only_ty
return true; return true;
} }
bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool only_types, std::shared_ptr<bool> & remove_filter) bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool only_types, bool & remove_filter)
{ {
assertSelect(); assertSelect();
@ -2441,7 +2441,7 @@ bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool onl
getRootActions(select_query->prewhere_expression, only_types, false, step.actions); getRootActions(select_query->prewhere_expression, only_types, false, step.actions);
String prewhere_column_name = select_query->prewhere_expression->getColumnName(); String prewhere_column_name = select_query->prewhere_expression->getColumnName();
step.required_output.push_back(prewhere_column_name); step.required_output.push_back(prewhere_column_name);
step.can_remove_required_output = {remove_filter = std::make_shared<bool>(true)}; step.not_need_in_future_steps = {&remove_filter};
{ {
/// Remove unused source_columns from prewhere actions. /// Remove unused source_columns from prewhere actions.
@ -2491,7 +2491,7 @@ bool ExpressionAnalyzer::appendPrewhere(ExpressionActionsChain & chain, bool onl
return true; return true;
} }
bool ExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, bool only_types, std::shared_ptr<bool> & remove_filter) bool ExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, bool only_types, bool & remove_filter)
{ {
assertSelect(); assertSelect();
@ -2502,7 +2502,7 @@ bool ExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, bool only_t
ExpressionActionsChain::Step & step = chain.steps.back(); ExpressionActionsChain::Step & step = chain.steps.back();
step.required_output.push_back(select_query->where_expression->getColumnName()); step.required_output.push_back(select_query->where_expression->getColumnName());
step.can_remove_required_output = {remove_filter = std::make_shared<bool>(true)}; step.not_need_in_future_steps = {&remove_filter};
getRootActions(select_query->where_expression, only_types, false, step.actions); getRootActions(select_query->where_expression, only_types, false, step.actions);
return true; return true;

View File

@ -103,8 +103,8 @@ public:
/// Before aggregation: /// Before aggregation:
bool appendArrayJoin(ExpressionActionsChain & chain, bool only_types); bool appendArrayJoin(ExpressionActionsChain & chain, bool only_types);
bool appendJoin(ExpressionActionsChain & chain, bool only_types); bool appendJoin(ExpressionActionsChain & chain, bool only_types);
bool appendPrewhere(ExpressionActionsChain & chain, bool only_types, std::shared_ptr<bool> & remove_filter); bool appendPrewhere(ExpressionActionsChain & chain, bool only_types, bool & remove_filter);
bool appendWhere(ExpressionActionsChain & chain, bool only_types, std::shared_ptr<bool> & remove_filter); bool appendWhere(ExpressionActionsChain & chain, bool only_types, bool & remove_filter);
bool appendGroupBy(ExpressionActionsChain & chain, bool only_types); bool appendGroupBy(ExpressionActionsChain & chain, bool only_types);
void appendAggregateFunctionsArguments(ExpressionActionsChain & chain, bool only_types); void appendAggregateFunctionsArguments(ExpressionActionsChain & chain, bool only_types);

View File

@ -250,13 +250,12 @@ InterpreterSelectQuery::AnalysisResult InterpreterSelectQuery::analyzeExpression
* throw out unnecessary columns based on the entire query. In unnecessary parts of the query, we will not execute subqueries. * throw out unnecessary columns based on the entire query. In unnecessary parts of the query, we will not execute subqueries.
*/ */
std::shared_ptr<bool> remove_where_filter; bool remove_prewhere_filter;
std::shared_ptr<bool> remove_prewhere_filter;
{ {
ExpressionActionsChain chain; ExpressionActionsChain chain;
if (query_analyzer->appendPrewhere(chain, false, remove_prewhere_filter)) if (query_analyzer->appendPrewhere(chain, !res.first_stage, remove_prewhere_filter))
{ {
res.prewhere_info = std::make_shared<PrewhereInfo>( res.prewhere_info = std::make_shared<PrewhereInfo>(
chain.steps.front().actions, query.prewhere_expression->getColumnName()); chain.steps.front().actions, query.prewhere_expression->getColumnName());
@ -274,7 +273,7 @@ InterpreterSelectQuery::AnalysisResult InterpreterSelectQuery::analyzeExpression
chain.addStep(); chain.addStep();
} }
if (query_analyzer->appendWhere(chain, !res.first_stage, remove_where_filter)) if (query_analyzer->appendWhere(chain, !res.first_stage, res.remove_where_filter))
{ {
res.has_where = true; res.has_where = true;
res.before_where = chain.getLastActions(); res.before_where = chain.getLastActions();
@ -320,14 +319,11 @@ InterpreterSelectQuery::AnalysisResult InterpreterSelectQuery::analyzeExpression
} }
if (res.prewhere_info) if (res.prewhere_info)
res.prewhere_info->remove_prewhere_column = *remove_prewhere_filter; res.prewhere_info->remove_prewhere_column = remove_prewhere_filter;
/// Before executing WHERE and HAVING, remove the extra columns from the block (mostly the aggregation keys). /// Before executing WHERE and HAVING, remove the extra columns from the block (mostly the aggregation keys).
if (res.has_where) if (res.has_where)
{
res.before_where->prependProjectInput(); res.before_where->prependProjectInput();
res.remove_where_filter = *remove_where_filter;
}
if (res.has_having) if (res.has_having)
res.before_having->prependProjectInput(); res.before_having->prependProjectInput();