Skip to content

Commit a01bc05

Browse files
committed
join_alias_dups: fix + all debug logs
1 parent 6feb251 commit a01bc05

19 files changed

Lines changed: 486 additions & 16 deletions

src/Core/ColumnWithTypeAndName.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ void ColumnWithTypeAndName::dumpStructure(WriteBuffer & out) const
4747
dumpNameAndType(out);
4848

4949
if (column)
50-
out << ' ' << column->dumpStructure();
50+
out << "<==>" << ' ' << column->dumpStructure();
5151
else
52-
out << " nullptr";
52+
out << "<==>" << " nullptr";
5353
}
5454

5555
String ColumnWithTypeAndName::dumpStructure() const

src/Interpreters/ActionsDAG.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,17 @@ ActionsDAG ActionsDAG::makeConvertingActions(
17131713
size_t num_input_columns = source.size();
17141714
size_t num_result_columns = result.size();
17151715

1716+
for (const auto & s : source)
1717+
{
1718+
LOG_TRACE(&Poco::Logger::get("ActionsDAG"), "makeConvertingActions source {} {}", s.name, s.type->getName());
1719+
}
1720+
for (const auto & r : result)
1721+
{
1722+
LOG_TRACE(&Poco::Logger::get("ActionsDAG"), "makeConvertingActions result {} {}", r.name, r.type->getName());
1723+
}
1724+
1725+
1726+
17161727
if (mode == MatchColumnsMode::Position && num_input_columns != num_result_columns)
17171728
throw Exception(ErrorCodes::NUMBER_OF_COLUMNS_DOESNT_MATCH, "Number of columns doesn't match (source: {} and result: {})", num_input_columns, num_result_columns);
17181729

@@ -1729,7 +1740,11 @@ ActionsDAG ActionsDAG::makeConvertingActions(
17291740
{
17301741
size_t input_nodes_size = actions_dag.inputs.size();
17311742
for (size_t pos = 0; pos < input_nodes_size; ++pos)
1743+
{
1744+
LOG_TRACE(&Poco::Logger::get("ActionsDAG"), "makeConvertingActions input name {}", actions_dag.inputs[pos]->result_name);
17321745
inputs[actions_dag.inputs[pos]->result_name].push_back(pos);
1746+
}
1747+
17331748
}
17341749

17351750
for (size_t result_col_num = 0; result_col_num < num_result_columns; ++result_col_num)

src/Interpreters/ExpressionActions.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,12 +1194,25 @@ ExpressionActionsChainSteps::JoinStep::JoinStep(
11941194

11951195
void ExpressionActionsChainSteps::JoinStep::finalize(const NameSet & required_output_)
11961196
{
1197+
LOG_TRACE(getLogger("ExpressionActions"), "Top of JoinStep::finalize");
1198+
for (const auto & col : result_columns)
1199+
{
1200+
LOG_TRACE(getLogger("ExpressionActions"), "JoinStep::finalize result_columns: col name {} type {}", col.name, col.type);
1201+
}
1202+
for (const auto & col : required_columns)
1203+
{
1204+
LOG_TRACE(getLogger("ExpressionActions"), "JoinStep::finalize required_columns: col name {} type {}", col.name, col.type);
1205+
}
1206+
1207+
1208+
11971209
/// We need to update required and result columns by removing unused ones.
11981210
NamesAndTypesList new_required_columns;
11991211
ColumnsWithTypeAndName new_result_columns;
12001212

12011213
/// That's an input columns we need.
12021214
NameSet required_names = required_output_;
1215+
12031216
for (const auto & name : analyzed_join->getAllNames(JoinTableSide::Left))
12041217
required_names.emplace(name);
12051218

@@ -1225,6 +1238,16 @@ void ExpressionActionsChainSteps::JoinStep::finalize(const NameSet & required_ou
12251238

12261239
std::swap(required_columns, new_required_columns);
12271240
std::swap(result_columns, new_result_columns);
1241+
1242+
LOG_TRACE(getLogger("ExpressionActions"), "Bottom of ExpressionActionsChainSteps::JoinStep::finalize");
1243+
for (const auto & col : result_columns)
1244+
{
1245+
LOG_TRACE(getLogger("ExpressionActions"), "ExpressionActionsChainSteps::JoinStep::finalize result_columns: col name {} type {}", col.name, col.type);
1246+
}
1247+
for (const auto & col : required_columns)
1248+
{
1249+
LOG_TRACE(getLogger("ExpressionActions"), "ExpressionActionsChainSteps::JoinStep::finalize required_columns: col name {} type {}", col.name, col.type);
1250+
}
12281251
}
12291252

12301253
ActionsAndProjectInputsFlagPtr & ExpressionActionsChainSteps::Step::actions()

src/Interpreters/ExpressionAnalyzer.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,15 @@ NamesAndTypesList ExpressionAnalyzer::getColumnsAfterArrayJoin(ActionsDAG & acti
267267

268268
NamesAndTypesList ExpressionAnalyzer::analyzeJoin(ActionsDAG & actions, const NamesAndTypesList & src_columns)
269269
{
270+
LOG_TRACE(getLogger(), "Top of analyzeJoin");
270271
const auto * select_query = query->as<ASTSelectQuery>();
271272
if (!select_query)
272273
return {};
273274

274275
const ASTTablesInSelectQueryElement * join = select_query->join();
275276
if (join)
276277
{
278+
LOG_TRACE(getLogger(), "analyzeJoin - join");
277279
getRootActionsNoMakeSet(analyzedJoin().leftKeysList(), actions, false);
278280
auto sample_columns = actions.getNamesAndTypesList();
279281
syntax->analyzed_join->addJoinedColumnsAndCorrectTypes(sample_columns, true);
@@ -475,7 +477,7 @@ void ExpressionAnalyzer::initGlobalSubqueriesAndExternalTables(bool do_global, b
475477
if (do_global)
476478
{
477479
GlobalSubqueriesVisitor::Data subqueries_data(
478-
getContext(), subquery_depth, isRemoteStorage(), is_explain, external_tables, prepared_sets, has_global_subqueries, syntax->analyzed_join.get());
480+
getContext(), subquery_depth, isRemoteStorage(), is_explain, external_tables, prepared_sets, has_global_subqueries , syntax->analyzed_join.get());
479481
GlobalSubqueriesVisitor(subqueries_data).visit(query);
480482
}
481483
}
@@ -979,15 +981,28 @@ JoinPtr SelectQueryExpressionAnalyzer::appendJoin(
979981

980982
if (converting_actions)
981983
{
984+
LOG_TRACE(getLogger(), "appendJoin: adding converting actions");
982985
converting_join_columns = std::make_shared<ActionsAndProjectInputsFlag>();
983986
converting_join_columns->dag = std::move(*converting_actions);
984987
chain.steps.push_back(std::make_unique<ExpressionActionsChainSteps::ExpressionActionsStep>(converting_join_columns));
985988
chain.addStep();
986989
}
987990

988991
ExpressionActionsChainSteps::Step & step = chain.lastStep(columns_after_array_join);
989-
chain.steps.push_back(std::make_unique<ExpressionActionsChainSteps::JoinStep>(
990-
syntax->analyzed_join, join, step.getResultColumns()));
992+
auto js = std::make_unique<ExpressionActionsChainSteps::JoinStep>(
993+
syntax->analyzed_join, join, step.getResultColumns());
994+
995+
for (const auto & col : js->result_columns)
996+
{
997+
LOG_TRACE(getLogger(), "appendJoin result_columns name {}, type {}", col.name, col.type->getName());
998+
}
999+
for (const auto & col : js->required_columns)
1000+
{
1001+
LOG_TRACE(getLogger(), "appendJoin required_columns name {}, type {}", col.name, col.type->getName());
1002+
}
1003+
1004+
1005+
chain.steps.push_back(std::move(js));
9911006
chain.addStep();
9921007
return join;
9931008
}
@@ -1068,6 +1083,7 @@ static std::shared_ptr<IJoin> chooseJoinAlgorithm(
10681083
std::shared_ptr<TableJoin> analyzed_join, const ColumnsWithTypeAndName & left_sample_columns, std::unique_ptr<QueryPlan> & joined_plan, ContextPtr context)
10691084
{
10701085
auto right_sample_block = joined_plan->getCurrentHeader();
1086+
LOG_TRACE(getLogger(), "right_sample_block {}", right_sample_block->dumpStructure());
10711087
const auto & join_algorithms = analyzed_join->getEnabledJoinAlgorithms();
10721088
for (const auto alg : join_algorithms)
10731089
{
@@ -1089,6 +1105,18 @@ static std::unique_ptr<QueryPlan> buildJoinedPlan(
10891105
{
10901106
/// Actions which need to be calculated on joined block.
10911107
auto joined_block_actions = analyzed_join.createJoinedBlockActions(context, std::move(prepared_sets));
1108+
1109+
1110+
for (const auto & s : joined_block_actions.getRequiredColumns())
1111+
{
1112+
LOG_DEBUG(getLogger(), "joined_block_actions source {} {}", s.name, s.type->getName());
1113+
}
1114+
for (const auto & r : joined_block_actions.getResultColumns())
1115+
{
1116+
LOG_DEBUG(getLogger(), "joined_block_actions result {} {}", r.name, r.type->getName());
1117+
}
1118+
1119+
10921120
NamesWithAliases required_columns_with_aliases = analyzed_join.getRequiredColumns(
10931121
Block(joined_block_actions.getResultColumns()), joined_block_actions.getRequiredColumns().getNames());
10941122

@@ -1111,6 +1139,8 @@ static std::unique_ptr<QueryPlan> buildJoinedPlan(
11111139
interpreter->buildQueryPlan(*joined_plan);
11121140
{
11131141
auto original_right_columns = interpreter->getSampleBlock();
1142+
LOG_DEBUG(getLogger(), "original_right_columns {}", original_right_columns->dumpStructure());
1143+
11141144
ActionsDAG rename_dag(original_right_columns->getColumnsWithTypeAndName());
11151145
for (const auto & name_with_alias : required_columns_with_aliases)
11161146
{

src/Interpreters/HashJoin/HashJoin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ HashJoin::HashJoin(
160160
{
161161
if (!column.column)
162162
column.column = column.type->createColumn();
163+
LOG_TEST(
164+
log,
165+
"column: {}, {} ", column.name, column.type);
163166
}
164167

165168
LOG_TEST(

0 commit comments

Comments
 (0)