mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
808d1a0215
It was initially implemented in #15454, but was reverted in #21948 (due to higher memory usage). This implementation differs from the initial, since now there is separate attribute to enable preallocation, before it was done automatically, but this has problems with duplicates in the source. Plus this implementation does not uses dynamic_cast, instead it extends IDictionarySource interface.
79 lines
2.4 KiB
Bash
Executable File
79 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# shellcheck disable=SC2031
|
|
# shellcheck disable=SC2030
|
|
|
|
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
# shellcheck source=../shell_config.sh
|
|
. "$CUR_DIR"/../shell_config.sh
|
|
|
|
$CLICKHOUSE_CLIENT -nm -q "
|
|
DROP TABLE IF EXISTS data_01509;
|
|
DROP DICTIONARY IF EXISTS dict_01509;
|
|
DROP DICTIONARY IF EXISTS dict_01509_preallocate;
|
|
|
|
CREATE TABLE data_01509
|
|
(
|
|
key UInt64,
|
|
value String
|
|
)
|
|
ENGINE = MergeTree()
|
|
ORDER BY key;
|
|
INSERT INTO data_01509 SELECT number key, toString(number) value FROM numbers(10e3);
|
|
"
|
|
|
|
# regular
|
|
$CLICKHOUSE_CLIENT -nm -q "
|
|
CREATE DICTIONARY dict_01509
|
|
(
|
|
key UInt64,
|
|
value String DEFAULT '-'
|
|
)
|
|
PRIMARY KEY key
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'data_01509'))
|
|
LAYOUT(SPARSE_HASHED(PREALLOCATE 0))
|
|
LIFETIME(0);
|
|
SHOW CREATE DICTIONARY dict_01509;
|
|
"
|
|
(
|
|
# start new shell to avoid overriding variables for other client invocation
|
|
CLICKHOUSE_CLIENT=${CLICKHOUSE_CLIENT/--send_logs_level=${CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL}/--send_logs_level=trace}
|
|
$CLICKHOUSE_CLIENT -nm -q "SYSTEM RELOAD DICTIONARY dict_01509" |& grep -o "HashedDictionary.*"
|
|
)
|
|
|
|
# with preallocation
|
|
$CLICKHOUSE_CLIENT -nm -q "
|
|
CREATE DICTIONARY dict_01509_preallocate
|
|
(
|
|
key UInt64,
|
|
value String DEFAULT '-'
|
|
)
|
|
PRIMARY KEY key
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'data_01509'))
|
|
LAYOUT(SPARSE_HASHED(PREALLOCATE 1))
|
|
LIFETIME(0);
|
|
SHOW CREATE DICTIONARY dict_01509_preallocate;
|
|
SYSTEM RELOAD DICTIONARY dict_01509_preallocate;
|
|
"
|
|
(
|
|
# start new shell to avoid overriding variables for other client invocation
|
|
CLICKHOUSE_CLIENT=${CLICKHOUSE_CLIENT/--send_logs_level=${CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL}/--send_logs_level=trace}
|
|
$CLICKHOUSE_CLIENT -nm -q "SYSTEM RELOAD DICTIONARY dict_01509_preallocate" |& grep -o "HashedDictionary.*"
|
|
)
|
|
|
|
$CLICKHOUSE_CLIENT -nm -q "
|
|
SELECT dictGet('dict_01509', 'value', toUInt64(1e12));
|
|
SELECT dictGet('dict_01509', 'value', toUInt64(0));
|
|
SELECT count() FROM dict_01509;
|
|
|
|
SELECT dictGet('dict_01509_preallocate', 'value', toUInt64(1e12));
|
|
SELECT dictGet('dict_01509_preallocate', 'value', toUInt64(0));
|
|
SELECT count() FROM dict_01509_preallocate;
|
|
"
|
|
|
|
$CLICKHOUSE_CLIENT -nm -q "
|
|
DROP TABLE data_01509;
|
|
DROP DICTIONARY dict_01509;
|
|
DROP DICTIONARY dict_01509_preallocate;
|
|
"
|