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; } 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