This commit is contained in:
Raúl Marín 2022-01-24 13:31:24 +01:00
parent e77fc9e9be
commit beb99a344f
6 changed files with 88 additions and 151 deletions

View File

@ -0,0 +1,21 @@
4 4 4 4 5
9 9 9 9 5
14 14 14 14 5
19 19 19 19 5
24 24 24 24 5
29 29 29 29 5
34 34 34 34 5
39 39 39 39 5
44 44 44 44 5
49 49 49 49 5
54 54 54 54 5
59 59 59 59 5
64 64 64 64 5
69 69 69 69 5
74 74 74 74 5
79 79 79 79 5
84 84 84 84 5
89 89 89 89 5
94 94 94 94 5
99 99 99 99 5
02177_MV 7 80 22

View File

@ -0,0 +1,67 @@
-- TEST CACHE
CREATE TABLE t1 (i Int64, j Int64) ENGINE = Memory;
INSERT INTO t1 SELECT number, number FROM system.numbers LIMIT 100;
CREATE TABLE t2 (k Int64, l Int64, m Int64, n Int64) ENGINE = Memory;
CREATE MATERIALIZED VIEW mv1 TO t2 AS
WITH
(SELECT max(i) FROM t1) AS t1
SELECT
t1 as k, -- Using local cache x 4
t1 as l,
t1 as m,
t1 as n
FROM t1
LIMIT 5;
-- FIRST INSERT
INSERT INTO t1
WITH
(SELECT max(i) FROM t1) AS t1
SELECT
number as i,
t1 + t1 + t1 AS j -- Using global cache
FROM system.numbers
LIMIT 100
SETTINGS
min_insert_block_size_rows=5,
max_insert_block_size=5,
min_insert_block_size_rows_for_materialized_views=5,
max_block_size=5,
max_threads=1;
SELECT k, l, m, n, count()
FROM t2
GROUP BY k, l, m, n
ORDER BY k, l, m, n;
SYSTEM FLUSH LOGS;
-- The main query should have a cache miss and 3 global hits
-- The MV is executed 20 times (100 / 5) and each run does 1 miss and 4 hits to the LOCAL cache
-- In addition to this, to prepare the MV, there is an extra preparation to get the list of columns via
-- InterpreterSelectQuery, which adds 1 miss and 4 global hits (since it uses the global cache)
-- So in total we have:
-- Main query: 1 miss, 3 global
-- Preparation: 1 miss, 4 global
-- Blocks (20): 20 miss, 0 global, 80 local hits
-- TOTAL: 22 miss, 7 global, 80 local
SELECT
'02177_MV',
ProfileEvents['ScalarSubqueriesGlobalCacheHit'] as scalar_cache_global_hit,
ProfileEvents['ScalarSubqueriesLocalCacheHit'] as scalar_cache_local_hit,
ProfileEvents['ScalarSubqueriesCacheMiss'] as scalar_cache_miss
FROM system.query_log
WHERE
current_database = currentDatabase()
AND type = 'QueryFinish'
AND query LIKE '-- FIRST INSERT\nINSERT INTO t1\n%'
AND event_date >= yesterday() AND event_time > now() - interval 10 minute;
-- MV SOURCE SHOULD USE LOCAL CACHE
-- MV SOURCE DEEP IN THE CALL SHOULD USE LOCAL CACHE
-- CHECK PERF TEST (EXISTING FOR SCALAR AND MAYBE ADD ONE WITH MVS)

View File

@ -1,101 +0,0 @@
0 4 4 1
1 4 4 1
2 4 4 1
3 4 4 1
4 4 4 1
5 9 9 1
6 9 9 1
7 9 9 1
8 9 9 1
9 9 9 1
10 14 14 1
11 14 14 1
12 14 14 1
13 14 14 1
14 14 14 1
15 19 19 1
16 19 19 1
17 19 19 1
18 19 19 1
19 19 19 1
20 24 24 1
21 24 24 1
22 24 24 1
23 24 24 1
24 24 24 1
25 29 29 1
26 29 29 1
27 29 29 1
28 29 29 1
29 29 29 1
30 34 34 1
31 34 34 1
32 34 34 1
33 34 34 1
34 34 34 1
35 39 39 1
36 39 39 1
37 39 39 1
38 39 39 1
39 39 39 1
40 44 44 1
41 44 44 1
42 44 44 1
43 44 44 1
44 44 44 1
45 49 49 1
46 49 49 1
47 49 49 1
48 49 49 1
49 49 49 1
50 54 54 1
51 54 54 1
52 54 54 1
53 54 54 1
54 54 54 1
55 59 59 1
56 59 59 1
57 59 59 1
58 59 59 1
59 59 59 1
60 64 64 1
61 64 64 1
62 64 64 1
63 64 64 1
64 64 64 1
65 69 69 1
66 69 69 1
67 69 69 1
68 69 69 1
69 69 69 1
70 74 74 1
71 74 74 1
72 74 74 1
73 74 74 1
74 74 74 1
75 79 79 1
76 79 79 1
77 79 79 1
78 79 79 1
79 79 79 1
80 84 84 1
81 84 84 1
82 84 84 1
83 84 84 1
84 84 84 1
85 89 89 1
86 89 89 1
87 89 89 1
88 89 89 1
89 89 89 1
90 94 94 1
91 94 94 1
92 94 94 1
93 94 94 1
94 94 94 1
95 99 99 1
96 99 99 1
97 99 99 1
98 99 99 1
99 99 99 1
02177_MV 3 60 21

View File

@ -1,50 +0,0 @@
-- TEST CACHE
CREATE TABLE t1 (i Int64, j Int64) ENGINE = Memory;
INSERT INTO t1 SELECT number, number FROM system.numbers LIMIT 100;
CREATE TABLE t2 (i Int64, j Int64, k Int64, l Int64) ENGINE = Memory;
CREATE MATERIALIZED VIEW mv1 TO t2 AS
WITH
(SELECT max(i) FROM t1) AS t1
SELECT
t1 as i,
t1 as j,
t1 as k,
t1 as l
FROM t1
LIMIT 5;
INSERT INTO t1
WITH
(SELECT max(i) FROM t1) AS t1
SELECT
number as i,
t1 + t1 + t1 AS j -- Using global cache
FROM system.numbers
LIMIT 100
SETTINGS
min_insert_block_size_rows=5,
max_insert_block_size=5,
min_insert_block_size_rows_for_materialized_views=5,
max_block_size=5;
-- INSERT INTO t1 SELECT number as i, (SELECT max(i) FROM t1) AS j FROM system.numbers LIMIT 10 OFFSET 100 SETTINGS min_insert_block_size_rows=5, max_insert_block_size=5, max_block_size=5;
-- SELECT max(i) FROM t1;
SELECT i, j, k, l, count() FROM t2 GROUP BY i, j, k, l ORDER BY i, j, k, l;
SYSTEM FLUSH LOGS;
SELECT
'02177_MV',
ProfileEvents['ScalarSubqueriesGlobalCacheHit'] as scalar_cache_global_hit,
ProfileEvents['ScalarSubqueriesLocalCacheHit'] as scalar_cache_local_hit,
ProfileEvents['ScalarSubqueriesCacheMiss'] as scalar_cache_miss
FROM system.query_log
WHERE
current_database = currentDatabase()
AND type = 'QueryFinish'
AND query LIKE 'INSERT INTO t1\n%'
AND event_date >= yesterday() AND event_time > now() - interval 10 minute;
-- MV SOURCE SHOULD USE LOCAL CACHE
-- MV SOURCE DEEP IN THE CALL SHOULD USE LOCAL CACHE
-- CHECK PERF TEST (EXISTING FOR SCALAR AND MAYBE ADD ONE WITH MVS)