2016-12-21 20:04:27 +00:00
#!/usr/bin/env bash
2024-04-17 14:48:48 +00:00
# Tags: long, no-debug, no-asan, no-tsan, no-msan
2015-05-12 04:55:14 +00:00
2017-12-15 19:34:19 +00:00
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
2017-12-15 19:34:19 +00:00
2015-05-12 04:55:14 +00:00
function create {
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS summing_00155"
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS collapsing_00155"
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS aggregating_00155"
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS replacing_00155"
2022-06-23 08:37:52 +00:00
$CLICKHOUSE_CLIENT --allow_deprecated_syntax_for_merge_tree= 1 --query= "CREATE TABLE summing_00155 (d Date DEFAULT today(), x UInt64, s UInt64 DEFAULT 1) ENGINE = SummingMergeTree(d, x, 8192)"
2022-06-28 12:39:22 +00:00
$CLICKHOUSE_CLIENT --allow_deprecated_syntax_for_merge_tree= 1 --query= "CREATE TABLE collapsing_00155 (d Date DEFAULT today(), x UInt64, s Int8 DEFAULT 1) ENGINE = CollapsingMergeTree(d, x, 8192, s)"
2022-06-23 08:37:52 +00:00
$CLICKHOUSE_CLIENT --allow_deprecated_syntax_for_merge_tree= 1 --query= "CREATE TABLE aggregating_00155 (d Date DEFAULT today(), x UInt64, s AggregateFunction(sum, UInt64)) ENGINE = AggregatingMergeTree(d, x, 8192)"
2022-06-28 12:39:22 +00:00
$CLICKHOUSE_CLIENT --allow_deprecated_syntax_for_merge_tree= 1 --query= "CREATE TABLE replacing_00155 (d Date DEFAULT today(), x UInt64, s Int8 DEFAULT 1, v UInt64) ENGINE = ReplacingMergeTree(d, (x), 8192, v)"
2015-05-12 04:55:14 +00:00
}
function cleanup {
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE summing_00155"
$CLICKHOUSE_CLIENT --query= "DROP TABLE collapsing_00155"
$CLICKHOUSE_CLIENT --query= "DROP TABLE aggregating_00155"
$CLICKHOUSE_CLIENT --query= "DROP TABLE replacing_00155"
2015-05-12 04:55:14 +00:00
}
function test {
2017-04-05 11:52:23 +00:00
create
2016-08-13 05:06:36 +00:00
2017-04-05 11:52:23 +00:00
SUM = $(( $1 + $2 ))
MAX = $(( $1 > $2 ? $1 : $2 ))
2015-05-12 04:55:14 +00:00
2022-04-06 17:44:37 +00:00
SETTINGS = "--min_insert_block_size_rows=0 --min_insert_block_size_bytes=0 --max_block_size=65505"
2016-08-13 05:06:36 +00:00
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM STOP MERGES summing_00155"
2020-08-01 23:43:31 +00:00
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO summing_00155 (x) SELECT number AS x FROM system.numbers LIMIT $1 "
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO summing_00155 (x) SELECT number AS x FROM system.numbers LIMIT $2 "
2015-05-12 04:55:14 +00:00
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM STOP MERGES collapsing_00155"
2020-08-01 23:43:31 +00:00
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO collapsing_00155 (x) SELECT number AS x FROM system.numbers LIMIT $1 "
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO collapsing_00155 (x) SELECT number AS x FROM system.numbers LIMIT $2 "
2015-05-12 04:55:14 +00:00
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM STOP MERGES aggregating_00155"
2020-08-01 23:43:31 +00:00
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO aggregating_00155 (d, x, s) SELECT today() AS d, number AS x, sumState(materialize(toUInt64(1))) AS s FROM (SELECT number FROM system.numbers LIMIT $1 ) GROUP BY number "
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO aggregating_00155 (d, x, s) SELECT today() AS d, number AS x, sumState(materialize(toUInt64(1))) AS s FROM (SELECT number FROM system.numbers LIMIT $2 ) GROUP BY number "
2015-05-12 04:55:14 +00:00
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM STOP MERGES replacing_00155"
2020-08-01 23:43:31 +00:00
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO replacing_00155 (x, v) SELECT number AS x, toUInt64(number % 3 == 0) FROM system.numbers LIMIT $1 "
$CLICKHOUSE_CLIENT $SETTINGS --query= " INSERT INTO replacing_00155 (x, v) SELECT number AS x, toUInt64(number % 3 == 1) FROM system.numbers LIMIT $2 "
2017-07-17 19:45:16 +00:00
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $SUM , sum(s) = $SUM FROM summing_00155 "
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM START MERGES summing_00155"
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= "OPTIMIZE TABLE summing_00155"
$CLICKHOUSE_CLIENT --query= " SELECT count() = $MAX , sum(s) = $SUM FROM summing_00155 "
2017-04-05 11:52:23 +00:00
echo
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $SUM , sum(s) = $SUM FROM collapsing_00155 "
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM START MERGES collapsing_00155"
$CLICKHOUSE_CLIENT --query= "OPTIMIZE TABLE collapsing_00155 FINAL" --server_logs_file= '/dev/null' ;
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $MAX , sum(s) = $MAX FROM collapsing_00155 "
2017-04-05 11:52:23 +00:00
echo
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $SUM , sumMerge(s) = $SUM FROM aggregating_00155 "
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM START MERGES aggregating_00155"
$CLICKHOUSE_CLIENT --query= "OPTIMIZE TABLE aggregating_00155 FINAL"
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $MAX , sumMerge(s) = $SUM FROM aggregating_00155 "
2017-04-05 11:52:23 +00:00
echo
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $SUM , sum(s) = $SUM FROM replacing_00155 "
2023-12-08 15:26:17 +00:00
$CLICKHOUSE_CLIENT --query= "SYSTEM START MERGES replacing_00155"
$CLICKHOUSE_CLIENT --query= "OPTIMIZE TABLE replacing_00155 FINAL"
2019-06-03 17:36:27 +00:00
$CLICKHOUSE_CLIENT --query= " SELECT count() = $MAX , sum(s) = $MAX FROM replacing_00155 "
$CLICKHOUSE_CLIENT --query= " SELECT count() = sum(v) FROM replacing_00155 where x % 3 == 0 and x < $1 "
$CLICKHOUSE_CLIENT --query= " SELECT count() = sum(v) FROM replacing_00155 where x % 3 == 1 and x < $2 "
$CLICKHOUSE_CLIENT --query= "SELECT sum(v) = 0 FROM replacing_00155 where x % 3 == 2"
2017-07-17 19:45:16 +00:00
echo
2017-04-05 11:52:23 +00:00
echo
2015-05-12 04:55:14 +00:00
}
2020-08-01 01:20:22 +00:00
merged_rows_0 = $( $CLICKHOUSE_CLIENT -q "select value from system.events where event = 'MergedRows'" )
2017-09-14 13:56:54 +00:00
2015-05-12 04:55:14 +00:00
test 8191 8191
test 8191 8192
test 8192 8191
test 8192 8192
test 8192 8193
test 8193 8192
test 8193 8193
test 8191 8193
test 8193 8191
test 8193 8194
test 8194 8193
test 8194 8194
2020-08-01 01:20:22 +00:00
merged_rows_1 = $( $CLICKHOUSE_CLIENT -q "select value from system.events where event = 'MergedRows'" )
2017-09-14 13:56:54 +00:00
[ [ $merged_rows_1 -le $merged_rows_0 ] ]
2015-05-12 04:55:14 +00:00
cleanup