2019-05-09 12:26:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
2020-12-28 11:46:53 +00:00
|
|
|
# shellcheck source=../shell_config.sh
|
2020-08-01 00:51:12 +00:00
|
|
|
. "$CURDIR"/../shell_config.sh
|
2019-05-09 12:26:25 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS minmax_idx;"
|
2019-05-09 12:26:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT -n --query="
|
2020-05-29 10:08:11 +00:00
|
|
|
CREATE TABLE minmax_idx
|
2019-05-09 12:26:25 +00:00
|
|
|
(
|
|
|
|
u64 UInt64,
|
|
|
|
i64 Int64,
|
2019-05-09 12:30:32 +00:00
|
|
|
i32 Int32
|
2019-05-09 12:26:25 +00:00
|
|
|
) ENGINE = MergeTree()
|
2019-05-09 12:53:08 +00:00
|
|
|
PARTITION BY i32
|
2019-05-09 12:26:25 +00:00
|
|
|
ORDER BY u64
|
2023-02-20 22:43:11 +00:00
|
|
|
SETTINGS index_granularity = 2, index_granularity_bytes = '10Mi';"
|
2019-05-09 12:26:25 +00:00
|
|
|
|
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="INSERT INTO minmax_idx VALUES
|
2019-05-09 12:26:25 +00:00
|
|
|
(0, 2, 1),
|
2019-05-09 12:53:08 +00:00
|
|
|
(1, 1, 1),
|
|
|
|
(2, 1, 1),
|
|
|
|
(3, 1, 1),
|
|
|
|
(4, 2, 2),
|
|
|
|
(5, 2, 2),
|
|
|
|
(6, 2, 2),
|
|
|
|
(7, 2, 2),
|
|
|
|
(8, 1, 2),
|
|
|
|
(9, 1, 2)"
|
2019-05-09 12:26:25 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2;"
|
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read"
|
2019-05-09 12:26:25 +00:00
|
|
|
|
2019-05-09 12:30:32 +00:00
|
|
|
$CLICKHOUSE_CLIENT -n --query="
|
2020-07-16 11:44:14 +00:00
|
|
|
ALTER TABLE minmax_idx ADD INDEX idx (i64, u64 * i64) TYPE minmax GRANULARITY 1 SETTINGS mutations_sync = 2;"
|
2019-05-09 12:30:32 +00:00
|
|
|
|
2020-07-16 11:44:14 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="ALTER TABLE minmax_idx MATERIALIZE INDEX idx IN PARTITION 1 SETTINGS mutations_sync = 2;"
|
2019-05-09 12:53:08 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2;"
|
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read"
|
2019-05-09 12:53:08 +00:00
|
|
|
|
2020-07-16 11:44:14 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="ALTER TABLE minmax_idx MATERIALIZE INDEX idx IN PARTITION 2 SETTINGS mutations_sync = 2"
|
2019-05-09 12:53:08 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2;"
|
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read"
|
2019-05-09 12:53:08 +00:00
|
|
|
|
2020-07-16 11:44:14 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="ALTER TABLE minmax_idx CLEAR INDEX idx IN PARTITION 1 SETTINGS mutations_sync = 2"
|
|
|
|
$CLICKHOUSE_CLIENT --query="ALTER TABLE minmax_idx CLEAR INDEX idx IN PARTITION 2 SETTINGS mutations_sync = 2"
|
2019-08-04 14:32:33 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2;"
|
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read"
|
2019-08-04 14:32:33 +00:00
|
|
|
|
2020-07-16 11:44:14 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="ALTER TABLE minmax_idx MATERIALIZE INDEX idx SETTINGS mutations_sync = 2"
|
2019-05-09 12:26:25 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2;"
|
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT count() FROM minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read"
|
2019-05-09 12:26:25 +00:00
|
|
|
|
2020-05-29 10:08:11 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="DROP TABLE minmax_idx"
|