Merge pull request #22867 from azat/sparse_hashed-bytes_allocated-fix

Fix bytes_allocated for sparse_hashed dictionaries
This commit is contained in:
alexey-milovidov 2021-04-09 09:50:04 +03:00 committed by GitHub
commit f7edcdf7c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -567,7 +567,11 @@ void HashedDictionary<dictionary_key_type, sparse>::calculateBytesAllocated()
if constexpr (sparse || std::is_same_v<AttributeValueType, Field>)
{
bytes_allocated += container.max_size() * (sizeof(KeyType) + sizeof(AttributeValueType));
/// bucket_count() - Returns table size, that includes empty and deleted
/// size() - Returns table size, w/o empty and deleted
/// and since this is sparsehash, empty cells should not be significant,
/// and since items cannot be removed from the dictionary, deleted is also not important.
bytes_allocated += container.size() * (sizeof(KeyType) + sizeof(AttributeValueType));
bucket_count = container.bucket_count();
}
else

View File

@ -0,0 +1,30 @@
DROP TABLE IF EXISTS data_01802;
DROP DICTIONARY IF EXISTS dict_01802;
CREATE TABLE data_01802
(
id UInt64,
value UInt16
)
ENGINE = Memory();
INSERT INTO data_01802 VALUES(0, 0);
INSERT INTO data_01802 VALUES(1, 0);
INSERT INTO data_01802 VALUES(2, 0);
CREATE DICTIONARY dict_01802
(
id UInt64,
value UInt16
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'data_01802'))
LIFETIME(MIN 1 MAX 1000)
LAYOUT(SPARSE_HASHED());
SYSTEM RELOAD DICTIONARY dict_01802;
SELECT bytes_allocated FROM system.dictionaries WHERE database = currentDatabase() AND name = 'dict_01802';
DROP TABLE data_01802;
DROP DICTIONARY dict_01802;