Skip to content

Commit 463dbfd

Browse files
committed
refactoring, more tests, disable anyarray_ops for <= PG 9.6
1 parent a3fdac3 commit 463dbfd

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

expected/array.out

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,50 @@ CREATE TABLE test_array (
88
);
99
INSERT INTO test_array VALUES ('{}'), ('{0}'), ('{1,2,3,4}'), ('{1,2,3}'), ('{1,2}'), ('{1}');
1010
CREATE INDEX idx_array ON test_array USING rum (i rum_anyarray_ops);
11+
SELECT NULL::int[] = '{1}';
12+
?column?
13+
----------
14+
15+
(1 row)
16+
17+
SELECT NULL::int[] && '{1}';
18+
?column?
19+
----------
20+
21+
(1 row)
22+
23+
SELECT NULL::int[] @> '{1}';
24+
?column?
25+
----------
26+
27+
(1 row)
28+
29+
SELECT NULL::int[] <@ '{1}';
30+
?column?
31+
----------
32+
33+
(1 row)
34+
35+
SELECT NULL::int[] % '{1}';
36+
?column?
37+
----------
38+
39+
(1 row)
40+
41+
SELECT NULL::int[] <=> '{1}';
42+
?column?
43+
----------
44+
45+
(1 row)
46+
47+
INSERT INTO test_array VALUES (NULL);
48+
SELECT * FROM test_array WHERE i = '{1}';
49+
i
50+
-----
51+
{1}
52+
(1 row)
53+
54+
DELETE FROM test_array WHERE i IS NULL;
1155
SELECT * FROM test_array WHERE i = '{NULL}';
1256
ERROR: array must not contain nulls
1357
SELECT * FROM test_array WHERE i = '{1,2,3,NULL}';

sql/array.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ INSERT INTO test_array VALUES ('{}'), ('{0}'), ('{1,2,3,4}'), ('{1,2,3}'), ('{1,
1313

1414
CREATE INDEX idx_array ON test_array USING rum (i rum_anyarray_ops);
1515

16+
17+
SELECT NULL::int[] = '{1}';
18+
SELECT NULL::int[] && '{1}';
19+
SELECT NULL::int[] @> '{1}';
20+
SELECT NULL::int[] <@ '{1}';
21+
SELECT NULL::int[] % '{1}';
22+
SELECT NULL::int[] <=> '{1}';
23+
24+
INSERT INTO test_array VALUES (NULL);
25+
SELECT * FROM test_array WHERE i = '{1}';
26+
DELETE FROM test_array WHERE i IS NULL;
27+
1628
SELECT * FROM test_array WHERE i = '{NULL}';
1729
SELECT * FROM test_array WHERE i = '{1,2,3,NULL}';
1830
SELECT * FROM test_array WHERE i = '{{1,2},{3,4}}';

src/rum_arr_utils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
} \
6161
} while (0)
6262

63-
#define InitDummySimpleArray(s, len) \
63+
#define INIT_DUMMY_SIMPLE_ARRAY(s, len) \
6464
do { \
6565
(s)->elems = NULL; \
6666
(s)->hashedElems = NULL; \
@@ -388,8 +388,8 @@ rum_anyarray_consistent(PG_FUNCTION_ARGS)
388388
/* there must be addInfo */
389389
Assert(nentries >= 0);
390390

391-
InitDummySimpleArray(&sa, nentries);
392-
InitDummySimpleArray(&sb, nkeys);
391+
INIT_DUMMY_SIMPLE_ARRAY(&sa, nentries);
392+
INIT_DUMMY_SIMPLE_ARRAY(&sb, nkeys);
393393
res = getSimilarity(&sa, &sb, intersection) >= SmlLimit;
394394
}
395395
else
@@ -444,8 +444,8 @@ rum_anyarray_ordering(PG_FUNCTION_ARGS)
444444
/* there must be addInfo */
445445
Assert(nentries >= 0);
446446

447-
InitDummySimpleArray(&sa, nentries);
448-
InitDummySimpleArray(&sb, nkeys);
447+
INIT_DUMMY_SIMPLE_ARRAY(&sa, nentries);
448+
INIT_DUMMY_SIMPLE_ARRAY(&sb, nkeys);
449449
sml = getSimilarity(&sa, &sb, intersection);
450450

451451
PG_RETURN_FLOAT8(DIST_FROM_SML(sml));

src/rumutil.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ initRumState(RumState * state, Relation index)
253253
*/
254254
if (index_getprocid(index, i + 1, GIN_COMPARE_PROC) != InvalidOid)
255255
{
256+
#if PG_VERSION_NUM < 100000
257+
ereport(ERROR,
258+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
259+
errmsg("array indexing is only available on PostgreSQL 10+")));
260+
#endif
256261
fmgr_info_copy(&(state->compareFn[i]),
257262
index_getprocinfo(index, i + 1, GIN_COMPARE_PROC),
258263
CurrentMemoryContext);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy