|
| 1 | +set enable_seqscan=off; |
| 2 | +SET enable_bitmapscan=OFF; |
| 3 | +CREATE TABLE test_anyarray( |
| 4 | + i int[] |
| 5 | +); |
| 6 | +INSERT INTO test_anyarray |
| 7 | +SELECT ARRAY[1, x, x + 1] FROM generate_series(1, 10000) x; |
| 8 | +CREATE INDEX test_anyarray_idx ON test_anyarray USING rum (i); |
| 9 | +EXPLAIN (costs off) |
| 10 | +SELECT *, i <=> '{1}' FROM test_anyarray WHERE i % '{1}' ORDER BY i <=> '{1}' LIMIT 5; |
| 11 | + QUERY PLAN |
| 12 | +----------------------------------------------------------- |
| 13 | + Limit |
| 14 | + -> Index Scan using test_anyarray_idx on test_anyarray |
| 15 | + Index Cond: (i % '{1}'::integer[]) |
| 16 | + Order By: (i <=> '{1}'::integer[]) |
| 17 | +(4 rows) |
| 18 | + |
| 19 | +SELECT *, i <=> '{1}' FROM test_anyarray WHERE i % '{1}' ORDER BY i <=> '{1}' LIMIT 5; |
| 20 | + i | ?column? |
| 21 | +---------+------------------ |
| 22 | + {1,1,2} | 1.4142135623731 |
| 23 | + {1,2,3} | 1.73205080756888 |
| 24 | + {1,3,4} | 1.73205080756888 |
| 25 | + {1,4,5} | 1.73205080756888 |
| 26 | + {1,5,6} | 1.73205080756888 |
| 27 | +(5 rows) |
| 28 | + |
| 29 | +EXPLAIN (costs off) |
| 30 | +SELECT *, i <=> '{1}' FROM test_anyarray WHERE i @> '{1}' ORDER BY i <=> '{1}' LIMIT 5; |
| 31 | + QUERY PLAN |
| 32 | +----------------------------------------------------------- |
| 33 | + Limit |
| 34 | + -> Index Scan using test_anyarray_idx on test_anyarray |
| 35 | + Index Cond: (i @> '{1}'::integer[]) |
| 36 | + Order By: (i <=> '{1}'::integer[]) |
| 37 | +(4 rows) |
| 38 | + |
| 39 | +SELECT *, i <=> '{1}' FROM test_anyarray WHERE i @> '{1}' ORDER BY i <=> '{1}' LIMIT 5; |
| 40 | + i | ?column? |
| 41 | +---------+------------------ |
| 42 | + {1,1,2} | 1.4142135623731 |
| 43 | + {1,2,3} | 1.73205080756888 |
| 44 | + {1,3,4} | 1.73205080756888 |
| 45 | + {1,4,5} | 1.73205080756888 |
| 46 | + {1,5,6} | 1.73205080756888 |
| 47 | +(5 rows) |
| 48 | + |
| 49 | +EXPLAIN (costs off) |
| 50 | +SELECT *, i <=> '{1}' FROM test_anyarray WHERE i % '{1}' ORDER BY i <=> '{1}' LIMIT 5000; |
| 51 | + QUERY PLAN |
| 52 | +----------------------------------------------------------- |
| 53 | + Limit |
| 54 | + -> Index Scan using test_anyarray_idx on test_anyarray |
| 55 | + Index Cond: (i % '{1}'::integer[]) |
| 56 | + Order By: (i <=> '{1}'::integer[]) |
| 57 | +(4 rows) |
| 58 | + |
| 59 | +CREATE TABLE test_anyarray_ts( |
| 60 | + i int[], |
| 61 | + d timestamp |
| 62 | +); |
| 63 | +INSERT INTO test_anyarray_ts VALUES |
| 64 | + ( '{1,2,3}', '2004-10-26 03:55:08' ), |
| 65 | + ( '{2,3,4}', '2004-10-26 04:55:08' ), |
| 66 | + ( '{3,4,5}', '2004-10-26 05:55:08' ), |
| 67 | + ( '{4,5,6}', '2004-10-26 08:55:08' ), |
| 68 | + ( '{5,6,7}', '2004-10-26 09:55:08' ), |
| 69 | + ( '{6,7,8}', '2004-10-26 10:55:08' ) |
| 70 | +; |
| 71 | +CREATE INDEX test_anyarray_ts_idx ON test_anyarray_ts USING rum |
| 72 | + (i rum_anyarray_addon_ops, d) |
| 73 | + WITH (attach = 'd', to = 'i'); |
| 74 | +EXPLAIN (costs off) |
| 75 | +SELECT *, d <=> '2004-10-26 08:00:00' FROM test_anyarray_ts WHERE i % '{3}' ORDER BY d <=> '2004-10-26 08:00:00' LIMIT 5; |
| 76 | + QUERY PLAN |
| 77 | +----------------------------------------------------------------------------------- |
| 78 | + Limit |
| 79 | + -> Index Scan using test_anyarray_ts_idx on test_anyarray_ts |
| 80 | + Order By: (d <=> 'Tue Oct 26 08:00:00 2004'::timestamp without time zone) |
| 81 | + Filter: (i % '{3}'::integer[]) |
| 82 | +(4 rows) |
| 83 | + |
| 84 | +SELECT *, d <=> '2004-10-26 08:00:00' FROM test_anyarray_ts WHERE i % '{3}' ORDER BY d <=> '2004-10-26 08:00:00' LIMIT 5; |
| 85 | + i | d | ?column? |
| 86 | +---------+--------------------------+---------- |
| 87 | + {3,4,5} | Tue Oct 26 05:55:08 2004 | 7492 |
| 88 | + {2,3,4} | Tue Oct 26 04:55:08 2004 | 11092 |
| 89 | + {1,2,3} | Tue Oct 26 03:55:08 2004 | 14692 |
| 90 | +(3 rows) |
| 91 | + |
| 92 | +EXPLAIN (costs off) |
| 93 | +SELECT *, d <=> '2004-10-26 08:00:00' FROM test_anyarray_ts WHERE i @> '{3}' ORDER BY d <=> '2004-10-26 08:00:00' LIMIT 5; |
| 94 | + QUERY PLAN |
| 95 | +----------------------------------------------------------------------------------- |
| 96 | + Limit |
| 97 | + -> Index Scan using test_anyarray_ts_idx on test_anyarray_ts |
| 98 | + Index Cond: (i @> '{3}'::integer[]) |
| 99 | + Order By: (d <=> 'Tue Oct 26 08:00:00 2004'::timestamp without time zone) |
| 100 | +(4 rows) |
| 101 | + |
| 102 | +SELECT *, d <=> '2004-10-26 08:00:00' FROM test_anyarray_ts WHERE i @> '{3}' ORDER BY d <=> '2004-10-26 08:00:00' LIMIT 5; |
| 103 | + i | d | ?column? |
| 104 | +---------+--------------------------+---------- |
| 105 | + {3,4,5} | Tue Oct 26 05:55:08 2004 | 7492 |
| 106 | + {2,3,4} | Tue Oct 26 04:55:08 2004 | 11092 |
| 107 | + {1,2,3} | Tue Oct 26 03:55:08 2004 | 14692 |
| 108 | +(3 rows) |
| 109 | + |
0 commit comments