diff -Nru postgresql-rum-1.3.7/debian/changelog postgresql-rum-1.3.9/debian/changelog --- postgresql-rum-1.3.7/debian/changelog 2020-10-19 19:26:00.000000000 +0000 +++ postgresql-rum-1.3.9/debian/changelog 2021-10-26 12:07:28.000000000 +0000 @@ -1,3 +1,21 @@ +postgresql-rum (1.3.9-1) unstable; urgency=medium + + * New upstream version. + + -- Christoph Berg Tue, 26 Oct 2021 14:07:28 +0200 + +postgresql-rum (1.3.8-2) unstable; urgency=medium + + * Upload for PostgreSQL 14. + + -- Christoph Berg Thu, 21 Oct 2021 10:51:24 +0200 + +postgresql-rum (1.3.8-1) experimental; urgency=medium + + * New upstream version. + + -- Christoph Berg Wed, 30 Jun 2021 14:21:23 +0200 + postgresql-rum (1.3.7-1) unstable; urgency=medium * Upload for PostgreSQL 13. diff -Nru postgresql-rum-1.3.7/debian/control postgresql-rum-1.3.9/debian/control --- postgresql-rum-1.3.7/debian/control 2020-10-19 19:26:00.000000000 +0000 +++ postgresql-rum-1.3.9/debian/control 2021-10-26 12:06:36.000000000 +0000 @@ -13,9 +13,9 @@ Vcs-Browser: https://salsa.debian.org/postgresql/postgresql-rum Vcs-Git: https://salsa.debian.org/postgresql/postgresql-rum.git -Package: postgresql-13-rum +Package: postgresql-14-rum Architecture: any -Depends: postgresql-13, ${misc:Depends}, ${shlibs:Depends} +Depends: postgresql-14, ${misc:Depends}, ${shlibs:Depends} Description: PostgreSQL RUM access method This PostgreSQL extension provides the RUM access method, an inverted index with additional information in posting lists. diff -Nru postgresql-rum-1.3.7/expected/int4.out postgresql-rum-1.3.9/expected/int4.out --- postgresql-rum-1.3.7/expected/int4.out 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/expected/int4.out 2021-10-08 09:20:34.000000000 +0000 @@ -145,7 +145,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) SELECT id, id <=> 400 FROM test_int4_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5; @@ -258,7 +257,6 @@ CREATE INDEX test_int4_a_idx ON test_int4_a USING rum (t rum_tsvector_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; EXPLAIN (costs off) SELECT count(*) FROM test_int4_a WHERE id < 400; QUERY PLAN @@ -448,7 +446,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) SELECT id, id <=> 400 FROM test_int4_h_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5; @@ -561,7 +558,6 @@ CREATE INDEX test_int4_h_a_idx ON test_int4_h_a USING rum (t rum_tsvector_hash_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; EXPLAIN (costs off) SELECT count(*) FROM test_int4_h_a WHERE id < 400; QUERY PLAN diff -Nru postgresql-rum-1.3.7/expected/int8_1.out postgresql-rum-1.3.9/expected/int8_1.out --- postgresql-rum-1.3.7/expected/int8_1.out 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/expected/int8_1.out 2021-10-08 09:20:34.000000000 +0000 @@ -130,7 +130,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) SELECT id, id <=> 400 FROM test_int8_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5; @@ -220,7 +219,6 @@ (t rum_tsvector_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); ERROR: doesn't support order index over pass-by-reference column -SET enable_bitmapscan=OFF; EXPLAIN (costs off) SELECT count(*) FROM test_int8_a WHERE id < 400::int8; QUERY PLAN @@ -413,7 +411,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) SELECT id, id <=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5; @@ -503,7 +500,6 @@ (t rum_tsvector_hash_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); ERROR: doesn't support order index over pass-by-reference column -SET enable_bitmapscan=OFF; EXPLAIN (costs off) SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8; QUERY PLAN diff -Nru postgresql-rum-1.3.7/expected/int8.out postgresql-rum-1.3.9/expected/int8.out --- postgresql-rum-1.3.7/expected/int8.out 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/expected/int8.out 2021-10-08 09:20:34.000000000 +0000 @@ -145,7 +145,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) SELECT id, id <=> 400 FROM test_int8_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5; @@ -258,7 +257,6 @@ CREATE INDEX test_int8_a_idx ON test_int8_a USING rum (t rum_tsvector_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; EXPLAIN (costs off) SELECT count(*) FROM test_int8_a WHERE id < 400::int8; QUERY PLAN @@ -448,7 +446,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) SELECT id, id <=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5; @@ -561,7 +558,6 @@ CREATE INDEX test_int8_h_a_idx ON test_int8_h_a USING rum (t rum_tsvector_hash_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; EXPLAIN (costs off) SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8; QUERY PLAN diff -Nru postgresql-rum-1.3.7/expected/rum.out postgresql-rum-1.3.9/expected/rum.out --- postgresql-rum-1.3.7/expected/rum.out 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/expected/rum.out 2021-10-08 09:20:34.000000000 +0000 @@ -381,6 +381,24 @@ 16.4493 | the few that escaped destruction in 1693. It is a beautiful, highly | '1693':7 'beauti':11 'destruct':5 'escap':4 'high':12 (20 rows) +-- Test correct work of phrase operator when position information is not in index. +create table test_rum_addon as table test_rum; +alter table test_rum_addon add column id serial; +create index on test_rum_addon using rum (a rum_tsvector_addon_ops, id) with (attach = 'id', to='a'); +select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way'); + t | a | id +---------------------------------------------------------------------+---------------------------------------------------------+---- + itself. Put on your "specs" and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12 | 9 +(1 row) + +explain (costs off) select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way'); + QUERY PLAN +------------------------------------------------------------ + Index Scan using test_rum_addon_a_id_idx on test_rum_addon + Index Cond: (a @@ '''half'' <-> ''way'''::tsquery) +(2 rows) + +-- select ('bjarn:6237 stroustrup:6238'::tsvector <=> 'bjarn <-> stroustrup'::tsquery)::numeric(10,5) AS distance; distance ---------- diff -Nru postgresql-rum-1.3.7/expected/security.out postgresql-rum-1.3.9/expected/security.out --- postgresql-rum-1.3.7/expected/security.out 1970-01-01 00:00:00.000000000 +0000 +++ postgresql-rum-1.3.9/expected/security.out 2021-10-08 09:20:34.000000000 +0000 @@ -0,0 +1,5 @@ +-- Check security CVE-2020-14350 +CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS $$ SELECT false $$ LANGUAGE SQL; +CREATE EXTENSION rum; +ERROR: function "rum_anyarray_similar" already exists with same argument types +DROP FUNCTION rum_anyarray_similar(anyarray,anyarray); diff -Nru postgresql-rum-1.3.7/gen_rum_sql--1.1--1.2.pl postgresql-rum-1.3.9/gen_rum_sql--1.1--1.2.pl --- postgresql-rum-1.3.7/gen_rum_sql--1.1--1.2.pl 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/gen_rum_sql--1.1--1.2.pl 2021-10-08 09:20:34.000000000 +0000 @@ -82,7 +82,7 @@ LANGUAGE C IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; @@ -97,7 +97,7 @@ ); -CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray) RETURNS float8 AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; diff -Nru postgresql-rum-1.3.7/Makefile postgresql-rum-1.3.9/Makefile --- postgresql-rum-1.3.7/Makefile 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/Makefile 2021-10-08 09:20:34.000000000 +0000 @@ -25,7 +25,7 @@ LDFLAGS_SL += $(filter -lm, $(LIBS)) -REGRESS = rum rum_validate rum_hash ruminv timestamp orderby orderby_hash \ +REGRESS = security rum rum_validate rum_hash ruminv timestamp orderby orderby_hash \ altorder altorder_hash limits \ int2 int4 int8 float4 float8 money oid \ time timetz date interval \ diff -Nru postgresql-rum-1.3.7/README.md postgresql-rum-1.3.9/README.md --- postgresql-rum-1.3.7/README.md 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/README.md 2021-10-08 09:20:34.000000000 +0000 @@ -16,7 +16,7 @@ - Slow ranking. It is need position information about lexems to ranking. `GIN` index doesn't store positions of lexems. So after index scan we need additional -heap scan to retreive lexems positions. +heap scan to retrieve lexems positions. - Slow phrase search with `GIN` index. This problem relates with previous problem. It is need position information to perform phrase search. - Slow ordering by timestamp. `GIN` index can't store some related information @@ -239,7 +239,7 @@ For type: `anyarray` -This operator class stores `anyarrray` elements with length of the array. +This operator class stores `anyarray` elements with length of the array. Supports operators `&&`, `@>`, `<@`, `=`, `%` operators. Supports ordering by `<=>` operator. For example we have the table: @@ -278,7 +278,7 @@ For type: `anyarray` -This operator class stores `anyarrray` elements with any supported by module +This operator class stores `anyarray` elements with any supported by module field. ## Todo diff -Nru postgresql-rum-1.3.7/rum--1.0.sql postgresql-rum-1.3.9/rum--1.0.sql --- postgresql-rum-1.3.7/rum--1.0.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/rum--1.0.sql 2021-10-08 09:20:34.000000000 +0000 @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION rumhandler(internal) +CREATE FUNCTION rumhandler(internal) RETURNS index_am_handler AS 'MODULE_PATHNAME' LANGUAGE C; diff -Nru postgresql-rum-1.3.7/rum--1.1--1.2.sql postgresql-rum-1.3.9/rum--1.1--1.2.sql --- postgresql-rum-1.3.7/rum--1.1--1.2.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/rum--1.1--1.2.sql 2021-10-08 09:20:34.000000000 +0000 @@ -10,7 +10,7 @@ LANGUAGE C IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; @@ -25,7 +25,7 @@ ); -CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray) RETURNS float8 AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; diff -Nru postgresql-rum-1.3.7/rum--1.1.sql postgresql-rum-1.3.9/rum--1.1.sql --- postgresql-rum-1.3.7/rum--1.1.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/rum--1.1.sql 2021-10-08 09:20:34.000000000 +0000 @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION rumhandler(internal) +CREATE FUNCTION rumhandler(internal) RETURNS index_am_handler AS 'MODULE_PATHNAME' LANGUAGE C; diff -Nru postgresql-rum-1.3.7/rum--1.2.sql postgresql-rum-1.3.9/rum--1.2.sql --- postgresql-rum-1.3.7/rum--1.2.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/rum--1.2.sql 2021-10-08 09:20:34.000000000 +0000 @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION rumhandler(internal) +CREATE FUNCTION rumhandler(internal) RETURNS index_am_handler AS 'MODULE_PATHNAME' LANGUAGE C; @@ -1527,7 +1527,7 @@ LANGUAGE C IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; @@ -1542,7 +1542,7 @@ ); -CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray) RETURNS float8 AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; diff -Nru postgresql-rum-1.3.7/rum--1.3.sql postgresql-rum-1.3.9/rum--1.3.sql --- postgresql-rum-1.3.7/rum--1.3.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/rum--1.3.sql 2021-10-08 09:20:34.000000000 +0000 @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION rumhandler(internal) +CREATE FUNCTION rumhandler(internal) RETURNS index_am_handler AS 'MODULE_PATHNAME' LANGUAGE C; @@ -1527,7 +1527,7 @@ LANGUAGE C IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; @@ -1542,7 +1542,7 @@ ); -CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray) +CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray) RETURNS float8 AS 'MODULE_PATHNAME' LANGUAGE C STRICT STABLE; diff -Nru postgresql-rum-1.3.7/sql/int4.sql postgresql-rum-1.3.9/sql/int4.sql --- postgresql-rum-1.3.7/sql/int4.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/sql/int4.sql 2021-10-08 09:20:34.000000000 +0000 @@ -40,7 +40,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) @@ -66,8 +65,6 @@ (t rum_tsvector_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; - EXPLAIN (costs off) SELECT count(*) FROM test_int4_a WHERE id < 400; SELECT count(*) FROM test_int4_a WHERE id < 400; @@ -107,7 +104,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) @@ -133,8 +129,6 @@ (t rum_tsvector_hash_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; - EXPLAIN (costs off) SELECT count(*) FROM test_int4_h_a WHERE id < 400; SELECT count(*) FROM test_int4_h_a WHERE id < 400; diff -Nru postgresql-rum-1.3.7/sql/int8.sql postgresql-rum-1.3.9/sql/int8.sql --- postgresql-rum-1.3.7/sql/int8.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/sql/int8.sql 2021-10-08 09:20:34.000000000 +0000 @@ -40,7 +40,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) @@ -66,8 +65,6 @@ (t rum_tsvector_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; - EXPLAIN (costs off) SELECT count(*) FROM test_int8_a WHERE id < 400::int8; SELECT count(*) FROM test_int8_a WHERE id < 400::int8; @@ -107,7 +104,6 @@ RESET enable_indexscan; RESET enable_indexonlyscan; -RESET enable_bitmapscan; SET enable_seqscan = off; EXPLAIN (costs off) @@ -120,6 +116,7 @@ SELECT id, id |=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id |=> 400 LIMIT 5; SELECT id, id |=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id |=> 400 LIMIT 5; + EXPLAIN (costs off) SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id <= 400::int8 ORDER BY id; SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id <= 400::int8 ORDER BY id; @@ -133,8 +130,6 @@ (t rum_tsvector_hash_addon_ops, id) WITH (attach = 'id', to = 't', order_by_attach='t'); -SET enable_bitmapscan=OFF; - EXPLAIN (costs off) SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8; SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8; diff -Nru postgresql-rum-1.3.7/sql/rum.sql postgresql-rum-1.3.9/sql/rum.sql --- postgresql-rum-1.3.7/sql/rum.sql 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/sql/rum.sql 2021-10-08 09:20:34.000000000 +0000 @@ -141,5 +141,14 @@ WHERE a @@ to_tsquery('pg_catalog.english', 'b:*') ORDER BY a <=> to_tsquery('pg_catalog.english', 'b:*'); +-- Test correct work of phrase operator when position information is not in index. +create table test_rum_addon as table test_rum; +alter table test_rum_addon add column id serial; +create index on test_rum_addon using rum (a rum_tsvector_addon_ops, id) with (attach = 'id', to='a'); + +select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way'); +explain (costs off) select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way'); +-- + select ('bjarn:6237 stroustrup:6238'::tsvector <=> 'bjarn <-> stroustrup'::tsquery)::numeric(10,5) AS distance; SELECT ('stroustrup:5508B,6233B,6238B bjarn:6235B,6237B' <=> 'bjarn <-> stroustrup'::tsquery)::numeric(10,5) AS distance; diff -Nru postgresql-rum-1.3.7/sql/security.sql postgresql-rum-1.3.9/sql/security.sql --- postgresql-rum-1.3.7/sql/security.sql 1970-01-01 00:00:00.000000000 +0000 +++ postgresql-rum-1.3.9/sql/security.sql 2021-10-08 09:20:34.000000000 +0000 @@ -0,0 +1,5 @@ +-- Check security CVE-2020-14350 +CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS $$ SELECT false $$ LANGUAGE SQL; +CREATE EXTENSION rum; +DROP FUNCTION rum_anyarray_similar(anyarray,anyarray); + diff -Nru postgresql-rum-1.3.7/src/rumdatapage.c postgresql-rum-1.3.9/src/rumdatapage.c --- postgresql-rum-1.3.7/src/rumdatapage.c 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/src/rumdatapage.c 2021-10-08 09:20:34.000000000 +0000 @@ -736,7 +736,7 @@ if (offset <= maxoff) memmove(ptr + sizeof(PostingItem), ptr, - ((uint16_t)(maxoff - offset + 1)) * sizeof(PostingItem)); + ((uint16)(maxoff - offset + 1)) * sizeof(PostingItem)); } memcpy(ptr, data, sizeof(PostingItem)); RumPageGetOpaque(page)->maxoff++; @@ -763,7 +763,7 @@ char *dstptr = RumDataPageGetItem(page, offset), *sourceptr = RumDataPageGetItem(page, offset + 1); - memmove(dstptr, sourceptr, sizeof(PostingItem) * (uint16_t)(maxoff - offset)); + memmove(dstptr, sourceptr, sizeof(PostingItem) * (uint16)(maxoff - offset)); } RumPageGetOpaque(page)->maxoff--; @@ -853,7 +853,14 @@ ItemPointerData iptr = {{0, 0}, 0}; RumItem copyItem; bool copyItemEmpty = true; - char pageCopy[BLCKSZ]; + /* + * Must have pageCopy MAXALIGNed to use PG macros to access data in + * it. Should not rely on compiler alignment preferences to avoid + * pageCopy overflow related to PG in-memory page items alignment + * inside rumDataPageLeafRead() or elsewhere. + */ + char pageCopyStorage[BLCKSZ + MAXIMUM_ALIGNOF]; + char *pageCopy = (char *) MAXALIGN(pageCopyStorage); int maxoff = RumPageGetOpaque(page)->maxoff; int freespace, insertCount = 0; @@ -1055,7 +1062,14 @@ RumItem item; int totalCount = 0; int maxItemIndex = btree->curitem; - static char lpageCopy[BLCKSZ]; + /* + * Must have lpageCopy MAXALIGNed to use PG macros to access data in + * it. Should not rely on compiler alignment preferences to avoid + * lpageCopy overflow related to PG in-memory page items alignment + * inside rumDataPageLeafRead() etc. + */ + static char lpageCopyStorage[BLCKSZ + MAXIMUM_ALIGNOF]; + char *lpageCopy = (char *) MAXALIGN(lpageCopyStorage); memset(&item, 0, sizeof(item)); dataPrepareData(btree, newlPage, off); @@ -1233,8 +1247,14 @@ OffsetNumber maxoff = RumPageGetOpaque(newlPage)->maxoff; Size pageSize = PageGetPageSize(newlPage); Size freeSpace; - - static char vector[2 * BLCKSZ]; + /* + * Must have vector MAXALIGNed to use PG macros to access data in + * it. Should not rely on compiler alignment preferences to avoid + * vector overflow related to PG in-memory page items alignment + * inside rumDataPageLeafRead() etc. + */ + static char vectorStorage[2 * BLCKSZ + MAXIMUM_ALIGNOF]; + char *vector = (char *) MAXALIGN(vectorStorage); RumInitPage(rPage, RumPageGetOpaque(newlPage)->flags, pageSize); freeSpace = RumDataPageGetFreeSpace(rPage); @@ -1246,7 +1266,7 @@ Assert(!RumPageIsLeaf(newlPage)); ptr = vector + (off - 1) * sizeofitem; if (maxoff + 1 - off != 0) - memmove(ptr + sizeofitem, ptr, (uint16_t)(maxoff - off + 1) * sizeofitem); + memmove(ptr + sizeofitem, ptr, (uint16)(maxoff - off + 1) * sizeofitem); memcpy(ptr, &(btree->pitem), sizeofitem); maxoff++; @@ -1273,7 +1293,7 @@ ptr = RumDataPageGetItem(rPage, FirstOffsetNumber); memcpy(ptr, vector + separator * sizeofitem, - (uint16_t)(maxoff - separator) * sizeofitem); + (uint16)(maxoff - separator) * sizeofitem); RumPageGetOpaque(rPage)->maxoff = maxoff - separator; /* Adjust pd_lower */ ((PageHeader) rPage)->pd_lower = (ptr + diff -Nru postgresql-rum-1.3.7/src/rumentrypage.c postgresql-rum-1.3.9/src/rumentrypage.c --- postgresql-rum-1.3.7/src/rumentrypage.c 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/src/rumentrypage.c 2021-10-08 09:20:34.000000000 +0000 @@ -428,8 +428,14 @@ Page page; Page newlPage = PageGetTempPageCopy(lPage); Size pageSize = PageGetPageSize(newlPage); - - static char tupstore[2 * BLCKSZ]; + /* + * Must have tupstore MAXALIGNed to use PG macros to access data in + * it. Should not rely on compiler alignment preferences to avoid + * tupstore overflow related to PG in-memory page items alignment + * inside rumDataPageLeafRead() or elsewhere. + */ + static char tupstoreStorage[2 * BLCKSZ + MAXIMUM_ALIGNOF]; + char *tupstore = (char *) MAXALIGN(tupstoreStorage); entryPreparePage(btree, newlPage, off); diff -Nru postgresql-rum-1.3.7/src/rumget.c postgresql-rum-1.3.9/src/rumget.c --- postgresql-rum-1.3.7/src/rumget.c 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/src/rumget.c 2021-10-08 09:20:34.000000000 +0000 @@ -687,7 +687,7 @@ else if (RumGetNPosting(itup) > 0) { entry->nlist = RumGetNPosting(itup); - entry->predictNumberResult = (uint32_t)entry->nlist; + entry->predictNumberResult = (uint32)entry->nlist; entry->list = (RumItem *) palloc(sizeof(RumItem) * entry->nlist); rumReadTuple(rumstate, entry->attnum, itup, entry->list, true); @@ -1104,7 +1104,7 @@ else if (RumGetNPosting(itup) > 0) { entry->nlist = RumGetNPosting(itup); - entry->predictNumberResult = (uint32_t)entry->nlist; + entry->predictNumberResult = (uint32)entry->nlist; entry->list = (RumItem *) palloc(sizeof(RumItem) * entry->nlist); rumReadTuple(rumstate, entry->attnum, itup, entry->list, true); diff -Nru postgresql-rum-1.3.7/src/rum.h postgresql-rum-1.3.9/src/rum.h --- postgresql-rum-1.3.7/src/rum.h 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/src/rum.h 2021-10-08 09:20:34.000000000 +0000 @@ -449,6 +449,9 @@ extern bool ruminsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique +#if PG_VERSION_NUM >= 140000 + , bool indexUnchanged +#endif #if PG_VERSION_NUM >= 100000 , struct IndexInfo *indexInfo #endif diff -Nru postgresql-rum-1.3.7/src/ruminsert.c postgresql-rum-1.3.9/src/ruminsert.c --- postgresql-rum-1.3.7/src/ruminsert.c 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/src/ruminsert.c 2021-10-08 09:20:34.000000000 +0000 @@ -818,6 +818,9 @@ ruminsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique +#if PG_VERSION_NUM >= 140000 + , bool indexUnchanged +#endif #if PG_VERSION_NUM >= 100000 , struct IndexInfo *indexInfo #endif diff -Nru postgresql-rum-1.3.7/src/rum_ts_utils.c postgresql-rum-1.3.9/src/rum_ts_utils.c --- postgresql-rum-1.3.7/src/rum_ts_utils.c 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/src/rum_ts_utils.c 2021-10-08 09:20:34.000000000 +0000 @@ -244,19 +244,15 @@ gcv.map_item_operand = (int *) (extra_data[0]); gcv.need_recheck = &recheck; -#if PG_VERSION_NUM >= 130000 - res = TS_execute(GETQUERY(query), - &gcv, - TS_EXEC_PHRASE_NO_POS | TS_EXEC_SKIP_NOT, - pre_checkcondition_rum); -#else res = TS_execute(GETQUERY(query), &gcv, - TS_EXEC_PHRASE_NO_POS, - pre_checkcondition_rum); + TS_EXEC_PHRASE_NO_POS +#if PG_VERSION_NUM >= 130000 + | TS_EXEC_SKIP_NOT #endif + , + pre_checkcondition_rum); } - PG_RETURN_BOOL(res); } @@ -604,6 +600,14 @@ if (curitem->qoperator.oper == OP_PHRASE) { + /* In case of index where position is not available + * (e.g. addon_ops) output TS_MAYBE even in case both + * lmatch and rmatch are TS_YES. Otherwise we can lose + * results of phrase queries. + */ + if (flags & TS_EXEC_PHRASE_NO_POS) + return TS_MAYBE; + /* * Compute Loffset and Roffset suitable for phrase match, and * compute overall width of whole phrase match. @@ -840,6 +844,11 @@ * converting at the topmost phrase operator gives results that * are bug-compatible with the old implementation, so do it like * this for now. + * + * Checking for TS_EXEC_PHRASE_NO_POS has been moved inside + * rum_phrase_execute, otherwise we can lose results of phrase + * operator when position information is not available in index + * (e.g. index built with addon_ops) */ switch (rum_phrase_execute(curitem, arg, flags, chkcond, NULL)) { diff -Nru postgresql-rum-1.3.7/t/001_wal.pl postgresql-rum-1.3.9/t/001_wal.pl --- postgresql-rum-1.3.7/t/001_wal.pl 2020-10-14 15:36:59.000000000 +0000 +++ postgresql-rum-1.3.9/t/001_wal.pl 2021-10-08 09:20:34.000000000 +0000 @@ -23,12 +23,12 @@ if ($server_version < 100000) { $caughtup_query = - "SELECT pg_current_xlog_location() <= write_location FROM pg_stat_replication WHERE application_name = '$applname';"; + "SELECT pg_current_xlog_location() <= replay_location FROM pg_stat_replication WHERE application_name = '$applname';"; } else { $caughtup_query = - "SELECT pg_current_wal_lsn() <= write_lsn FROM pg_stat_replication WHERE application_name = '$applname';"; + "SELECT pg_current_wal_lsn() <= replay_lsn FROM pg_stat_replication WHERE application_name = '$applname';"; } $node_master->poll_query_until('postgres', $caughtup_query) or die "Timed out while waiting for standby 1 to catch up";