ClickHouse/tests/queries/0_stateless/01280_ssd_complex_key_dictionary.sql

140 lines
5.5 KiB
MySQL
Raw Normal View History

2020-04-30 20:51:06 +00:00
SET send_logs_level = 'none';
2021-02-28 13:30:03 +00:00
DROP DATABASE IF EXISTS 01280_db;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
CREATE DATABASE 01280_db Engine = Ordinary;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
DROP TABLE IF EXISTS 01280_db.table_for_dict;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
CREATE TABLE 01280_db.table_for_dict
2020-04-30 20:51:06 +00:00
(
k1 String,
k2 Int32,
a UInt64,
b Int32,
c String
)
ENGINE = MergeTree()
ORDER BY (k1, k2);
2021-02-28 13:30:03 +00:00
INSERT INTO 01280_db.table_for_dict VALUES (toString(1), 3, 100, -100, 'clickhouse'), (toString(2), -1, 3, 4, 'database'), (toString(5), -3, 6, 7, 'columns'), (toString(10), -20, 9, 8, '');
INSERT INTO 01280_db.table_for_dict SELECT toString(number), number + 1, 0, -1, 'a' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 370;
INSERT INTO 01280_db.table_for_dict SELECT toString(number), number + 10, 0, -1, 'b' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 370, 370;
INSERT INTO 01280_db.table_for_dict SELECT toString(number), number + 100, 0, -1, 'c' FROM system.numbers WHERE number NOT IN (1, 2, 5, 10) LIMIT 700, 370;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
DROP DICTIONARY IF EXISTS 01280_db.ssd_dict;
2020-04-30 20:51:06 +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 01280_db.ssd_dict
2020-04-30 20:51:06 +00:00
(
k1 String,
k2 Int32,
a UInt64 DEFAULT 0,
b Int32 DEFAULT -1,
c String DEFAULT 'none'
)
PRIMARY KEY k1, k2
2021-02-28 13:30:03 +00:00
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'table_for_dict' PASSWORD '' DB '01280_db'))
2020-04-30 20:51:06 +00:00
LIFETIME(MIN 1000 MAX 2000)
LAYOUT(COMPLEX_KEY_SSD_CACHE(FILE_SIZE 8192 PATH '/var/lib/clickhouse/clickhouse_dicts/0d'));
2020-04-30 20:51:06 +00:00
SELECT 'TEST_SMALL';
SELECT 'VALUE FROM RAM BUFFER';
2021-03-13 20:26:01 +00:00
SELECT dictHas('01280_db.ssd_dict', 'a', tuple('1')); -- { serverError 43 }
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', tuple('1', toInt32(3)));
SELECT dictGetInt32('01280_db.ssd_dict', 'b', tuple('1', toInt32(3)));
SELECT dictGetString('01280_db.ssd_dict', 'c', tuple('1', toInt32(3)));
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', tuple('1', toInt32(3)));
SELECT dictGetInt32('01280_db.ssd_dict', 'b', tuple('1', toInt32(3)));
SELECT dictGetString('01280_db.ssd_dict', 'c', tuple('1', toInt32(3)));
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', tuple('2', toInt32(-1)));
SELECT dictGetInt32('01280_db.ssd_dict', 'b', tuple('2', toInt32(-1)));
SELECT dictGetString('01280_db.ssd_dict', 'c', tuple('2', toInt32(-1)));
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', tuple('5', toInt32(-3)));
SELECT dictGetInt32('01280_db.ssd_dict', 'b', tuple('5', toInt32(-3)));
SELECT dictGetString('01280_db.ssd_dict', 'c', tuple('5', toInt32(-3)));
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', tuple('10', toInt32(-20)));
SELECT dictGetInt32('01280_db.ssd_dict', 'b', tuple('10', toInt32(-20)));
SELECT dictGetString('01280_db.ssd_dict', 'c', tuple('10', toInt32(-20)));
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', tuple(toInt32(3))); --{serverError 53}
2021-02-28 13:30:03 +00:00
DROP DICTIONARY 01280_db.ssd_dict;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
DROP TABLE IF EXISTS 01280_db.keys_table;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
CREATE TABLE 01280_db.keys_table
2020-04-30 20:51:06 +00:00
(
k1 String,
k2 Int32
)
ENGINE = StripeLog();
2021-02-28 13:30:03 +00:00
INSERT INTO 01280_db.keys_table VALUES ('1', 3);
INSERT INTO 01280_db.keys_table SELECT toString(intHash64(number + 1) % 1200), 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 370;
INSERT INTO 01280_db.keys_table VALUES ('2', -1);
INSERT INTO 01280_db.keys_table SELECT toString(intHash64(number + 1) % 1200), 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 370, 370;
INSERT INTO 01280_db.keys_table VALUES ('5', -3);
INSERT INTO 01280_db.keys_table SELECT toString(intHash64(number + 1) % 1200), 11 + intHash64(number) % 1200 FROM system.numbers LIMIT 700, 370;
INSERT INTO 01280_db.keys_table VALUES ('10', -20);
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
DROP DICTIONARY IF EXISTS 01280_db.ssd_dict;
2020-04-30 20:51:06 +00:00
2021-02-28 13:30:03 +00:00
CREATE DICTIONARY 01280_db.ssd_dict
2020-04-30 20:51:06 +00:00
(
k1 String,
k2 Int32,
a UInt64 DEFAULT 0,
b Int32 DEFAULT -1,
c String DEFAULT 'none'
)
PRIMARY KEY k1, k2
2021-02-28 13:30:03 +00:00
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'table_for_dict' PASSWORD '' DB '01280_db'))
2020-04-30 20:51:06 +00:00
LIFETIME(MIN 1000 MAX 2000)
LAYOUT(COMPLEX_KEY_SSD_CACHE(FILE_SIZE 8192 PATH '/var/lib/clickhouse/clickhouse_dicts/1d' BLOCK_SIZE 512 WRITE_BUFFER_SIZE 4096 MAX_STORED_KEYS 1000000));
2020-04-30 20:51:06 +00:00
SELECT 'UPDATE DICTIONARY';
-- 118
2021-02-28 13:30:03 +00:00
SELECT sum(dictGetUInt64('01280_db.ssd_dict', 'a', (k1, k2))) FROM 01280_db.keys_table;
2020-04-30 20:51:06 +00:00
SELECT 'VALUE FROM DISK';
-- -100
2021-02-28 13:30:03 +00:00
SELECT dictGetInt32('01280_db.ssd_dict', 'b', ('1', toInt32(3)));
2020-04-30 20:51:06 +00:00
-- 'clickhouse'
2021-02-28 13:30:03 +00:00
SELECT dictGetString('01280_db.ssd_dict', 'c', ('1', toInt32(3)));
2020-04-30 20:51:06 +00:00
SELECT 'VALUE FROM RAM BUFFER';
-- 8
2021-02-28 13:30:03 +00:00
SELECT dictGetInt32('01280_db.ssd_dict', 'b', ('10', toInt32(-20)));
2020-04-30 20:51:06 +00:00
-- ''
2021-02-28 13:30:03 +00:00
SELECT dictGetString('01280_db.ssd_dict', 'c', ('10', toInt32(-20)));
2020-04-30 20:51:06 +00:00
SELECT 'VALUES FROM DISK AND RAM BUFFER';
-- 118
2021-02-28 13:30:03 +00:00
SELECT sum(dictGetUInt64('01280_db.ssd_dict', 'a', (k1, k2))) FROM 01280_db.keys_table;
2020-04-30 20:51:06 +00:00
SELECT 'HAS';
2020-05-09 11:48:33 +00:00
-- 6
2021-02-28 13:30:03 +00:00
SELECT count() FROM 01280_db.keys_table WHERE dictHas('01280_db.ssd_dict', (k1, k2));
2020-04-30 20:51:06 +00:00
SELECT 'VALUES NOT FROM TABLE';
-- 0 -1 none
2021-02-28 13:30:03 +00:00
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', ('unknown', toInt32(0))), dictGetInt32('01280_db.ssd_dict', 'b', ('unknown', toInt32(0))), dictGetString('01280_db.ssd_dict', 'c', ('unknown', toInt32(0)));
SELECT dictGetUInt64('01280_db.ssd_dict', 'a', ('unknown', toInt32(0))), dictGetInt32('01280_db.ssd_dict', 'b', ('unknown', toInt32(0))), dictGetString('01280_db.ssd_dict', 'c', ('unknown', toInt32(0)));
2020-04-30 20:51:06 +00:00
SELECT 'DUPLICATE KEYS';
2021-02-28 13:30:03 +00:00
SELECT arrayJoin([('1', toInt32(3)), ('2', toInt32(-1)), ('', toInt32(0)), ('', toInt32(0)), ('2', toInt32(-1)), ('1', toInt32(3))]) AS keys, dictGetInt32('01280_db.ssd_dict', 'b', keys);
2020-05-09 11:48:33 +00:00
2020-04-30 20:51:06 +00:00
DROP DICTIONARY IF EXISTS database_for_dict.ssd_dict;
DROP TABLE IF EXISTS database_for_dict.keys_table;