mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
extract JOIN in own plan step
This commit is contained in:
parent
0260358253
commit
801efc387a
@ -325,9 +325,9 @@ struct ExpressionActionsChain
|
||||
steps.clear();
|
||||
}
|
||||
|
||||
ExpressionActionsPtr getLastActions()
|
||||
ExpressionActionsPtr getLastActions(bool allow_empty = false)
|
||||
{
|
||||
if (steps.empty())
|
||||
if (steps.empty() && !allow_empty)
|
||||
throw Exception("Empty ExpressionActionsChain", ErrorCodes::LOGICAL_ERROR);
|
||||
|
||||
return steps.back().actions;
|
||||
|
@ -1101,10 +1101,14 @@ ExpressionAnalysisResult::ExpressionAnalysisResult(
|
||||
|
||||
query_analyzer.appendArrayJoin(chain, only_types || !first_stage);
|
||||
|
||||
before_join = chain.getLastActions(true);
|
||||
if (before_join)
|
||||
chain.addStep();
|
||||
|
||||
if (query_analyzer.appendJoin(chain, only_types || !first_stage))
|
||||
{
|
||||
before_join = chain.getLastActions();
|
||||
if (!hasJoin())
|
||||
join = chain.getLastActions();
|
||||
if (!join)
|
||||
throw Exception("No expected JOIN", ErrorCodes::LOGICAL_ERROR);
|
||||
chain.addStep();
|
||||
}
|
||||
@ -1153,11 +1157,11 @@ ExpressionAnalysisResult::ExpressionAnalysisResult(
|
||||
}
|
||||
|
||||
bool join_allow_read_in_order = true;
|
||||
if (before_join)
|
||||
if (hasJoin())
|
||||
{
|
||||
/// You may find it strange but we support read_in_order for HashJoin and do not support for MergeJoin.
|
||||
auto join = before_join->getTableJoinAlgo();
|
||||
join_allow_read_in_order = typeid_cast<HashJoin *>(join.get()) && !join->hasStreamWithNonJoinedRows();
|
||||
auto join_algo = join->getTableJoinAlgo();
|
||||
join_allow_read_in_order = typeid_cast<HashJoin *>(join_algo.get()) && !join_algo->hasStreamWithNonJoinedRows();
|
||||
}
|
||||
|
||||
optimize_read_in_order =
|
||||
|
@ -178,7 +178,8 @@ struct ExpressionAnalysisResult
|
||||
bool optimize_read_in_order = false;
|
||||
bool optimize_aggregation_in_order = false;
|
||||
|
||||
ExpressionActionsPtr before_join; /// including JOIN
|
||||
ExpressionActionsPtr before_join;
|
||||
ExpressionActionsPtr join;
|
||||
ExpressionActionsPtr before_where;
|
||||
ExpressionActionsPtr before_aggregation;
|
||||
ExpressionActionsPtr before_having;
|
||||
@ -214,7 +215,7 @@ struct ExpressionAnalysisResult
|
||||
/// Filter for row-level security.
|
||||
bool hasFilter() const { return filter_info.get(); }
|
||||
|
||||
bool hasJoin() const { return before_join.get(); }
|
||||
bool hasJoin() const { return join.get(); }
|
||||
bool hasPrewhere() const { return prewhere_info.get(); }
|
||||
bool hasWhere() const { return before_where.get(); }
|
||||
bool hasHaving() const { return before_having.get(); }
|
||||
|
@ -858,12 +858,21 @@ void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, const BlockInpu
|
||||
query_plan.addStep(std::move(row_level_security_step));
|
||||
}
|
||||
|
||||
if (expressions.before_join)
|
||||
{
|
||||
QueryPlanStepPtr before_join_step = std::make_unique<ExpressionStep>(
|
||||
query_plan.getCurrentDataStream(),
|
||||
expressions.before_join,
|
||||
true);
|
||||
query_plan.addStep(std::move(before_join_step));
|
||||
}
|
||||
|
||||
if (expressions.hasJoin())
|
||||
{
|
||||
Block join_result_sample;
|
||||
JoinPtr join = expressions.before_join->getTableJoinAlgo();
|
||||
JoinPtr join = expressions.join->getTableJoinAlgo();
|
||||
|
||||
join_result_sample = ExpressionTransform::transformHeader(query_plan.getCurrentDataStream().header, expressions.before_join);
|
||||
join_result_sample = ExpressionTransform::transformHeader(query_plan.getCurrentDataStream().header, expressions.join);
|
||||
|
||||
bool inflating_join = false;
|
||||
if (join)
|
||||
@ -873,25 +882,25 @@ void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, const BlockInpu
|
||||
inflating_join = isCross(hash_join->getKind());
|
||||
}
|
||||
|
||||
QueryPlanStepPtr before_join_step;
|
||||
QueryPlanStepPtr join_step;
|
||||
if (inflating_join)
|
||||
{
|
||||
before_join_step = std::make_unique<InflatingExpressionStep>(
|
||||
join_step = std::make_unique<InflatingExpressionStep>(
|
||||
query_plan.getCurrentDataStream(),
|
||||
expressions.before_join,
|
||||
expressions.join,
|
||||
true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
before_join_step = std::make_unique<ExpressionStep>(
|
||||
join_step = std::make_unique<ExpressionStep>(
|
||||
query_plan.getCurrentDataStream(),
|
||||
expressions.before_join,
|
||||
expressions.join,
|
||||
true);
|
||||
}
|
||||
|
||||
before_join_step->setStepDescription("JOIN");
|
||||
query_plan.addStep(std::move(before_join_step));
|
||||
join_step->setStepDescription("JOIN");
|
||||
query_plan.addStep(std::move(join_step));
|
||||
|
||||
if (join)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user