From 80259659ff2feb457500f71f20752e03dfe11c2e Mon Sep 17 00:00:00 2001 From: Konstantin Bogdanov Date: Tue, 17 Sep 2024 18:03:19 +0200 Subject: [PATCH] More asserts --- src/Interpreters/HashJoin/HashJoin.cpp | 42 +++++++++++++++++++++++--- src/Interpreters/HashJoin/HashJoin.h | 1 + 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/Interpreters/HashJoin/HashJoin.cpp b/src/Interpreters/HashJoin/HashJoin.cpp index 1b8b45b94ea..23ce4fdf0f5 100644 --- a/src/Interpreters/HashJoin/HashJoin.cpp +++ b/src/Interpreters/HashJoin/HashJoin.cpp @@ -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 } } diff --git a/src/Interpreters/HashJoin/HashJoin.h b/src/Interpreters/HashJoin/HashJoin.h index 230343691ea..4c1ebbcdc66 100644 --- a/src/Interpreters/HashJoin/HashJoin.h +++ b/src/Interpreters/HashJoin/HashJoin.h @@ -470,6 +470,7 @@ private: void tryRerangeRightTableData() override; template void tryRerangeRightTableDataImpl(Map & map); + void doDebugAsserts() const; }; }