2020-08-15 05:21:02 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-09-12 12:35:27 +00:00
|
|
|
# Tags: long
|
2020-08-15 05:21:02 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-06-25 02:11:27 +00:00
|
|
|
CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL=none
|
|
|
|
|
2020-08-15 05:21:02 +00:00
|
|
|
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
2020-12-28 11:46:53 +00:00
|
|
|
# shellcheck source=../shell_config.sh
|
2020-08-15 05:21:02 +00:00
|
|
|
. "$CUR_DIR"/../shell_config.sh
|
|
|
|
|
|
|
|
${CLICKHOUSE_CLIENT} --query="DROP TABLE IF EXISTS t"
|
2023-06-25 02:11:27 +00:00
|
|
|
${CLICKHOUSE_CLIENT} --query="CREATE TABLE t (x Int8) ENGINE = MergeTree ORDER BY ()"
|
|
|
|
|
|
|
|
|
2023-06-29 11:32:17 +00:00
|
|
|
function thread_optimize()
|
2023-06-25 02:11:27 +00:00
|
|
|
{
|
2023-06-29 11:32:17 +00:00
|
|
|
while true;
|
2023-06-25 02:11:27 +00:00
|
|
|
do
|
|
|
|
${CLICKHOUSE_CLIENT} --query="OPTIMIZE TABLE t FINAL;" 2>&1 | tr -d '\n' | rg -v 'Cancelled merging parts' ||:
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-06-29 11:32:17 +00:00
|
|
|
TIMEOUT=15
|
|
|
|
export -f thread_optimize
|
|
|
|
timeout $TIMEOUT bash -c thread_optimize 2> /dev/null &
|
2020-08-15 05:21:02 +00:00
|
|
|
|
2023-06-29 11:32:17 +00:00
|
|
|
for i in {1..100};
|
|
|
|
do
|
2023-06-25 02:11:27 +00:00
|
|
|
echo "
|
|
|
|
INSERT INTO t VALUES (0);
|
|
|
|
INSERT INTO t VALUES (0);
|
|
|
|
TRUNCATE TABLE t;
|
|
|
|
SELECT count() FROM t HAVING count() > 0;
|
|
|
|
SELECT ${i};
|
|
|
|
"
|
|
|
|
done | ${CLICKHOUSE_CLIENT} --multiquery
|
2020-08-15 05:21:02 +00:00
|
|
|
|
|
|
|
wait
|
2020-12-04 02:15:44 +00:00
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT -q "DROP TABLE t"
|