Skip to content

Commit 0d78d5c

Browse files
committed
Added anyarray tests
1 parent 3e66699 commit 0d78d5c

File tree

3 files changed

+156
-1
lines changed

3 files changed

+156
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ REGRESS = rum rum_hash ruminv timestamp orderby orderby_hash altorder \
2020
int2 int4 int8 float4 float8 money oid \
2121
time timetz date interval \
2222
macaddr inet cidr text varchar char bytea bit varbit \
23-
numeric
23+
numeric anyarray
2424

2525
LDFLAGS_SL += $(filter -lm, $(LIBS))
2626

expected/anyarray.out

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+

sql/anyarray.sql

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
set enable_seqscan=off;
2+
SET enable_bitmapscan=OFF;
3+
4+
CREATE TABLE test_anyarray(
5+
i int[]
6+
);
7+
INSERT INTO test_anyarray
8+
SELECT ARRAY[1, x, x + 1] FROM generate_series(1, 10000) x;
9+
10+
CREATE INDEX test_anyarray_idx ON test_anyarray USING rum (i);
11+
12+
EXPLAIN (costs off)
13+
SELECT *, i <=> '{1}' FROM test_anyarray WHERE i % '{1}' ORDER BY i <=> '{1}' LIMIT 5;
14+
SELECT *, i <=> '{1}' FROM test_anyarray WHERE i % '{1}' ORDER BY i <=> '{1}' LIMIT 5;
15+
16+
EXPLAIN (costs off)
17+
SELECT *, i <=> '{1}' FROM test_anyarray WHERE i @> '{1}' ORDER BY i <=> '{1}' LIMIT 5;
18+
SELECT *, i <=> '{1}' FROM test_anyarray WHERE i @> '{1}' ORDER BY i <=> '{1}' LIMIT 5;
19+
20+
EXPLAIN (costs off)
21+
SELECT *, i <=> '{1}' FROM test_anyarray WHERE i % '{1}' ORDER BY i <=> '{1}' LIMIT 5000;
22+
23+
CREATE TABLE test_anyarray_ts(
24+
i int[],
25+
d timestamp
26+
);
27+
INSERT INTO test_anyarray_ts VALUES
28+
( '{1,2,3}', '2004-10-26 03:55:08' ),
29+
( '{2,3,4}', '2004-10-26 04:55:08' ),
30+
( '{3,4,5}', '2004-10-26 05:55:08' ),
31+
( '{4,5,6}', '2004-10-26 08:55:08' ),
32+
( '{5,6,7}', '2004-10-26 09:55:08' ),
33+
( '{6,7,8}', '2004-10-26 10:55:08' )
34+
;
35+
36+
CREATE INDEX test_anyarray_ts_idx ON test_anyarray_ts USING rum
37+
(i rum_anyarray_addon_ops, d)
38+
WITH (attach = 'd', to = 'i');
39+
40+
EXPLAIN (costs off)
41+
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;
42+
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;
43+
44+
EXPLAIN (costs off)
45+
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;
46+
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;

0 commit comments

Comments
 (0)