dictionary_layout
hashed
hashed_array
func
dictGetHierarchy
dictGetDescendants
CREATE TABLE hierarchical_dictionary_source_table
(
id UInt64,
parent_id UInt64
) ENGINE = MergeTree ORDER BY id;
CREATE DICTIONARY hierarchical_{dictionary_layout}_dictionary
(
id UInt64,
parent_id UInt64 HIERARCHICAL
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(DB 'default' TABLE 'hierarchical_dictionary_source_table'))
LAYOUT({dictionary_layout})
LIFETIME(0);
CREATE DICTIONARY hierarchical_flat_dictionary
(
id UInt64,
parent_id UInt64 HIERARCHICAL
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(DB 'default' TABLE 'hierarchical_dictionary_source_table'))
LAYOUT(FLAT(max_array_size 1000001))
LIFETIME(0);
INSERT INTO hierarchical_dictionary_source_table
WITH 5000 AS first_level_start, 50000 as second_level_start
SELECT
(number + 1) as id,
multiIf(id > second_level_start, id % (second_level_start - first_level_start) + first_level_start + 1,
id > first_level_start, (id % first_level_start) + 1,
0) as parent_id
FROM system.numbers
LIMIT 1000000;
SELECT {func}('hierarchical_flat_dictionary', number + 1) FROM numbers(1000000) FORMAT Null;
SELECT {func}('hierarchical_{dictionary_layout}_dictionary', number + 1) FROM numbers(1000000) FORMAT Null;
DROP TABLE IF EXISTS hierarchical_dictionary_source_table;
DROP DICTIONARY IF EXISTS hierarchical_{dictionary_layout}_dictionary;
DROP DICTIONARY IF EXISTS hierarchical_flat_dictionary;