ClickHouse/tests/queries/0_stateless/01053_ssd_dictionary.sql

160 lines
5.5 KiB
MySQL
Raw Normal View History

2020-01-08 14:09:56 +00:00
SET send_logs_level = 'none';
2021-02-28 13:30:03 +00:00
DROP DATABASE IF EXISTS 01053_db;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
CREATE DATABASE 01053_db Engine = Ordinary;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
DROP TABLE IF EXISTS 01053_db.table_for_dict;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
CREATE TABLE 01053_db.table_for_dict
2020-01-08 14:09:56 +00:00
(
id UInt64,
a UInt64,
2020-01-28 20:32:41 +00:00
b Int32,
c String
2020-01-08 14:09:56 +00:00
)
ENGINE = MergeTree()
ORDER BY id;
2021-02-28 13:30:03 +00:00
INSERT INTO 01053_db.table_for_dict VALUES (1, 100, -100, 'clickhouse'), (2, 3, 4, 'database'), (5, 6, 7, 'columns'), (10, 9, 8, '');
INSERT INTO 01053_db.table_for_dict SELECT number, 0, -1, 'a' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 370;
INSERT INTO 01053_db.table_for_dict SELECT number, 0, -1, 'b' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 370, 370;
INSERT INTO 01053_db.table_for_dict SELECT number, 0, -1, 'c' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 700, 370;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
DROP DICTIONARY IF EXISTS 01053_db.ssd_dict;
2020-01-18 11:47:58 +00:00
2020-09-22 11:56:40 +00:00
-- FIXME filesystem error: in create_directory: Permission denied [/var/lib/clickhouse]
-- Probably we need rewrite it to integration test
2021-02-28 13:30:03 +00:00
CREATE DICTIONARY 01053_db.ssd_dict
2020-01-18 11:47:58 +00:00
(
id UInt64,
a UInt64 DEFAULT 0,
2020-01-28 20:32:41 +00:00
b Int32 DEFAULT -1,
c String DEFAULT 'none'
2020-01-18 11:47:58 +00:00
)
PRIMARY KEY id
2021-02-28 13:30:03 +00:00
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'table_for_dict' PASSWORD '' DB '01053_db'))
2020-01-18 11:47:58 +00:00
LIFETIME(MIN 1000 MAX 2000)
2020-05-10 17:32:03 +00:00
LAYOUT(SSD_CACHE(FILE_SIZE 8192 PATH '/var/lib/clickhouse/clickhouse_dicts/0d'));
2020-01-18 11:47:58 +00:00
SELECT 'TEST_SMALL';
2021-02-28 13:30:03 +00:00
SELECT dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(1));
SELECT dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(4));
SELECT dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(5));
SELECT dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(6));
SELECT dictGetString('01053_db.ssd_dict', 'c', toUInt64(2));
SELECT dictGetString('01053_db.ssd_dict', 'c', toUInt64(3));
2020-01-18 11:47:58 +00:00
2021-02-28 13:30:03 +00:00
SELECT * FROM 01053_db.ssd_dict ORDER BY id;
DROP DICTIONARY 01053_db.ssd_dict;
2020-01-18 11:47:58 +00:00
2021-02-28 13:30:03 +00:00
DROP TABLE IF EXISTS 01053_db.keys_table;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
CREATE TABLE 01053_db.keys_table
2020-01-08 14:09:56 +00:00
(
id UInt64
)
2020-01-08 14:14:19 +00:00
ENGINE = StripeLog();
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
INSERT INTO 01053_db.keys_table VALUES (1);
INSERT INTO 01053_db.keys_table SELECT 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 370;
INSERT INTO 01053_db.keys_table VALUES (2);
INSERT INTO 01053_db.keys_table SELECT 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 370, 370;
INSERT INTO 01053_db.keys_table VALUES (5);
INSERT INTO 01053_db.keys_table SELECT 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 700, 370;
INSERT INTO 01053_db.keys_table VALUES (10);
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
DROP DICTIONARY IF EXISTS 01053_db.ssd_dict;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
CREATE DICTIONARY 01053_db.ssd_dict
2020-01-08 14:09:56 +00:00
(
id UInt64,
a UInt64 DEFAULT 0,
2020-01-28 20:32:41 +00:00
b Int32 DEFAULT -1,
c String DEFAULT 'none'
2020-01-08 14:09:56 +00:00
)
PRIMARY KEY id
2021-02-28 13:30:03 +00:00
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'table_for_dict' PASSWORD '' DB '01053_db'))
2020-01-08 14:09:56 +00:00
LIFETIME(MIN 1000 MAX 2000)
2020-05-10 17:32:03 +00:00
LAYOUT(SSD_CACHE(FILE_SIZE 8192 PATH '/var/lib/clickhouse/clickhouse_dicts/1d' BLOCK_SIZE 512 WRITE_BUFFER_SIZE 4096 MAX_STORED_KEYS 1000000));
2020-01-08 14:09:56 +00:00
SELECT 'UPDATE DICTIONARY';
-- 118
2021-02-28 13:30:03 +00:00
SELECT sum(dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(id))) FROM 01053_db.keys_table;
2020-01-08 14:09:56 +00:00
SELECT 'VALUE FROM DISK';
-- -100
2021-02-28 13:30:03 +00:00
SELECT dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(1));
2020-01-08 14:09:56 +00:00
2020-01-26 17:35:39 +00:00
-- 'clickhouse'
2021-02-28 13:30:03 +00:00
SELECT dictGetString('01053_db.ssd_dict', 'c', toUInt64(1));
2020-01-26 17:35:39 +00:00
2020-01-08 14:09:56 +00:00
SELECT 'VALUE FROM RAM BUFFER';
-- 8
2021-02-28 13:30:03 +00:00
SELECT dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(10));
2020-01-08 14:09:56 +00:00
2020-01-26 17:35:39 +00:00
-- ''
2021-02-28 13:30:03 +00:00
SELECT dictGetString('01053_db.ssd_dict', 'c', toUInt64(10));
2020-01-26 17:35:39 +00:00
2020-01-08 14:09:56 +00:00
SELECT 'VALUES FROM DISK AND RAM BUFFER';
-- 118
2021-02-28 13:30:03 +00:00
SELECT sum(dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(id))) FROM 01053_db.keys_table;
2020-01-08 14:09:56 +00:00
2020-01-11 20:27:50 +00:00
SELECT 'HAS';
2020-03-30 07:12:12 +00:00
-- 1006
2021-02-28 13:30:03 +00:00
SELECT count() FROM 01053_db.keys_table WHERE dictHas('01053_db.ssd_dict', toUInt64(id));
2020-01-11 20:27:50 +00:00
2020-01-08 14:09:56 +00:00
SELECT 'VALUES NOT FROM TABLE';
2020-02-01 18:13:43 +00:00
-- 0 -1 none
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(1000000)), dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(1000000)), dictGetString('01053_db.ssd_dict', 'c', toUInt64(1000000));
SELECT dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(1000000)), dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(1000000)), dictGetString('01053_db.ssd_dict', 'c', toUInt64(1000000));
2020-01-08 14:09:56 +00:00
SELECT 'DUPLICATE KEYS';
2021-02-28 13:30:03 +00:00
SELECT arrayJoin([1, 2, 3, 3, 2, 1]) AS id, dictGetInt32('01053_db.ssd_dict', 'b', toUInt64(id));
2020-01-11 20:27:50 +00:00
--SELECT
2021-02-28 13:30:03 +00:00
DROP DICTIONARY IF EXISTS 01053_db.ssd_dict;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
DROP TABLE IF EXISTS 01053_db.keys_table;
2020-01-08 14:25:58 +00:00
2021-02-28 13:30:03 +00:00
CREATE TABLE 01053_db.keys_table
2020-01-08 14:25:58 +00:00
(
id UInt64
)
ENGINE = MergeTree()
ORDER BY id;
2021-02-28 13:30:03 +00:00
INSERT INTO 01053_db.keys_table VALUES (1);
INSERT INTO 01053_db.keys_table SELECT intHash64(number) FROM system.numbers LIMIT 370;
INSERT INTO 01053_db.keys_table VALUES (2);
INSERT INTO 01053_db.keys_table SELECT intHash64(number) FROM system.numbers LIMIT 370, 370;
INSERT INTO 01053_db.keys_table VALUES (5);
INSERT INTO 01053_db.keys_table SELECT intHash64(number) FROM system.numbers LIMIT 700, 370;
INSERT INTO 01053_db.keys_table VALUES (10);
2020-01-08 14:25:58 +00:00
2021-02-28 13:30:03 +00:00
OPTIMIZE TABLE 01053_db.keys_table;
2020-01-10 18:01:23 +00:00
2021-02-28 13:30:03 +00:00
CREATE DICTIONARY 01053_db.ssd_dict
2020-01-08 14:21:18 +00:00
(
id UInt64,
a UInt64 DEFAULT 0,
b Int32 DEFAULT -1
)
PRIMARY KEY id
2021-02-28 13:30:03 +00:00
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'table_for_dict' PASSWORD '' DB '01053_db'))
2020-01-08 14:21:18 +00:00
LIFETIME(MIN 1000 MAX 2000)
2020-05-10 17:32:03 +00:00
LAYOUT(SSD_CACHE(FILE_SIZE 8192 PATH '/var/lib/clickhouse/clickhouse_dicts/2d' BLOCK_SIZE 512 WRITE_BUFFER_SIZE 1024 MAX_STORED_KEYS 10));
2020-01-08 14:21:18 +00:00
2020-01-08 14:25:58 +00:00
SELECT 'UPDATE DICTIONARY (MT)';
2020-01-08 14:21:18 +00:00
-- 118
2021-02-28 13:30:03 +00:00
SELECT sum(dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(id))) FROM 01053_db.keys_table;
2020-01-08 14:21:18 +00:00
2020-01-08 14:25:58 +00:00
SELECT 'VALUES FROM DISK AND RAM BUFFER (MT)';
2020-01-08 14:21:18 +00:00
-- 118
2021-02-28 13:30:03 +00:00
SELECT sum(dictGetUInt64('01053_db.ssd_dict', 'a', toUInt64(id))) FROM 01053_db.keys_table;
2020-01-08 14:21:18 +00:00
2021-02-28 13:30:03 +00:00
DROP DICTIONARY IF EXISTS 01053_db.ssd_dict;
2020-01-08 14:21:18 +00:00
2021-02-28 13:30:03 +00:00
DROP TABLE IF EXISTS 01053_db.table_for_dict;
2020-01-08 14:09:56 +00:00
2021-02-28 13:30:03 +00:00
DROP DATABASE IF EXISTS 01053_db;