From 29d2928f93e20bd1bd611801171f59f25386941d Mon Sep 17 00:00:00 2001 From: Maxim Akhmedov Date: Thu, 25 Jun 2020 00:27:53 +0300 Subject: [PATCH 1/2] Consider allocatedBytes() instead of bytes() in Storage{Buffer,Memory}. --- src/Storages/IStorage.h | 6 +++++- src/Storages/StorageBuffer.cpp | 2 +- src/Storages/StorageMemory.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index 3cf26d218cd..5b49e1cfd4c 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -449,7 +449,7 @@ public: } /// If it is possible to quickly determine exact number of bytes for the table on storage: - /// - memory (approximated) + /// - memory (approximated, resident) /// - disk (compressed) /// /// Used for: @@ -457,6 +457,10 @@ public: // /// Does not takes underlying Storage (if any) into account /// (since for Buffer we still need to know how much bytes it uses). + /// + /// Memory part should be estimated as a resident memory size. + /// In particular, alloctedBytes() is preferable over bytes() + /// when considering in-memory blocks. virtual std::optional totalBytes() const { return {}; diff --git a/src/Storages/StorageBuffer.cpp b/src/Storages/StorageBuffer.cpp index e0bd19feba9..85b61dd34f9 100644 --- a/src/Storages/StorageBuffer.cpp +++ b/src/Storages/StorageBuffer.cpp @@ -797,7 +797,7 @@ std::optional StorageBuffer::totalBytes() const for (const auto & buffer : buffers) { std::lock_guard lock(buffer.mutex); - bytes += buffer.data.bytes(); + bytes += buffer.data.allocatedBytes(); } return bytes; } diff --git a/src/Storages/StorageMemory.cpp b/src/Storages/StorageMemory.cpp index 44413caaa57..3a10b2c7e7d 100644 --- a/src/Storages/StorageMemory.cpp +++ b/src/Storages/StorageMemory.cpp @@ -169,7 +169,7 @@ std::optional StorageMemory::totalBytes() const UInt64 bytes = 0; std::lock_guard lock(mutex); for (const auto & buffer : data) - bytes += buffer.bytes(); + bytes += buffer.allocatedBytes(); return bytes; } From 119780404821d31f1df8c2971418c635c2237902 Mon Sep 17 00:00:00 2001 From: Maxim Akhmedov Date: Thu, 25 Jun 2020 16:22:07 +0300 Subject: [PATCH 2/2] Update canonized values in 00753_system_columns_and_system_tables. --- .../00753_system_columns_and_system_tables.reference | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference b/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference index e84e610bb93..1d1177ba447 100644 --- a/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference +++ b/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference @@ -29,7 +29,7 @@ Check total_bytes/total_rows for TinyLog \N \N Check total_bytes/total_rows for Memory 0 0 -2 1 +64 1 Check total_bytes/total_rows for Buffer 0 0 -100 50 +256 50