2021-09-12 12:35:27 +00:00
|
|
|
-- Tags: no-parallel
|
|
|
|
|
2021-03-26 13:57:21 +00:00
|
|
|
DROP DATABASE IF EXISTS 01778_db;
|
|
|
|
CREATE DATABASE 01778_db;
|
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
CREATE TABLE 01778_db.hierarchy_source_table (id UInt64, parent_id UInt64) ENGINE = TinyLog;
|
|
|
|
INSERT INTO 01778_db.hierarchy_source_table VALUES (1, 0), (2, 1), (3, 1), (4, 2);
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
CREATE DICTIONARY 01778_db.hierarchy_flat_dictionary
|
2021-03-26 13:57:21 +00:00
|
|
|
(
|
|
|
|
id UInt64,
|
|
|
|
parent_id UInt64 HIERARCHICAL
|
|
|
|
)
|
|
|
|
PRIMARY KEY id
|
2021-03-26 18:01:56 +00:00
|
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
|
2021-03-26 13:57:21 +00:00
|
|
|
LAYOUT(FLAT())
|
|
|
|
LIFETIME(MIN 1 MAX 1000);
|
|
|
|
|
|
|
|
SELECT 'Flat dictionary';
|
|
|
|
|
|
|
|
SELECT 'Get hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetHierarchy('01778_db.hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get is in hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictIsIn('01778_db.hierarchy_flat_dictionary', number, number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get children';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetChildren('01778_db.hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get all descendants';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetDescendants('01778_db.hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get descendants at first level';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetDescendants('01778_db.hierarchy_flat_dictionary', number, 1) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
DROP DICTIONARY 01778_db.hierarchy_flat_dictionary;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
CREATE DICTIONARY 01778_db.hierarchy_hashed_dictionary
|
2021-03-26 13:57:21 +00:00
|
|
|
(
|
|
|
|
id UInt64,
|
|
|
|
parent_id UInt64 HIERARCHICAL
|
|
|
|
)
|
|
|
|
PRIMARY KEY id
|
2021-03-26 18:01:56 +00:00
|
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
|
|
|
|
LAYOUT(HASHED())
|
2021-03-26 13:57:21 +00:00
|
|
|
LIFETIME(MIN 1 MAX 1000);
|
|
|
|
|
|
|
|
SELECT 'Hashed dictionary';
|
|
|
|
|
|
|
|
SELECT 'Get hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetHierarchy('01778_db.hierarchy_hashed_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get is in hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictIsIn('01778_db.hierarchy_hashed_dictionary', number, number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get children';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetChildren('01778_db.hierarchy_hashed_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get all descendants';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetDescendants('01778_db.hierarchy_hashed_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get descendants at first level';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetDescendants('01778_db.hierarchy_hashed_dictionary', number, 1) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
DROP DICTIONARY 01778_db.hierarchy_hashed_dictionary;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
CREATE DICTIONARY 01778_db.hierarchy_cache_dictionary
|
2021-03-26 13:57:21 +00:00
|
|
|
(
|
|
|
|
id UInt64,
|
|
|
|
parent_id UInt64 HIERARCHICAL
|
|
|
|
)
|
|
|
|
PRIMARY KEY id
|
2021-03-26 18:01:56 +00:00
|
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
|
2021-03-26 13:57:21 +00:00
|
|
|
LAYOUT(CACHE(SIZE_IN_CELLS 10))
|
|
|
|
LIFETIME(MIN 1 MAX 1000);
|
|
|
|
|
|
|
|
SELECT 'Cache dictionary';
|
|
|
|
|
|
|
|
SELECT 'Get hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetHierarchy('01778_db.hierarchy_cache_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get is in hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictIsIn('01778_db.hierarchy_cache_dictionary', number, number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
DROP DICTIONARY 01778_db.hierarchy_cache_dictionary;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
CREATE DICTIONARY 01778_db.hierarchy_direct_dictionary
|
2021-03-26 13:57:21 +00:00
|
|
|
(
|
|
|
|
id UInt64,
|
|
|
|
parent_id UInt64 HIERARCHICAL
|
|
|
|
)
|
|
|
|
PRIMARY KEY id
|
2021-03-26 18:01:56 +00:00
|
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'hierarchy_source_table' DB '01778_db'))
|
2021-03-26 13:57:21 +00:00
|
|
|
LAYOUT(DIRECT());
|
|
|
|
|
|
|
|
SELECT 'Direct dictionary';
|
|
|
|
|
|
|
|
SELECT 'Get hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictGetHierarchy('01778_db.hierarchy_direct_dictionary', number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
SELECT 'Get is in hierarchy';
|
2021-03-26 18:01:56 +00:00
|
|
|
SELECT dictIsIn('01778_db.hierarchy_direct_dictionary', number, number) FROM system.numbers LIMIT 6;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
DROP DICTIONARY 01778_db.hierarchy_direct_dictionary;
|
2021-03-26 13:57:21 +00:00
|
|
|
|
2021-03-26 18:01:56 +00:00
|
|
|
DROP TABLE 01778_db.hierarchy_source_table;
|
2021-03-26 13:57:21 +00:00
|
|
|
DROP DATABASE 01778_db;
|