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