This commit is contained in:
Nikita Taranov 2024-08-09 17:47:55 +01:00
parent fec6d366e5
commit e8585a3740
4 changed files with 15 additions and 15 deletions

View File

@ -225,8 +225,7 @@ bool ConcurrentHashJoin::addBlockToJoin(const Block & right_block_, bool check_l
void ConcurrentHashJoin::joinBlock(Block & block, std::shared_ptr<ExtraBlock> & /*not_processed*/) void ConcurrentHashJoin::joinBlock(Block & block, std::shared_ptr<ExtraBlock> & /*not_processed*/)
{ {
if (hash_joins[0]->data->getKind() == JoinKind::Right || hash_joins[0]->data->getKind() == JoinKind::Full) hash_joins[0]->data->materializeColumnsFromLeftBlock(block);
materializeBlockInplace(block);
auto dispatched_blocks = dispatchBlock(table_join->getOnlyClause().key_names_left, block); auto dispatched_blocks = dispatchBlock(table_join->getOnlyClause().key_names_left, block);
block = {}; block = {};

View File

@ -446,6 +446,18 @@ void HashJoin::initRightBlockStructure(Block & saved_block_sample)
} }
} }
void HashJoin::materializeColumnsFromLeftBlock(Block & block) const
{
/** If you use FULL or RIGHT JOIN, then the columns from the "left" table must be materialized.
* Because if they are constants, then in the "not joined" rows, they may have different values
* - default values, which can differ from the values of these constants.
*/
if (kind == JoinKind::Right || kind == JoinKind::Full)
{
materializeBlockInplace(block);
}
}
Block HashJoin::materializeColumnsFromRightBlock(Block block) const Block HashJoin::materializeColumnsFromRightBlock(Block block) const
{ {
return DB::materializeColumnsFromRightBlock(std::move(block), savedBlockSample(), table_join->getAllNames(JoinTableSide::Right)); return DB::materializeColumnsFromRightBlock(std::move(block), savedBlockSample(), table_join->getAllNames(JoinTableSide::Right));
@ -943,10 +955,7 @@ void HashJoin::joinBlock(Block & block, ExtraBlockPtr & not_processed)
return; return;
} }
if (kind == JoinKind::Right || kind == JoinKind::Full) materializeColumnsFromLeftBlock(block);
{
materializeBlockInplace(block);
}
{ {
std::vector<const std::decay_t<decltype(data->maps[0])> * > maps_vector; std::vector<const std::decay_t<decltype(data->maps[0])> * > maps_vector;

View File

@ -526,6 +526,7 @@ public:
void setMaxJoinedBlockRows(size_t value) { max_joined_block_rows = value; } void setMaxJoinedBlockRows(size_t value) { max_joined_block_rows = value; }
void materializeColumnsFromLeftBlock(Block & block) const;
Block materializeColumnsFromRightBlock(Block block) const; Block materializeColumnsFromRightBlock(Block block) const;
private: private:

View File

@ -140,15 +140,6 @@ public:
auto & source_block = block.getSourceBlock(); auto & source_block = block.getSourceBlock();
size_t existing_columns = source_block.columns(); size_t existing_columns = source_block.columns();
/** If you use FULL or RIGHT JOIN, then the columns from the "left" table must be materialized.
* Because if they are constants, then in the "not joined" rows, they may have different values
* - default values, which can differ from the values of these constants.
*/
if constexpr (join_features.right || join_features.full)
{
materializeBlockInplace(source_block);
}
/** For LEFT/INNER JOIN, the saved blocks do not contain keys. /** For LEFT/INNER JOIN, the saved blocks do not contain keys.
* For FULL/RIGHT JOIN, the saved blocks contain keys; * For FULL/RIGHT JOIN, the saved blocks contain keys;
* but they will not be used at this stage of joining (and will be in `AdderNonJoined`), and they need to be skipped. * but they will not be used at this stage of joining (and will be in `AdderNonJoined`), and they need to be skipped.