ClickHouse/tests/queries/0_stateless/03143_prewhere_profile_events.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2.6 KiB
Bash
Raw Normal View History

2024-05-20 15:14:43 +00:00
#!/usr/bin/env bash
2024-06-07 22:12:41 +00:00
# Tags: no-random-settings, no-random-merge-tree-settings
2024-05-20 15:14:43 +00:00
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} -q "
2024-05-20 15:14:43 +00:00
DROP TABLE IF EXISTS t;
2024-06-07 22:12:41 +00:00
CREATE TABLE t(a UInt32, b UInt32, c UInt32, d UInt32) ENGINE=MergeTree ORDER BY a SETTINGS min_bytes_for_wide_part=0, min_rows_for_wide_part=0;
2024-05-20 15:14:43 +00:00
INSERT INTO t SELECT number, number, number, number FROM numbers_mt(1e7);
OPTIMIZE TABLE t FINAL;
"
query_id_1=$RANDOM$RANDOM
query_id_2=$RANDOM$RANDOM
query_id_3=$RANDOM$RANDOM
2024-05-21 13:37:41 +00:00
query_id_4=$RANDOM$RANDOM
2024-05-20 15:14:43 +00:00
client_opts=(
--max_block_size 65409
2024-05-21 13:37:41 +00:00
--max_threads 8
2024-05-20 15:14:43 +00:00
)
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} "${client_opts[@]}" --query_id "$query_id_1" -q "
2024-05-20 15:14:43 +00:00
SELECT *
FROM t
PREWHERE (b % 8192) = 42
WHERE c = 42
FORMAT Null
"
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} "${client_opts[@]}" --query_id "$query_id_2" -q "
2024-05-20 15:14:43 +00:00
SELECT *
FROM t
PREWHERE (b % 8192) = 42 AND (c % 8192) = 42
WHERE d = 42
FORMAT Null
settings enable_multiple_prewhere_read_steps=1;
"
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} "${client_opts[@]}" --query_id "$query_id_3" -q "
2024-05-20 15:14:43 +00:00
SELECT *
FROM t
PREWHERE (b % 8192) = 42 AND (c % 16384) = 42
WHERE d = 42
FORMAT Null
settings enable_multiple_prewhere_read_steps=0;
"
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} "${client_opts[@]}" --query_id "$query_id_4" -q "
2024-05-21 13:37:41 +00:00
SELECT b, c
FROM t
PREWHERE (b % 8192) = 42 AND (c % 8192) = 42
FORMAT Null
settings enable_multiple_prewhere_read_steps=1;
"
2024-08-07 10:55:16 +00:00
${CLICKHOUSE_CLIENT} -q "
2024-05-20 15:14:43 +00:00
SYSTEM FLUSH LOGS;
-- 52503 which is 43 * number of granules, 10000000
SELECT ProfileEvents['RowsReadByMainReader'], ProfileEvents['RowsReadByPrewhereReaders']
FROM system.query_log
WHERE current_database=currentDatabase() AND query_id = '$query_id_1' and type = 'QueryFinish';
-- 52503, 10052503 which is the sum of 10000000 from the first prewhere step plus 52503 from the second
SELECT ProfileEvents['RowsReadByMainReader'], ProfileEvents['RowsReadByPrewhereReaders']
FROM system.query_log
WHERE current_database=currentDatabase() AND query_id = '$query_id_2' and type = 'QueryFinish';
-- 26273 the same as query #1 but twice less data (43 * ceil((52503 / 43) / 2)), 10000000
SELECT ProfileEvents['RowsReadByMainReader'], ProfileEvents['RowsReadByPrewhereReaders']
FROM system.query_log
WHERE current_database=currentDatabase() AND query_id = '$query_id_3' and type = 'QueryFinish';
2024-05-21 13:37:41 +00:00
-- 0, 10052503
SELECT ProfileEvents['RowsReadByMainReader'], ProfileEvents['RowsReadByPrewhereReaders']
FROM system.query_log
WHERE current_database=currentDatabase() AND query_id = '$query_id_4' and type = 'QueryFinish';
2024-05-20 15:14:43 +00:00
"