2020-06-29 23:28:25 +00:00
#!/usr/bin/env bash
2022-02-08 19:21:16 +00:00
# Tags: no-tsan, no-asan, no-ubsan, no-msan, no-debug, no-parallel, no-fasttest, no-s3-storage
2020-06-29 23:28:25 +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
2020-06-29 23:28:25 +00:00
2023-06-22 21:58:55 +00:00
# Check that attaching a database with a large number of tables is not too slow.
2020-06-29 23:28:25 +00:00
# it is the worst way of making performance test, nevertheless it can detect significant slowdown and some other issues, that usually found by stress test
db = " test_01193_ $RANDOM "
tables = 1000
threads = 10
count_multiplier = 1
2023-07-03 09:58:41 +00:00
max_time_ms = 1500
2023-05-03 14:26:12 +00:00
2020-08-01 01:20:22 +00:00
debug_or_sanitizer_build = $( $CLICKHOUSE_CLIENT -q "WITH ((SELECT value FROM system.build_options WHERE name='BUILD_TYPE') AS build, (SELECT value FROM system.build_options WHERE name='CXX_FLAGS') as flags) SELECT build='Debug' OR flags LIKE '%fsanitize%' OR hasThreadFuzzer()" )
2020-06-29 23:28:25 +00:00
if [ [ debug_or_sanitizer_build -eq 1 ] ] ; then tables = 100; count_multiplier = 10; max_time_ms = 1500; fi
create_tables( ) {
2020-09-17 15:54:41 +00:00
$CLICKHOUSE_CLIENT -q " WITH
'CREATE TABLE $db.table_$1_' AS create1,
' (i UInt64, d Date, s String, n Nested(i UInt8, f Float32)) ENGINE=' AS create2,
[ 'Memory' , 'File(CSV)' , 'Log' , 'StripeLog' , 'MergeTree ORDER BY i' ] AS engines,
'INSERT INTO $db.table_$1_' AS insert1,
' VALUES (0, ' '2020-06-25' ', ' 'hello' ', [1, 2], [3, 4]), (1, ' '2020-06-26' ', ' 'word' ', [10, 20], [30, 40])' AS insert2
SELECT arrayStringConcat(
groupArray(
create1 || toString( number) || create2 || engines[ 1 + number % length( engines) ] || ';\n' ||
insert1 || toString( number) || insert2
) , ';\n' ) FROM numbers( $tables ) FORMAT TSVRaw; " | $CLICKHOUSE_CLIENT -nm
2020-06-29 23:28:25 +00:00
}
$CLICKHOUSE_CLIENT -q " CREATE DATABASE $db "
for i in $( seq 1 $threads ) ; do
2020-08-01 00:56:32 +00:00
create_tables " $i " &
2020-06-29 23:28:25 +00:00
done
wait
$CLICKHOUSE_CLIENT -q " CREATE TABLE $db .table_merge (i UInt64, d Date, s String, n Nested(i UInt8, f Float32)) ENGINE=Merge(' $db ', '^table_') "
2020-09-17 15:54:41 +00:00
$CLICKHOUSE_CLIENT -q " SELECT count() * $count_multiplier , i, d, s, n.i, n.f FROM merge(' $db ', '^table_9') GROUP BY i, d, s, n.i, n.f ORDER BY i "
2020-06-29 23:28:25 +00:00
2023-07-03 09:58:41 +00:00
for i in { 1..50} ; do
2020-09-17 15:54:41 +00:00
$CLICKHOUSE_CLIENT -q " DETACH DATABASE $db "
2023-07-03 09:58:41 +00:00
$CLICKHOUSE_CLIENT --query_profiler_real_time_period_ns= 100000000 --query_profiler_cpu_time_period_ns= 100000000 -q " ATTACH DATABASE $db " --query_id= " $db - $i " ;
2020-09-17 15:54:41 +00:00
done
2020-06-29 23:28:25 +00:00
2020-09-17 15:54:41 +00:00
$CLICKHOUSE_CLIENT -q "SYSTEM FLUSH LOGS"
2023-07-03 09:58:41 +00:00
durations = $( $CLICKHOUSE_CLIENT -q " SELECT groupArray(query_duration_ms) FROM system.query_log WHERE current_database = currentDatabase() AND query_id LIKE ' $db -%' AND type=2 " )
$CLICKHOUSE_CLIENT -q " SELECT 'durations', ' $db ', $durations FORMAT Null "
$CLICKHOUSE_CLIENT -q " SELECT if(quantile(0.5)(arrayJoin( $durations )) < $max_time_ms , 'ok', toString( $durations )) "
2020-06-29 23:28:25 +00:00
2020-07-10 14:00:44 +00:00
$CLICKHOUSE_CLIENT -q " SELECT count() * $count_multiplier , i, d, s, n.i, n.f FROM $db .table_merge GROUP BY i, d, s, n.i, n.f ORDER BY i "
2020-06-29 23:28:25 +00:00
2021-01-10 19:07:23 +00:00
$CLICKHOUSE_CLIENT -q " DROP DATABASE IF EXISTS $db "