-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathcolumnar_cache.sql
116 lines (91 loc) · 1.93 KB
/
columnar_cache.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
CREATE TABLE big_table (
id INT,
firstname TEXT,
lastname TEXT
) USING columnar;
INSERT INTO big_table (id, firstname, lastname)
SELECT i,
CONCAT('firstname-', i),
CONCAT('lastname-', i)
FROM generate_series(1, 1000000) as i;
-- get some baselines from multiple chunks
SELECT firstname,
lastname,
SUM(id)
FROM big_table
WHERE id < 1000
GROUP BY firstname,
lastname
UNION
SELECT firstname,
lastname,
SUM(id)
FROM big_table
WHERE id BETWEEN 15000 AND 16000
GROUP BY firstname,
lastname
ORDER BY firstname;
-- enable caching
SET columnar.enable_column_cache = 't';
-- the results should be the same as above
SELECT firstname,
lastname,
SUM(id)
FROM big_table
WHERE id < 1000
GROUP BY firstname,
lastname
UNION
SELECT firstname,
lastname,
SUM(id)
FROM big_table
WHERE id BETWEEN 15000 AND 16000
GROUP BY firstname,
lastname
ORDER BY firstname;
-- disable caching
SET columnar.enable_column_cache = 'f';
CREATE TABLE test_2 (
value INT,
updated_value INT
) USING columnar;
INSERT INTO test_2 (value)
SELECT generate_series(1, 1000000, 1);
BEGIN;
SELECT SUM(value)
FROM test_2;
UPDATE test_2
SET updated_value = value * 2;
SELECT SUM(updated_value)
FROM test_2;
DELETE FROM test_2
WHERE value % 2 = 0;
SELECT SUM(value)
FROM test_2;
COMMIT;
DROP TABLE test_2;
set columnar.enable_column_cache = 't';
CREATE TABLE test_2 (
value INT,
updated_value INT
) USING columnar;
INSERT INTO test_2 (value)
SELECT generate_series(1, 1000000, 1);
BEGIN;
SELECT SUM(value)
FROM test_2;
UPDATE test_2
SET updated_value = value * 2;
SELECT SUM(updated_value)
FROM test_2;
DELETE FROM test_2
WHERE value % 2 = 0;
SELECT SUM(value)
FROM test_2;
COMMIT;
DROP TABLE test_2;
CREATE TABLE t1 (i int) USING columnar;
INSERT INTO t1 SELECT generate_series(1, 1000000, 1);
EXPLAIN SELECT COUNT(*) FROM t1;
DROP TABLE t1;