1-- Test bitmap AND and OR
2-- Generate enough data that we can test the lossy bitmaps.
3-- There's 55 tuples per page in the table. 53 is just
4-- below 55, so that an index scan with qual a = constant
5-- will return at least one hit per page. 59 is just above
6-- 55, so that an index scan with qual b = constant will return
7-- hits on most but not all pages. 53 and 59 are prime, so that
8-- there's a maximum number of a,b combinations in the table.
9-- That allows us to test all the different combinations of
10-- lossy and non-lossy pages with the minimum amount of data
11CREATE TABLE bmscantest (a int, b int, t text);
12INSERT INTO bmscantest
13  SELECT (r%53), (r%59), 'foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo'
14  FROM generate_series(1,70000) r;
15CREATE INDEX i_bmtest_a ON bmscantest(a);
16CREATE INDEX i_bmtest_b ON bmscantest(b);
17-- We want to use bitmapscans. With default settings, the planner currently
18-- chooses a bitmap scan for the queries below anyway, but let's make sure.
19set enable_indexscan=false;
20set enable_seqscan=false;
21-- Lower work_mem to trigger use of lossy bitmaps
22set work_mem = 64;
23-- Test bitmap-and.
24SELECT count(*) FROM bmscantest WHERE a = 1 AND b = 1;
25 count
26-------
27    23
28(1 row)
29
30-- Test bitmap-or.
31SELECT count(*) FROM bmscantest WHERE a = 1 OR b = 1;
32 count
33-------
34  2485
35(1 row)
36
37-- clean up
38DROP TABLE bmscantest;
39