Skip to content

Commit 61da66c

Browse files
committed
Rework tests for query condition cache
1 parent eb4fb3f commit 61da66c

11 files changed

+140
-44
lines changed

tests/queries/0_stateless/03229_query_condition_cache.reference

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Expect a single entry in the cache
2+
1
3+
Expect empty cache after DROP CACHE
4+
0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Tags: no-parallel
2+
-- Tag no-parallel: Messes with internal cache
3+
4+
-- Tests that SYSTEM DROP QUERY CONDITION CACHE works
5+
6+
SET allow_experimental_analyzer = 1;
7+
8+
-- (it's silly to use what will be tested below but we have to assume other tests cluttered the query cache)
9+
SYSTEM DROP QUERY CONDITION CACHE;
10+
11+
DROP TABLE IF EXISTS tab;
12+
CREATE TABLE tab (a Int64, b Int64) ENGINE = MergeTree ORDER BY a;
13+
INSERT INTO tab SELECT number, number FROM numbers(1_000_000); -- 1 mio rows sounds like a lot but the QCC doesn't cache anything if there is less data
14+
15+
SELECT count(*) FROM tab WHERE b = 10_000 SETTINGS use_query_condition_cache = true FORMAT Null;
16+
17+
SELECT 'Expect a single entry in the cache';
18+
SELECT count(*) FROM system.query_condition_cache;
19+
20+
SYSTEM DROP QUERY CONDITION CACHE;
21+
22+
SELECT 'Expect empty cache after DROP CACHE';
23+
SELECT count(*) FROM system.query_condition_cache;
24+
25+
DROP TABLE tab;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- with move to PREWHERE
2+
Query conditions with FINAL keyword must not be cached.
3+
0
4+
--- without move to PREWHERE
5+
Query conditions with FINAL keyword must not be cached.
6+
0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Tags: no-parallel
2+
-- Tag no-parallel: Messes with internal cache
3+
4+
-- Tests that the query condition cache rejects queries with FINAL keyword
5+
6+
SET allow_experimental_analyzer = 1;
7+
8+
DROP TABLE IF EXISTS tab;
9+
10+
CREATE TABLE tab (a Int64, b Int64) ENGINE = ReplacingMergeTree ORDER BY a;
11+
INSERT INTO tab SELECT number, number FROM numbers(1_000_000); -- 1 mio rows sounds like a lot but the QCC doesn't cache anything for less data
12+
13+
SELECT '--- with move to PREWHERE';
14+
SET optimize_move_to_prewhere = true;
15+
16+
SYSTEM DROP QUERY CONDITION CACHE;
17+
18+
SELECT 'Query conditions with FINAL keyword must not be cached.';
19+
SELECT count(*) FROM tab FINAL WHERE b = 10_000 SETTINGS use_query_condition_cache = true FORMAT Null;
20+
SELECT count(*) FROM system.query_condition_cache;
21+
22+
SELECT '--- without move to PREWHERE';
23+
SET optimize_move_to_prewhere = false;
24+
25+
SYSTEM DROP QUERY CONDITION CACHE;
26+
27+
SELECT 'Query conditions with FINAL keyword must not be cached.';
28+
SELECT count(*) FROM tab FINAL WHERE b = 10_000 SETTINGS use_query_condition_cache = true FORMAT Null;
29+
SELECT count(*) FROM system.query_condition_cache;
30+
31+
DROP TABLE tab;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- with move to PREWHERE
2+
Query conditions with non-deterministic functions must not be cached.
3+
0
4+
--- without move to PREWHERE
5+
Query conditions with non-deterministic functions must not be cached.
6+
0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Tags: no-parallel
2+
-- Tag no-parallel: Messes with internal cache
3+
4+
-- Tests that the query condition cache rejects conditions with non-deterministic functions
5+
6+
SET allow_experimental_analyzer = 1;
7+
8+
DROP TABLE IF EXISTS tab;
9+
10+
CREATE TABLE tab (a Int64, b Int64) ENGINE = MergeTree ORDER BY a;
11+
INSERT INTO tab SELECT number, number FROM numbers(1_000_000); -- 1 mio rows sounds like a lot but the QCC doesn't cache anything for less data
12+
13+
SELECT '--- with move to PREWHERE';
14+
SET optimize_move_to_prewhere = true;
15+
16+
SYSTEM DROP QUERY CONDITION CACHE;
17+
18+
SELECT 'Query conditions with non-deterministic functions must not be cached.';
19+
SELECT count(*) FROM tab WHERE b = rand64() SETTINGS use_query_condition_cache = true FORMAT Null;
20+
SELECT count(*) FROM system.query_condition_cache;
21+
22+
SELECT '--- without move to PREWHERE';
23+
SET optimize_move_to_prewhere = false;
24+
25+
SYSTEM DROP QUERY CONDITION CACHE;
26+
27+
SELECT 'Query conditions with non-deterministic functions must not be cached.';
28+
SELECT count(*) FROM tab WHERE b = rand64() SETTINGS use_query_condition_cache = true FORMAT Null;
29+
SELECT count(*) FROM system.query_condition_cache;
30+
31+
DROP TABLE tab;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- with move to PREWHERE
2+
0 1 0
3+
1 1 1
4+
--- without move to PREWHERE
5+
0 1 0
6+
1 0 1

tests/queries/0_stateless/03229_query_condition_cache.sql renamed to tests/queries/0_stateless/03229_query_condition_cache_profile_events.sql

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
-- Tags: no-parallel, no-parallel-replicas
1+
-- Tags: no-parallel
2+
-- Tag no-parallel: Messes with internal cache
23

34
SET allow_experimental_analyzer = 1;
45

5-
SELECT 'With PREWHERE';
6+
-- Tests that queries with enabled query condition cache correctly populate profile events
7+
8+
SELECT '--- with move to PREWHERE';
69

710
SYSTEM DROP QUERY CONDITION CACHE;
811

912
DROP TABLE IF EXISTS tab;
1013

1114
CREATE TABLE tab (a Int64, b Int64) ENGINE = MergeTree ORDER BY a;
12-
INSERT INTO tab SELECT number, number FROM numbers(1000000);
15+
INSERT INTO tab SELECT number, number FROM numbers(1_000_000); -- 1 mio rows sounds like a lot but the QCC doesn't cache anything for less data
1316

14-
SELECT count(*) FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true;
17+
SELECT count(*) FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true;
1518

1619
SYSTEM FLUSH LOGS query_log;
1720
SELECT
@@ -22,11 +25,11 @@ FROM system.query_log
2225
WHERE
2326
type = 'QueryFinish'
2427
AND current_database = currentDatabase()
25-
AND query = 'SELECT count(*) FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true;'
28+
AND query = 'SELECT count(*) FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true;'
2629
ORDER BY
2730
event_time_microseconds;
2831

29-
SELECT * FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true;
32+
SELECT * FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true;
3033

3134
SYSTEM FLUSH LOGS query_log;
3235
SELECT
@@ -37,15 +40,15 @@ FROM system.query_log
3740
WHERE
3841
type = 'QueryFinish'
3942
AND current_database = currentDatabase()
40-
AND query = 'SELECT * FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true;'
43+
AND query = 'SELECT * FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true;'
4144
ORDER BY
4245
event_time_microseconds;
4346

44-
SELECT 'Without PREWHERE';
47+
SELECT '--- without move to PREWHERE';
4548

4649
SYSTEM DROP QUERY CONDITION CACHE;
4750

48-
SELECT count(*) FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;
51+
SELECT count(*) FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;
4952

5053
SYSTEM FLUSH LOGS query_log;
5154
SELECT
@@ -56,11 +59,11 @@ FROM system.query_log
5659
WHERE
5760
type = 'QueryFinish'
5861
AND current_database = currentDatabase()
59-
AND query = 'SELECT count(*) FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;'
62+
AND query = 'SELECT count(*) FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;'
6063
ORDER BY
6164
event_time_microseconds;
6265

63-
SELECT * FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;
66+
SELECT * FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;
6467

6568
SYSTEM FLUSH LOGS query_log;
6669
SELECT
@@ -71,7 +74,7 @@ FROM system.query_log
7174
WHERE
7275
type = 'QueryFinish'
7376
AND current_database = currentDatabase()
74-
AND query = 'SELECT * FROM tab WHERE b = 10000 SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;'
77+
AND query = 'SELECT * FROM tab WHERE b = 10_000 FORMAT Null SETTINGS use_query_condition_cache = true, optimize_move_to_prewhere = false;'
7578
ORDER BY
7679
event_time_microseconds;
7780

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
--- with move to PREWHERE
2-
Expect the cache to be initially empty.
3-
0
4-
Expect that the cache contains one entry after the first query.
2+
Expect one entry in the cache after the first query.
53
1
64
If the same query runs again, the cache still contains just a single entry.
75
1
86
--- without move to PREWHERE
9-
Expect the cache to be initially empty.
10-
0
11-
Expect that the cache contains one entry after the first query.
7+
Expect one entry in the cache after the first query.
128
1
139
If the same query runs again, the cache still contains just a single entry.
1410
1

0 commit comments

Comments
 (0)