Debian Codegraph @

contrib/bloom/expected/bloom.out

raw
1 CREATE EXTENSION bloom;
2 CREATE TABLE tst (
3 i int4,
4 t text
5 );
6 INSERT INTO tst SELECT i%10, substr(encode(sha256(i::text::bytea), 'hex'), 1, 1) FROM generate_series(1,2000) i;
7 CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (col1 = 3);
8 ALTER INDEX bloomidx SET (length=80);
9 SET enable_seqscan=on;
10 SET enable_bitmapscan=off;
11 SET enable_indexscan=off;
12 SELECT count(*) FROM tst WHERE i = 7;
13 count
14 -------
15 200
16 (1 row)
17
18 SELECT count(*) FROM tst WHERE t = '5';
19 count
20 -------
21 126
22 (1 row)
23
24 SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
25 count
26 -------
27 14
28 (1 row)
29
30 SET enable_seqscan=off;
31 SET enable_bitmapscan=on;
32 SET enable_indexscan=on;
33 EXPLAIN (COSTS OFF) SELECT count(*) FROM tst WHERE i = 7;
34 QUERY PLAN
35 -------------------------------------------
36 Aggregate
37 -> Bitmap Heap Scan on tst
38 Recheck Cond: (i = 7)
39 -> Bitmap Index Scan on bloomidx
40 Index Cond: (i = 7)
41 (5 rows)
42
43 EXPLAIN (COSTS OFF) SELECT count(*) FROM tst WHERE t = '5';
44 QUERY PLAN
45 -------------------------------------------
46 Aggregate
47 -> Bitmap Heap Scan on tst
48 Recheck Cond: (t = '5'::text)
49 -> Bitmap Index Scan on bloomidx
50 Index Cond: (t = '5'::text)
51 (5 rows)
52
53 EXPLAIN (COSTS OFF) SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
54 QUERY PLAN
55 ---------------------------------------------------------
56 Aggregate
57 -> Bitmap Heap Scan on tst
58 Recheck Cond: ((i = 7) AND (t = '5'::text))
59 -> Bitmap Index Scan on bloomidx
60 Index Cond: ((i = 7) AND (t = '5'::text))
61 (5 rows)
62
63 SELECT count(*) FROM tst WHERE i = 7;
64 count
65 -------
66 200
67 (1 row)
68
69 SELECT count(*) FROM tst WHERE t = '5';
70 count
71 -------
72 126
73 (1 row)
74
75 SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
76 count
77 -------
78 14
79 (1 row)
80
81 DELETE FROM tst;
82 INSERT INTO tst SELECT i%10, substr(encode(sha256(i::text::bytea), 'hex'), 1, 1) FROM generate_series(1,2000) i;
83 VACUUM ANALYZE tst;
84 SELECT count(*) FROM tst WHERE i = 7;
85 count
86 -------
87 200
88 (1 row)
89
90 SELECT count(*) FROM tst WHERE t = '5';
91 count
92 -------
93 126
94 (1 row)
95
96 SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
97 count
98 -------
99 14
100 (1 row)
101
102 DELETE FROM tst WHERE i > 1 OR t = '5';
103 VACUUM tst;
104 INSERT INTO tst SELECT i%10, substr(encode(sha256(i::text::bytea), 'hex'), 1, 1) FROM generate_series(1,2000) i;
105 SELECT count(*) FROM tst WHERE i = 7;
106 count
107 -------
108 200
109 (1 row)
110
111 SELECT count(*) FROM tst WHERE t = '5';
112 count
113 -------
114 126
115 (1 row)
116
117 SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
118 count
119 -------
120 14
121 (1 row)
122
123 VACUUM FULL tst;
124 SELECT count(*) FROM tst WHERE i = 7;
125 count
126 -------
127 200
128 (1 row)
129
130 SELECT count(*) FROM tst WHERE t = '5';
131 count
132 -------
133 126
134 (1 row)
135
136 SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
137 count
138 -------
139 14
140 (1 row)
141
142 -- Try an unlogged table too
143 CREATE UNLOGGED TABLE tstu (
144 i int4,
145 t text
146 );
147 INSERT INTO tstu SELECT i%10, substr(encode(sha256(i::text::bytea), 'hex'), 1, 1) FROM generate_series(1,2000) i;
148 CREATE INDEX bloomidxu ON tstu USING bloom (i, t) WITH (col2 = 4);
149 SET enable_seqscan=off;
150 SET enable_bitmapscan=on;
151 SET enable_indexscan=on;
152 EXPLAIN (COSTS OFF) SELECT count(*) FROM tstu WHERE i = 7;
153 QUERY PLAN
154 --------------------------------------------
155 Aggregate
156 -> Bitmap Heap Scan on tstu
157 Recheck Cond: (i = 7)
158 -> Bitmap Index Scan on bloomidxu
159 Index Cond: (i = 7)
160 (5 rows)
161
162 EXPLAIN (COSTS OFF) SELECT count(*) FROM tstu WHERE t = '5';
163 QUERY PLAN
164 --------------------------------------------
165 Aggregate
166 -> Bitmap Heap Scan on tstu
167 Recheck Cond: (t = '5'::text)
168 -> Bitmap Index Scan on bloomidxu
169 Index Cond: (t = '5'::text)
170 (5 rows)
171
172 EXPLAIN (COSTS OFF) SELECT count(*) FROM tstu WHERE i = 7 AND t = '5';
173 QUERY PLAN
174 ---------------------------------------------------------
175 Aggregate
176 -> Bitmap Heap Scan on tstu
177 Recheck Cond: ((i = 7) AND (t = '5'::text))
178 -> Bitmap Index Scan on bloomidxu
179 Index Cond: ((i = 7) AND (t = '5'::text))
180 (5 rows)
181
182 SELECT count(*) FROM tstu WHERE i = 7;
183 count
184 -------
185 200
186 (1 row)
187
188 SELECT count(*) FROM tstu WHERE t = '5';
189 count
190 -------
191 126
192 (1 row)
193
194 SELECT count(*) FROM tstu WHERE i = 7 AND t = '5';
195 count
196 -------
197 14
198 (1 row)
199
200 RESET enable_seqscan;
201 RESET enable_bitmapscan;
202 RESET enable_indexscan;
203 -- Run amvalidator function on our opclasses
204 SELECT opcname, amvalidate(opc.oid)
205 FROM pg_opclass opc JOIN pg_am am ON am.oid = opcmethod
206 WHERE amname = 'bloom'
207 ORDER BY 1;
208 opcname | amvalidate
209 ----------+------------
210 int4_ops | t
211 text_ops | t
212 (2 rows)
213
214 --
215 -- relation options
216 --
217 DROP INDEX bloomidx;
218 CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (length=7, col1=4);
219 SELECT reloptions FROM pg_class WHERE oid = 'bloomidx'::regclass;
220 reloptions
221 -------------------
222 {length=7,col1=4}
223 (1 row)
224
225 -- check for min and max values
226 \set VERBOSITY terse
227 CREATE INDEX bloomidx2 ON tst USING bloom (i, t) WITH (length=0);
228 ERROR: value 0 out of bounds for option "length"
229 CREATE INDEX bloomidx2 ON tst USING bloom (i, t) WITH (col1=0);
230 ERROR: value 0 out of bounds for option "col1"