|
1 | | -CREATE TABLE |
2 | | -COPY 77 |
3 | | -CREATE FUNCTION |
4 | | -CREATE INDEX |
5 | | -SET |
6 | | -SET |
7 | | -SET |
8 | | - ?column? | qnodes |
9 | | -----------+---------- |
10 | | - scan_seq | Seq Scan |
11 | | -(1 row) |
12 | | - |
13 | | - p |
| 1 | +CREATE TABLE test_points ( |
| 2 | + p spoint |
| 3 | +); |
| 4 | +COPY test_points (p) FROM stdin; |
| 5 | +CREATE OR REPLACE FUNCTION qnodes(q text) RETURNS text |
| 6 | +LANGUAGE 'plpgsql' AS |
| 7 | +$$ |
| 8 | +DECLARE |
| 9 | + exp TEXT; |
| 10 | + mat TEXT[]; |
| 11 | + ret TEXT[]; |
| 12 | +BEGIN |
| 13 | + FOR exp IN EXECUTE 'EXPLAIN ' || q |
| 14 | + LOOP |
| 15 | + --RAISE NOTICE 'EXP: %', exp; |
| 16 | + mat := regexp_matches(exp, ' *(?:-> *)?(.*Scan on (test_points|brin_spoint))'); |
| 17 | + --RAISE NOTICE 'MAT: %', mat; |
| 18 | + IF mat IS NOT NULL THEN |
| 19 | + ret := array_append(ret, mat[1]); |
| 20 | + END IF; |
| 21 | + --RAISE NOTICE 'RET: %', ret; |
| 22 | + END LOOP; |
| 23 | + RETURN array_to_string(ret,','); |
| 24 | +END; |
| 25 | +$$; |
| 26 | +CREATE INDEX brin_spoint ON test_points USING brin (p) WITH (pages_per_range = 16); |
| 27 | +set enable_indexscan = off; |
| 28 | +set enable_bitmapscan = off; |
| 29 | +set enable_seqscan = on; |
| 30 | +SELECT 'scan_seq', qnodes('SELECT * FROM test_points WHERE p <@ sbox ''( (10d,10d), (20d,20d) )'''); |
| 31 | + ?column? | qnodes |
| 32 | +----------+------------------------- |
| 33 | + scan_seq | Seq Scan on test_points |
| 34 | +(1 row) |
| 35 | + |
| 36 | +SELECT * FROM test_points WHERE p <@ sbox '( (10d,10d), (20d,20d) )'; |
| 37 | + p |
14 | 38 | ----------------------------------------- |
15 | 39 | (0.349065850398866 , 0.174532925199433) |
16 | 40 | (1 row) |
17 | 41 |
|
18 | | - ?column? | qnodes |
19 | | -----------+---------- |
20 | | - scan_seq | Seq Scan |
| 42 | +SELECT 'scan_seq', qnodes('SELECT * FROM test_points WHERE p && sbox ''( (10d,10d), (20d,20d) )'''); |
| 43 | + ?column? | qnodes |
| 44 | +----------+------------------------- |
| 45 | + scan_seq | Seq Scan on test_points |
21 | 46 | (1 row) |
22 | 47 |
|
23 | | - p |
| 48 | +SELECT * FROM test_points WHERE p && sbox '( (10d,10d), (20d,20d) )'; |
| 49 | + p |
24 | 50 | ----------------------------------------- |
25 | 51 | (0.349065850398866 , 0.174532925199433) |
26 | 52 | (1 row) |
27 | 53 |
|
28 | | -SET |
29 | | -SET |
30 | | -SET |
31 | | - ?column? | qnodes |
32 | | -----------+------------------------------------ |
33 | | - scan_idx | Bitmap Heap Scan,Bitmap Index Scan |
| 54 | +set enable_indexscan = off; |
| 55 | +set enable_bitmapscan = on; |
| 56 | +set enable_seqscan = off; |
| 57 | +SELECT 'scan_idx', qnodes('SELECT * FROM test_points WHERE p <@ sbox ''( (10d,10d), (20d,20d) )'''); |
| 58 | + ?column? | qnodes |
| 59 | +----------+------------------------------------------------------------------ |
| 60 | + scan_idx | Bitmap Heap Scan on test_points,Bitmap Index Scan on brin_spoint |
34 | 61 | (1 row) |
35 | 62 |
|
36 | | - p |
| 63 | +SELECT * FROM test_points WHERE p <@ sbox '( (10d,10d), (20d,20d) )'; |
| 64 | + p |
37 | 65 | ----------------------------------------- |
38 | 66 | (0.349065850398866 , 0.174532925199433) |
39 | 67 | (1 row) |
40 | 68 |
|
41 | | - ?column? | qnodes |
42 | | -----------+------------------------------------ |
43 | | - scan_idx | Bitmap Heap Scan,Bitmap Index Scan |
| 69 | +SELECT 'scan_idx', qnodes('SELECT * FROM test_points WHERE p && sbox ''( (10d,10d), (20d,20d) )'''); |
| 70 | + ?column? | qnodes |
| 71 | +----------+------------------------------------------------------------------ |
| 72 | + scan_idx | Bitmap Heap Scan on test_points,Bitmap Index Scan on brin_spoint |
44 | 73 | (1 row) |
45 | 74 |
|
46 | | - p |
| 75 | +SELECT * FROM test_points WHERE p && sbox '( (10d,10d), (20d,20d) )'; |
| 76 | + p |
47 | 77 | ----------------------------------------- |
48 | 78 | (0.349065850398866 , 0.174532925199433) |
49 | 79 | (1 row) |
50 | 80 |
|
51 | | -DROP INDEX |
52 | | -DROP TABLE |
53 | | -DROP FUNCTION |
54 | | -SET |
55 | | -SET |
56 | | -SET |
| 81 | +-- cleanup |
| 82 | +DROP INDEX brin_spoint; |
| 83 | +DROP TABLE test_points; |
| 84 | +DROP FUNCTION qnodes(text); |
| 85 | +set enable_indexscan = on; |
| 86 | +set enable_bitmapscan = on; |
| 87 | +set enable_seqscan = on; |
0 commit comments