More asserts

This commit is contained in:
Konstantin Bogdanov 2024-09-17 18:03:19 +02:00
parent 2fce90ab76
commit 80259659ff
Signed by: thevar1able
GPG Key ID: DB399448D9FE52F1
2 changed files with 38 additions and 5 deletions

View File

@ -338,12 +338,8 @@ size_t HashJoin::getTotalRowCount() const
return res;
}
size_t HashJoin::getTotalByteCount() const
void HashJoin::doDebugAsserts() const
{
if (!data)
return 0;
#ifndef NDEBUG
size_t debug_blocks_allocated_size = 0;
for (const auto & block : data->blocks)
debug_blocks_allocated_size += block.allocatedBytes();
@ -359,6 +355,15 @@ size_t HashJoin::getTotalByteCount() const
if (data->blocks_nullmaps_allocated_size != debug_blocks_nullmaps_allocated_size)
throw Exception(ErrorCodes::LOGICAL_ERROR, "data->blocks_nullmaps_allocated_size != debug_blocks_nullmaps_allocated_size ({} != {})",
data->blocks_nullmaps_allocated_size, debug_blocks_nullmaps_allocated_size);
}
size_t HashJoin::getTotalByteCount() const
{
if (!data)
return 0;
#ifndef NDEBUG
doDebugAsserts();
#endif
size_t res = 0;
@ -544,10 +549,17 @@ bool HashJoin::addBlockToJoin(const Block & source_block_, bool check_limits)
have_compressed = true;
}
#ifndef NDEBUG
doDebugAsserts();
#endif
data->blocks_allocated_size += block_to_save.allocatedBytes();
data->blocks.emplace_back(std::move(block_to_save));
Block * stored_block = &data->blocks.back();
#ifndef NDEBUG
doDebugAsserts();
#endif
if (rows)
data->empty = false;
@ -634,9 +646,15 @@ bool HashJoin::addBlockToJoin(const Block & source_block_, bool check_limits)
if (!flag_per_row && !is_inserted)
{
#ifndef NDEBUG
doDebugAsserts();
#endif
LOG_TRACE(log, "Skipping inserting block with {} rows", rows);
data->blocks_allocated_size -= stored_block->allocatedBytes();
data->blocks.pop_back();
#ifndef NDEBUG
doDebugAsserts();
#endif
}
if (!check_limits)
@ -687,6 +705,10 @@ void HashJoin::shrinkStoredBlocksToFit(size_t & total_bytes_in_join, bool force_
stored_block = stored_block.shrinkToFit();
size_t new_size = stored_block.allocatedBytes();
#ifndef NDEBUG
doDebugAsserts();
#endif
if (old_size >= new_size)
{
if (data->blocks_allocated_size < old_size - new_size)
@ -700,6 +722,10 @@ void HashJoin::shrinkStoredBlocksToFit(size_t & total_bytes_in_join, bool force_
else
/// Sometimes after clone resized block can be bigger than original
data->blocks_allocated_size += new_size - old_size;
#ifndef NDEBUG
doDebugAsserts();
#endif
}
auto new_total_bytes_in_join = getTotalByteCount();
@ -1415,7 +1441,13 @@ void HashJoin::tryRerangeRightTableDataImpl(Map & map [[maybe_unused]])
};
BlocksList sorted_blocks;
visit_rows_map(sorted_blocks, map);
#ifdef NDEBUG
doDebugAsserts();
#endif
data->blocks.swap(sorted_blocks);
#ifdef NDEBUG
doDebugAsserts();
#endif
}
}

View File

@ -470,6 +470,7 @@ private:
void tryRerangeRightTableData() override;
template <JoinKind KIND, typename Map, JoinStrictness STRICTNESS>
void tryRerangeRightTableDataImpl(Map & map);
void doDebugAsserts() const;
};
}