2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS pk;
|
2017-08-01 19:01:38 +00:00
|
|
|
|
2022-06-23 10:58:34 +00:00
|
|
|
set allow_deprecated_syntax_for_merge_tree=1;
|
2022-08-10 18:25:51 +00:00
|
|
|
-- NOTE: here the timezone is pinned to UTC, to avoid issues with "partial
|
|
|
|
-- timezones" (timezones that does not starts from 00:00), like
|
|
|
|
-- Africa/Monrovia, for which toStartOfMinute(0) and toStartOfMinute(59) can
|
|
|
|
-- give different values:
|
|
|
|
--
|
|
|
|
-- SELECT
|
|
|
|
-- toDateTime(0, 'Africa/Monrovia') AS sec0,
|
|
|
|
-- toDateTime(59, 'Africa/Monrovia') AS sec59
|
|
|
|
--
|
|
|
|
-- ┌────────────────sec0─┬───────────────sec59─┐
|
|
|
|
-- │ 1969-12-31 23:15:30 │ 1969-12-31 23:16:29 │
|
|
|
|
-- └─────────────────────┴─────────────────────┘
|
|
|
|
--
|
|
|
|
CREATE TABLE pk (d Date DEFAULT '2000-01-01', x DateTime, y UInt64, z UInt64) ENGINE = MergeTree(d, (toStartOfMinute(x, 'UTC'), y, z), 1);
|
2017-08-01 19:01:38 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO pk (x, y, z) VALUES (1, 11, 1235), (2, 11, 4395), (3, 22, 3545), (4, 22, 6984), (5, 33, 4596), (61, 11, 4563), (62, 11, 4578), (63, 11, 3572), (64, 22, 5786), (65, 22, 5786), (66, 22, 2791), (67, 22, 2791), (121, 33, 2791), (122, 33, 2791), (123, 33, 1235), (124, 44, 4935), (125, 44, 4578), (126, 55, 5786), (127, 55, 2791), (128, 55, 1235);
|
2017-08-01 19:01:38 +00:00
|
|
|
|
|
|
|
SET min_insert_block_size_rows = 0, min_insert_block_size_bytes = 0;
|
|
|
|
SET max_block_size = 1;
|
|
|
|
|
|
|
|
-- Test inferred limit
|
|
|
|
SET max_rows_to_read = 5;
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT toUInt32(x), y, z FROM pk WHERE x BETWEEN toDateTime(0) AND toDateTime(59);
|
2017-08-01 19:01:38 +00:00
|
|
|
|
|
|
|
SET max_rows_to_read = 9;
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT toUInt32(x), y, z FROM pk WHERE x BETWEEN toDateTime(120) AND toDateTime(240);
|
2017-08-01 19:01:38 +00:00
|
|
|
|
|
|
|
-- Index is coarse, cannot read single row
|
|
|
|
SET max_rows_to_read = 5;
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT toUInt32(x), y, z FROM pk WHERE x = toDateTime(1);
|
2017-08-01 19:01:38 +00:00
|
|
|
|
|
|
|
-- Index works on interval 00:01:00 - 00:01:59
|
|
|
|
SET max_rows_to_read = 4;
|
2020-12-04 02:15:44 +00:00
|
|
|
SELECT toUInt32(x), y, z FROM pk WHERE (x BETWEEN toDateTime(60) AND toDateTime(119)) AND y = 11;
|
2017-08-01 19:01:38 +00:00
|
|
|
|
|
|
|
-- Cannot read less rows as PK is coarser on interval 00:01:00 - 00:02:00
|
|
|
|
SET max_rows_to_read = 5;
|
2020-12-04 02:15:44 +00:00
|
|
|
SELECT toUInt32(x), y, z FROM pk WHERE (x BETWEEN toDateTime(60) AND toDateTime(120)) AND y = 11;
|
2017-08-01 19:01:38 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE pk;
|