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

160 lines
6.1 KiB
MySQL
Raw Normal View History

2020-01-08 14:09:56 +00:00
SET send_logs_level = 'none';
DROP DATABASE IF EXISTS database_for_dict;
CREATE DATABASE database_for_dict Engine = Ordinary;
DROP TABLE IF EXISTS database_for_dict.table_for_dict;
CREATE TABLE database_for_dict.table_for_dict
(
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;
2020-01-28 20:32:41 +00:00
INSERT INTO database_for_dict.table_for_dict VALUES (1, 100, -100, 'clickhouse'), (2, 3, 4, 'database'), (5, 6, 7, 'columns'), (10, 9, 8, '');
2020-02-01 18:19:39 +00:00
INSERT INTO database_for_dict.table_for_dict SELECT number, 0, -1, 'a' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 370;
2020-03-30 07:12:12 +00:00
INSERT INTO database_for_dict.table_for_dict SELECT number, 0, -1, 'b' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 370, 370;
INSERT INTO database_for_dict.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
2020-01-18 11:47:58 +00:00
DROP DICTIONARY IF EXISTS database_for_dict.ssd_dict;
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
2020-01-18 11:47:58 +00:00
CREATE DICTIONARY database_for_dict.ssd_dict
(
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
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict'))
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';
SELECT dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(1));
SELECT dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(4));
SELECT dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(5));
SELECT dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(6));
2020-01-28 20:32:41 +00:00
SELECT dictGetString('database_for_dict.ssd_dict', 'c', toUInt64(2));
SELECT dictGetString('database_for_dict.ssd_dict', 'c', toUInt64(3));
2020-01-18 11:47:58 +00:00
2020-01-26 17:35:39 +00:00
SELECT * FROM database_for_dict.ssd_dict ORDER BY id;
2020-01-18 11:47:58 +00:00
DROP DICTIONARY database_for_dict.ssd_dict;
2020-01-08 14:09:56 +00:00
DROP TABLE IF EXISTS database_for_dict.keys_table;
CREATE TABLE database_for_dict.keys_table
(
id UInt64
)
2020-01-08 14:14:19 +00:00
ENGINE = StripeLog();
2020-01-08 14:09:56 +00:00
INSERT INTO database_for_dict.keys_table VALUES (1);
2020-03-30 07:12:12 +00:00
INSERT INTO database_for_dict.keys_table SELECT 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 370;
2020-01-08 14:09:56 +00:00
INSERT INTO database_for_dict.keys_table VALUES (2);
2020-03-30 07:12:12 +00:00
INSERT INTO database_for_dict.keys_table SELECT 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 370, 370;
2020-01-08 14:09:56 +00:00
INSERT INTO database_for_dict.keys_table VALUES (5);
2020-03-30 07:12:12 +00:00
INSERT INTO database_for_dict.keys_table SELECT 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 700, 370;
2020-01-08 14:09:56 +00:00
INSERT INTO database_for_dict.keys_table VALUES (10);
DROP DICTIONARY IF EXISTS database_for_dict.ssd_dict;
CREATE DICTIONARY database_for_dict.ssd_dict
(
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
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict'))
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
SELECT sum(dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(id))) FROM database_for_dict.keys_table;
SELECT 'VALUE FROM DISK';
-- -100
SELECT dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(1));
2020-01-26 17:35:39 +00:00
-- 'clickhouse'
2020-01-28 20:32:41 +00:00
SELECT dictGetString('database_for_dict.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
SELECT dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(10));
2020-01-26 17:35:39 +00:00
-- ''
2020-01-28 20:32:41 +00:00
SELECT dictGetString('database_for_dict.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
SELECT sum(dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(id))) FROM database_for_dict.keys_table;
2020-01-11 20:27:50 +00:00
SELECT 'HAS';
2020-03-30 07:12:12 +00:00
-- 1006
SELECT count() FROM database_for_dict.keys_table WHERE dictHas('database_for_dict.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
SELECT dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(1000000)), dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(1000000)), dictGetString('database_for_dict.ssd_dict', 'c', toUInt64(1000000));
SELECT dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(1000000)), dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(1000000)), dictGetString('database_for_dict.ssd_dict', 'c', toUInt64(1000000));
2020-01-08 14:09:56 +00:00
SELECT 'DUPLICATE KEYS';
SELECT arrayJoin([1, 2, 3, 3, 2, 1]) AS id, dictGetInt32('database_for_dict.ssd_dict', 'b', toUInt64(id));
2020-01-11 20:27:50 +00:00
--SELECT
2020-01-08 14:09:56 +00:00
DROP DICTIONARY IF EXISTS database_for_dict.ssd_dict;
2020-01-08 14:25:58 +00:00
DROP TABLE IF EXISTS database_for_dict.keys_table;
CREATE TABLE database_for_dict.keys_table
(
id UInt64
)
ENGINE = MergeTree()
ORDER BY id;
INSERT INTO database_for_dict.keys_table VALUES (1);
INSERT INTO database_for_dict.keys_table SELECT intHash64(number) FROM system.numbers LIMIT 370;
INSERT INTO database_for_dict.keys_table VALUES (2);
INSERT INTO database_for_dict.keys_table SELECT intHash64(number) FROM system.numbers LIMIT 370, 370;
INSERT INTO database_for_dict.keys_table VALUES (5);
INSERT INTO database_for_dict.keys_table SELECT intHash64(number) FROM system.numbers LIMIT 700, 370;
INSERT INTO database_for_dict.keys_table VALUES (10);
2020-01-10 18:01:23 +00:00
OPTIMIZE TABLE database_for_dict.keys_table;
2020-01-08 14:21:18 +00:00
CREATE DICTIONARY database_for_dict.ssd_dict
(
id UInt64,
a UInt64 DEFAULT 0,
b Int32 DEFAULT -1
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict'))
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
2020-01-08 14:25:58 +00:00
SELECT sum(dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(id))) FROM database_for_dict.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
2020-01-08 14:25:58 +00:00
SELECT sum(dictGetUInt64('database_for_dict.ssd_dict', 'a', toUInt64(id))) FROM database_for_dict.keys_table;
2020-01-08 14:21:18 +00:00
DROP DICTIONARY IF EXISTS database_for_dict.ssd_dict;
2020-01-08 14:09:56 +00:00
DROP TABLE IF EXISTS database_for_dict.table_for_dict;
DROP DATABASE IF EXISTS database_for_dict;