fix JoinSwitcher logic

This commit is contained in:
chertus 2020-02-18 15:41:23 +03:00
parent a9e743d8bd
commit f1673e1344
4 changed files with 13 additions and 13 deletions

View File

@ -316,7 +316,7 @@ void Join::setSampleBlock(const Block & block)
ColumnRawPtrs key_columns = JoinCommon::extractKeysForJoin(key_names_right, block, right_table_keys, sample_block_with_columns_to_add);
initRightBlockStructure();
initRightBlockStructure(data->sample_block);
initRequiredRightKeys();
JoinCommon::createMissedColumns(sample_block_with_columns_to_add);
@ -481,13 +481,12 @@ void Join::initRequiredRightKeys()
}
}
void Join::initRightBlockStructure()
void Join::initRightBlockStructure(Block & saved_block_sample)
{
auto & saved_block_sample = data->sample_block;
if (isRightOrFull(kind))
/// We could remove key columns for LEFT | INNER HashJoin but we should keep them for JoinSwitcher (if any).
bool save_key_columns = !table_join->forceHashJoin() || isRightOrFull(kind);
if (save_key_columns)
{
/// Save keys for NonJoinedBlockInputStream
saved_block_sample = right_table_keys.cloneEmpty();
}
else if (strictness == ASTTableJoin::Strictness::Asof)

View File

@ -369,7 +369,7 @@ private:
/// Modify (structure) right block to save it in block list
Block structureRightBlock(const Block & stored_block) const;
void initRightBlockStructure();
void initRightBlockStructure(Block & saved_block_sample);
void initRequiredRightKeys();
template <ASTTableJoin::Kind KIND, ASTTableJoin::Strictness STRICTNESS, typename Maps>

View File

@ -64,7 +64,7 @@ void JoinSwitcher::switchJoin()
if (right_blocks.size())
{
positions.reserve(right_sample_block.columns());
Block & tmp_block = *right_blocks.begin();
const Block & tmp_block = *right_blocks.begin();
for (const auto & sample_column : right_sample_block)
{
positions.emplace_back(tmp_block.getPositionByName(sample_column.name));
@ -72,14 +72,15 @@ void JoinSwitcher::switchJoin()
}
}
for (Block & block : right_blocks)
for (Block & saved_block : right_blocks)
{
Block restored_block;
for (size_t i = 0; i < positions.size(); ++i)
{
auto & column = block.getByPosition(positions[i]);
block.insert(correctNullability(std::move(column), is_nullable[i]));
join->addJoinedBlock(block);
auto & column = saved_block.getByPosition(positions[i]);
restored_block.insert(correctNullability(std::move(column), is_nullable[i]));
}
join->addJoinedBlock(restored_block);
}
switched = true;

View File

@ -66,7 +66,7 @@ private:
bool switched;
mutable std::mutex switch_mutex;
std::shared_ptr<AnalyzedJoin> table_join;
Block right_sample_block;
const Block right_sample_block;
void switchJoin();
};