mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
place left join keys in before_join actions
This commit is contained in:
parent
9637dad462
commit
d573005b04
@ -340,6 +340,13 @@ struct ExpressionActionsChain
|
|||||||
return steps.back();
|
return steps.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Step & lastStep(const NamesAndTypesList & columns)
|
||||||
|
{
|
||||||
|
if (steps.empty())
|
||||||
|
steps.emplace_back(std::make_shared<ExpressionActions>(columns, context));
|
||||||
|
return steps.back();
|
||||||
|
}
|
||||||
|
|
||||||
std::string dumpChain();
|
std::string dumpChain();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -453,14 +453,6 @@ const ASTSelectQuery * SelectQueryExpressionAnalyzer::getAggregatingQuery() cons
|
|||||||
return getSelectQuery();
|
return getSelectQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionAnalyzer::initChain(ExpressionActionsChain & chain, const NamesAndTypesList & columns) const
|
|
||||||
{
|
|
||||||
if (chain.steps.empty())
|
|
||||||
{
|
|
||||||
chain.steps.emplace_back(std::make_shared<ExpressionActions>(columns, context));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "Big" ARRAY JOIN.
|
/// "Big" ARRAY JOIN.
|
||||||
void ExpressionAnalyzer::addMultipleArrayJoinAction(ExpressionActionsPtr & actions, bool array_join_is_left) const
|
void ExpressionAnalyzer::addMultipleArrayJoinAction(ExpressionActionsPtr & actions, bool array_join_is_left) const
|
||||||
{
|
{
|
||||||
@ -487,8 +479,7 @@ bool SelectQueryExpressionAnalyzer::appendArrayJoin(ExpressionActionsChain & cha
|
|||||||
if (!array_join_expression_list)
|
if (!array_join_expression_list)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
getRootActions(array_join_expression_list, only_types, step.actions);
|
getRootActions(array_join_expression_list, only_types, step.actions);
|
||||||
|
|
||||||
@ -502,14 +493,20 @@ void ExpressionAnalyzer::addJoinAction(ExpressionActionsPtr & actions, JoinPtr j
|
|||||||
actions->add(ExpressionAction::ordinaryJoin(syntax->analyzed_join, join));
|
actions->add(ExpressionAction::ordinaryJoin(syntax->analyzed_join, join));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SelectQueryExpressionAnalyzer::appendJoin(ExpressionActionsChain & chain, bool only_types)
|
bool SelectQueryExpressionAnalyzer::appendJoinLeftKeys(ExpressionActionsChain & chain, bool only_types)
|
||||||
|
{
|
||||||
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
|
|
||||||
|
getRootActions(analyzedJoin().leftKeysList(), only_types, step.actions);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SelectQueryExpressionAnalyzer::appendJoin(ExpressionActionsChain & chain)
|
||||||
{
|
{
|
||||||
JoinPtr table_join = makeTableJoin(*syntax->ast_join);
|
JoinPtr table_join = makeTableJoin(*syntax->ast_join);
|
||||||
|
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
getRootActions(analyzedJoin().leftKeysList(), only_types, step.actions);
|
|
||||||
addJoinAction(step.actions, table_join);
|
addJoinAction(step.actions, table_join);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -633,8 +630,7 @@ bool SelectQueryExpressionAnalyzer::appendPrewhere(
|
|||||||
if (!select_query->prewhere())
|
if (!select_query->prewhere())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, sourceColumns());
|
auto & step = chain.lastStep(sourceColumns());
|
||||||
auto & step = chain.getLastStep();
|
|
||||||
getRootActions(select_query->prewhere(), only_types, step.actions);
|
getRootActions(select_query->prewhere(), only_types, step.actions);
|
||||||
String prewhere_column_name = select_query->prewhere()->getColumnName();
|
String prewhere_column_name = select_query->prewhere()->getColumnName();
|
||||||
step.required_output.push_back(prewhere_column_name);
|
step.required_output.push_back(prewhere_column_name);
|
||||||
@ -701,8 +697,7 @@ bool SelectQueryExpressionAnalyzer::appendPrewhere(
|
|||||||
|
|
||||||
void SelectQueryExpressionAnalyzer::appendPreliminaryFilter(ExpressionActionsChain & chain, ExpressionActionsPtr actions, String column_name)
|
void SelectQueryExpressionAnalyzer::appendPreliminaryFilter(ExpressionActionsChain & chain, ExpressionActionsPtr actions, String column_name)
|
||||||
{
|
{
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
// FIXME: assert(filter_info);
|
// FIXME: assert(filter_info);
|
||||||
step.actions = std::move(actions);
|
step.actions = std::move(actions);
|
||||||
@ -719,8 +714,7 @@ bool SelectQueryExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain,
|
|||||||
if (!select_query->where())
|
if (!select_query->where())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
step.required_output.push_back(select_query->where()->getColumnName());
|
step.required_output.push_back(select_query->where()->getColumnName());
|
||||||
step.can_remove_required_output = {true};
|
step.can_remove_required_output = {true};
|
||||||
@ -738,8 +732,7 @@ bool SelectQueryExpressionAnalyzer::appendGroupBy(ExpressionActionsChain & chain
|
|||||||
if (!select_query->groupBy())
|
if (!select_query->groupBy())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
ASTs asts = select_query->groupBy()->children;
|
ASTs asts = select_query->groupBy()->children;
|
||||||
for (const auto & ast : asts)
|
for (const auto & ast : asts)
|
||||||
@ -765,8 +758,7 @@ void SelectQueryExpressionAnalyzer::appendAggregateFunctionsArguments(Expression
|
|||||||
{
|
{
|
||||||
const auto * select_query = getAggregatingQuery();
|
const auto * select_query = getAggregatingQuery();
|
||||||
|
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
for (const auto & desc : aggregate_descriptions)
|
for (const auto & desc : aggregate_descriptions)
|
||||||
for (const auto & name : desc.argument_names)
|
for (const auto & name : desc.argument_names)
|
||||||
@ -797,8 +789,7 @@ bool SelectQueryExpressionAnalyzer::appendHaving(ExpressionActionsChain & chain,
|
|||||||
if (!select_query->having())
|
if (!select_query->having())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, aggregated_columns);
|
ExpressionActionsChain::Step & step = chain.lastStep(aggregated_columns);
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
step.required_output.push_back(select_query->having()->getColumnName());
|
step.required_output.push_back(select_query->having()->getColumnName());
|
||||||
getRootActions(select_query->having(), only_types, step.actions);
|
getRootActions(select_query->having(), only_types, step.actions);
|
||||||
@ -810,8 +801,7 @@ void SelectQueryExpressionAnalyzer::appendSelect(ExpressionActionsChain & chain,
|
|||||||
{
|
{
|
||||||
const auto * select_query = getSelectQuery();
|
const auto * select_query = getSelectQuery();
|
||||||
|
|
||||||
initChain(chain, aggregated_columns);
|
ExpressionActionsChain::Step & step = chain.lastStep(aggregated_columns);
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
getRootActions(select_query->select(), only_types, step.actions);
|
getRootActions(select_query->select(), only_types, step.actions);
|
||||||
|
|
||||||
@ -827,8 +817,7 @@ bool SelectQueryExpressionAnalyzer::appendOrderBy(ExpressionActionsChain & chain
|
|||||||
if (!select_query->orderBy())
|
if (!select_query->orderBy())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, aggregated_columns);
|
ExpressionActionsChain::Step & step = chain.lastStep(aggregated_columns);
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
getRootActions(select_query->orderBy(), only_types, step.actions);
|
getRootActions(select_query->orderBy(), only_types, step.actions);
|
||||||
|
|
||||||
@ -860,8 +849,7 @@ bool SelectQueryExpressionAnalyzer::appendLimitBy(ExpressionActionsChain & chain
|
|||||||
if (!select_query->limitBy())
|
if (!select_query->limitBy())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
initChain(chain, aggregated_columns);
|
ExpressionActionsChain::Step & step = chain.lastStep(aggregated_columns);
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
getRootActions(select_query->limitBy(), only_types, step.actions);
|
getRootActions(select_query->limitBy(), only_types, step.actions);
|
||||||
|
|
||||||
@ -886,8 +874,7 @@ void SelectQueryExpressionAnalyzer::appendProjectResult(ExpressionActionsChain &
|
|||||||
{
|
{
|
||||||
const auto * select_query = getSelectQuery();
|
const auto * select_query = getSelectQuery();
|
||||||
|
|
||||||
initChain(chain, aggregated_columns);
|
ExpressionActionsChain::Step & step = chain.lastStep(aggregated_columns);
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
|
|
||||||
NamesWithAliases result_columns;
|
NamesWithAliases result_columns;
|
||||||
|
|
||||||
@ -935,8 +922,7 @@ void SelectQueryExpressionAnalyzer::appendProjectResult(ExpressionActionsChain &
|
|||||||
|
|
||||||
void ExpressionAnalyzer::appendExpression(ExpressionActionsChain & chain, const ASTPtr & expr, bool only_types)
|
void ExpressionAnalyzer::appendExpression(ExpressionActionsChain & chain, const ASTPtr & expr, bool only_types)
|
||||||
{
|
{
|
||||||
initChain(chain, sourceColumns());
|
ExpressionActionsChain::Step & step = chain.lastStep(sourceColumns());
|
||||||
ExpressionActionsChain::Step & step = chain.steps.back();
|
|
||||||
getRootActions(expr, only_types, step.actions);
|
getRootActions(expr, only_types, step.actions);
|
||||||
step.required_output.push_back(expr->getColumnName());
|
step.required_output.push_back(expr->getColumnName());
|
||||||
}
|
}
|
||||||
@ -1099,11 +1085,13 @@ ExpressionAnalysisResult::ExpressionAnalysisResult(
|
|||||||
|
|
||||||
if (query_analyzer.hasTableJoin())
|
if (query_analyzer.hasTableJoin())
|
||||||
{
|
{
|
||||||
|
query_analyzer.appendJoinLeftKeys(chain, only_types || !first_stage);
|
||||||
|
|
||||||
before_join = chain.getLastActions(true);
|
before_join = chain.getLastActions(true);
|
||||||
if (before_join)
|
if (before_join)
|
||||||
chain.addStep();
|
chain.addStep();
|
||||||
|
|
||||||
query_analyzer.appendJoin(chain, only_types || !first_stage);
|
query_analyzer.appendJoin(chain);
|
||||||
|
|
||||||
join = chain.getLastActions();
|
join = chain.getLastActions();
|
||||||
if (!join)
|
if (!join)
|
||||||
|
@ -153,9 +153,6 @@ protected:
|
|||||||
void analyzeAggregation();
|
void analyzeAggregation();
|
||||||
bool makeAggregateDescriptions(ExpressionActionsPtr & actions);
|
bool makeAggregateDescriptions(ExpressionActionsPtr & actions);
|
||||||
|
|
||||||
/// columns - the columns that are present before the transformations begin.
|
|
||||||
void initChain(ExpressionActionsChain & chain, const NamesAndTypesList & columns) const;
|
|
||||||
|
|
||||||
const ASTSelectQuery * getSelectQuery() const;
|
const ASTSelectQuery * getSelectQuery() const;
|
||||||
|
|
||||||
bool isRemoteStorage() const;
|
bool isRemoteStorage() const;
|
||||||
@ -309,7 +306,8 @@ private:
|
|||||||
|
|
||||||
/// 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 appendJoinLeftKeys(ExpressionActionsChain & chain, bool only_types);
|
||||||
|
bool appendJoin(ExpressionActionsChain & chain);
|
||||||
/// Add preliminary rows filtration. Actions are created in other expression analyzer to prevent any possible alias injection.
|
/// Add preliminary rows filtration. Actions are created in other expression analyzer to prevent any possible alias injection.
|
||||||
void appendPreliminaryFilter(ExpressionActionsChain & chain, ExpressionActionsPtr actions, String column_name);
|
void appendPreliminaryFilter(ExpressionActionsChain & chain, ExpressionActionsPtr actions, String column_name);
|
||||||
/// remove_filter is set in ExpressionActionsChain::finalize();
|
/// remove_filter is set in ExpressionActionsChain::finalize();
|
||||||
|
Loading…
Reference in New Issue
Block a user