Skip to content

Commit 1a4d4b8

Browse files
committedJun 1, 2021
Merge branch 'master' of git.postgrespro.ru:pgpro-dev/rum
2 parents 3d331aa + 727d692 commit 1a4d4b8

21 files changed

+109
-60
lines changed
 

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RELATIVE_INCLUDES = $(addprefix src/, $(INCLUDES))
2525

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

28-
REGRESS = rum rum_validate rum_hash ruminv timestamp orderby orderby_hash \
28+
REGRESS = security rum rum_validate rum_hash ruminv timestamp orderby orderby_hash \
2929
altorder altorder_hash limits \
3030
int2 int4 int8 float4 float8 money oid \
3131
time timetz date interval \

‎expected/int4.out

-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ SELECT id FROM test_int4_o WHERE t @@ 'wr&qh' AND id >= 400 ORDER BY id;
145145

146146
RESET enable_indexscan;
147147
RESET enable_indexonlyscan;
148-
RESET enable_bitmapscan;
149148
SET enable_seqscan = off;
150149
EXPLAIN (costs off)
151150
SELECT id, id <=> 400 FROM test_int4_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5;
@@ -258,7 +257,6 @@ CREATE TABLE test_int4_a AS SELECT id::int4, t FROM tsts;
258257
CREATE INDEX test_int4_a_idx ON test_int4_a USING rum
259258
(t rum_tsvector_addon_ops, id)
260259
WITH (attach = 'id', to = 't', order_by_attach='t');
261-
SET enable_bitmapscan=OFF;
262260
EXPLAIN (costs off)
263261
SELECT count(*) FROM test_int4_a WHERE id < 400;
264262
QUERY PLAN
@@ -448,7 +446,6 @@ SELECT id FROM test_int4_h_o WHERE t @@ 'wr&qh' AND id >= 400 ORDER BY id;
448446

449447
RESET enable_indexscan;
450448
RESET enable_indexonlyscan;
451-
RESET enable_bitmapscan;
452449
SET enable_seqscan = off;
453450
EXPLAIN (costs off)
454451
SELECT id, id <=> 400 FROM test_int4_h_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5;
@@ -561,7 +558,6 @@ CREATE TABLE test_int4_h_a AS SELECT id::int4, t FROM tsts;
561558
CREATE INDEX test_int4_h_a_idx ON test_int4_h_a USING rum
562559
(t rum_tsvector_hash_addon_ops, id)
563560
WITH (attach = 'id', to = 't', order_by_attach='t');
564-
SET enable_bitmapscan=OFF;
565561
EXPLAIN (costs off)
566562
SELECT count(*) FROM test_int4_h_a WHERE id < 400;
567563
QUERY PLAN

‎expected/int8.out

-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ SELECT id FROM test_int8_o WHERE t @@ 'wr&qh' AND id >= 400::int8 ORDER BY id;
145145

146146
RESET enable_indexscan;
147147
RESET enable_indexonlyscan;
148-
RESET enable_bitmapscan;
149148
SET enable_seqscan = off;
150149
EXPLAIN (costs off)
151150
SELECT id, id <=> 400 FROM test_int8_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5;
@@ -258,7 +257,6 @@ CREATE TABLE test_int8_a AS SELECT id::int8, t FROM tsts;
258257
CREATE INDEX test_int8_a_idx ON test_int8_a USING rum
259258
(t rum_tsvector_addon_ops, id)
260259
WITH (attach = 'id', to = 't', order_by_attach='t');
261-
SET enable_bitmapscan=OFF;
262260
EXPLAIN (costs off)
263261
SELECT count(*) FROM test_int8_a WHERE id < 400::int8;
264262
QUERY PLAN
@@ -448,7 +446,6 @@ SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id >= 400::int8 ORDER BY id
448446

449447
RESET enable_indexscan;
450448
RESET enable_indexonlyscan;
451-
RESET enable_bitmapscan;
452449
SET enable_seqscan = off;
453450
EXPLAIN (costs off)
454451
SELECT id, id <=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5;
@@ -561,7 +558,6 @@ CREATE TABLE test_int8_h_a AS SELECT id::int8, t FROM tsts;
561558
CREATE INDEX test_int8_h_a_idx ON test_int8_h_a USING rum
562559
(t rum_tsvector_hash_addon_ops, id)
563560
WITH (attach = 'id', to = 't', order_by_attach='t');
564-
SET enable_bitmapscan=OFF;
565561
EXPLAIN (costs off)
566562
SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8;
567563
QUERY PLAN

‎expected/int8_1.out

-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ SELECT id FROM test_int8_o WHERE t @@ 'wr&qh' AND id >= 400::int8 ORDER BY id;
130130

131131
RESET enable_indexscan;
132132
RESET enable_indexonlyscan;
133-
RESET enable_bitmapscan;
134133
SET enable_seqscan = off;
135134
EXPLAIN (costs off)
136135
SELECT id, id <=> 400 FROM test_int8_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5;
@@ -220,7 +219,6 @@ CREATE INDEX test_int8_a_idx ON test_int8_a USING rum
220219
(t rum_tsvector_addon_ops, id)
221220
WITH (attach = 'id', to = 't', order_by_attach='t');
222221
ERROR: doesn't support order index over pass-by-reference column
223-
SET enable_bitmapscan=OFF;
224222
EXPLAIN (costs off)
225223
SELECT count(*) FROM test_int8_a WHERE id < 400::int8;
226224
QUERY PLAN
@@ -413,7 +411,6 @@ SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id >= 400::int8 ORDER BY id
413411

414412
RESET enable_indexscan;
415413
RESET enable_indexonlyscan;
416-
RESET enable_bitmapscan;
417414
SET enable_seqscan = off;
418415
EXPLAIN (costs off)
419416
SELECT id, id <=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id <=> 400 LIMIT 5;
@@ -503,7 +500,6 @@ CREATE INDEX test_int8_h_a_idx ON test_int8_h_a USING rum
503500
(t rum_tsvector_hash_addon_ops, id)
504501
WITH (attach = 'id', to = 't', order_by_attach='t');
505502
ERROR: doesn't support order index over pass-by-reference column
506-
SET enable_bitmapscan=OFF;
507503
EXPLAIN (costs off)
508504
SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8;
509505
QUERY PLAN

‎expected/rum.out

+18
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ SELECT (a <=> to_tsquery('pg_catalog.english', 'b:*'))::numeric(10,4) AS distanc
381381
16.4493 | the few that escaped destruction in 1693. It is a beautiful, highly | '1693':7 'beauti':11 'destruct':5 'escap':4 'high':12
382382
(20 rows)
383383

384+
-- Test correct work of phrase operator when position information is not in index.
385+
create table test_rum_addon as table test_rum;
386+
alter table test_rum_addon add column id serial;
387+
create index on test_rum_addon using rum (a rum_tsvector_addon_ops, id) with (attach = 'id', to='a');
388+
select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way');
389+
t | a | id
390+
---------------------------------------------------------------------+---------------------------------------------------------+----
391+
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
392+
(1 row)
393+
394+
explain (costs off) select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way');
395+
QUERY PLAN
396+
------------------------------------------------------------
397+
Index Scan using test_rum_addon_a_id_idx on test_rum_addon
398+
Index Cond: (a @@ '''half'' <-> ''way'''::tsquery)
399+
(2 rows)
400+
401+
--
384402
select ('bjarn:6237 stroustrup:6238'::tsvector <=> 'bjarn <-> stroustrup'::tsquery)::numeric(10,5) AS distance;
385403
distance
386404
----------

‎expected/security.out

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Check security CVE-2020-14350
2+
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS $$ SELECT false $$ LANGUAGE SQL;
3+
CREATE EXTENSION rum;
4+
ERROR: function "rum_anyarray_similar" already exists with same argument types
5+
DROP FUNCTION rum_anyarray_similar(anyarray,anyarray);

‎gen_rum_sql--1.1--1.2.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
LANGUAGE C IMMUTABLE STRICT;
8383
8484
85-
CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray)
85+
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray)
8686
RETURNS bool
8787
AS 'MODULE_PATHNAME'
8888
LANGUAGE C STRICT STABLE;
@@ -97,7 +97,7 @@
9797
);
9898
9999
100-
CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray)
100+
CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray)
101101
RETURNS float8
102102
AS 'MODULE_PATHNAME'
103103
LANGUAGE C STRICT STABLE;

‎rum--1.0.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE OR REPLACE FUNCTION rumhandler(internal)
1+
CREATE FUNCTION rumhandler(internal)
22
RETURNS index_am_handler
33
AS 'MODULE_PATHNAME'
44
LANGUAGE C;

‎rum--1.1--1.2.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ AS 'MODULE_PATHNAME'
1010
LANGUAGE C IMMUTABLE STRICT;
1111

1212

13-
CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray)
13+
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray)
1414
RETURNS bool
1515
AS 'MODULE_PATHNAME'
1616
LANGUAGE C STRICT STABLE;
@@ -25,7 +25,7 @@ CREATE OPERATOR % (
2525
);
2626

2727

28-
CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray)
28+
CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray)
2929
RETURNS float8
3030
AS 'MODULE_PATHNAME'
3131
LANGUAGE C STRICT STABLE;

‎rum--1.1.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE OR REPLACE FUNCTION rumhandler(internal)
1+
CREATE FUNCTION rumhandler(internal)
22
RETURNS index_am_handler
33
AS 'MODULE_PATHNAME'
44
LANGUAGE C;

‎rum--1.2.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE OR REPLACE FUNCTION rumhandler(internal)
1+
CREATE FUNCTION rumhandler(internal)
22
RETURNS index_am_handler
33
AS 'MODULE_PATHNAME'
44
LANGUAGE C;
@@ -1527,7 +1527,7 @@ AS 'MODULE_PATHNAME'
15271527
LANGUAGE C IMMUTABLE STRICT;
15281528

15291529

1530-
CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray)
1530+
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray)
15311531
RETURNS bool
15321532
AS 'MODULE_PATHNAME'
15331533
LANGUAGE C STRICT STABLE;
@@ -1542,7 +1542,7 @@ CREATE OPERATOR % (
15421542
);
15431543

15441544

1545-
CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray)
1545+
CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray)
15461546
RETURNS float8
15471547
AS 'MODULE_PATHNAME'
15481548
LANGUAGE C STRICT STABLE;

‎rum--1.3.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE OR REPLACE FUNCTION rumhandler(internal)
1+
CREATE FUNCTION rumhandler(internal)
22
RETURNS index_am_handler
33
AS 'MODULE_PATHNAME'
44
LANGUAGE C;
@@ -1527,7 +1527,7 @@ AS 'MODULE_PATHNAME'
15271527
LANGUAGE C IMMUTABLE STRICT;
15281528

15291529

1530-
CREATE OR REPLACE FUNCTION rum_anyarray_similar(anyarray,anyarray)
1530+
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray)
15311531
RETURNS bool
15321532
AS 'MODULE_PATHNAME'
15331533
LANGUAGE C STRICT STABLE;
@@ -1542,7 +1542,7 @@ CREATE OPERATOR % (
15421542
);
15431543

15441544

1545-
CREATE OR REPLACE FUNCTION rum_anyarray_distance(anyarray,anyarray)
1545+
CREATE FUNCTION rum_anyarray_distance(anyarray,anyarray)
15461546
RETURNS float8
15471547
AS 'MODULE_PATHNAME'
15481548
LANGUAGE C STRICT STABLE;

‎sql/int4.sql

-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ SELECT id FROM test_int4_o WHERE t @@ 'wr&qh' AND id >= 400 ORDER BY id;
4040

4141
RESET enable_indexscan;
4242
RESET enable_indexonlyscan;
43-
RESET enable_bitmapscan;
4443
SET enable_seqscan = off;
4544

4645
EXPLAIN (costs off)
@@ -66,8 +65,6 @@ CREATE INDEX test_int4_a_idx ON test_int4_a USING rum
6665
(t rum_tsvector_addon_ops, id)
6766
WITH (attach = 'id', to = 't', order_by_attach='t');
6867

69-
SET enable_bitmapscan=OFF;
70-
7168
EXPLAIN (costs off)
7269
SELECT count(*) FROM test_int4_a WHERE id < 400;
7370
SELECT count(*) FROM test_int4_a WHERE id < 400;
@@ -107,7 +104,6 @@ SELECT id FROM test_int4_h_o WHERE t @@ 'wr&qh' AND id >= 400 ORDER BY id;
107104

108105
RESET enable_indexscan;
109106
RESET enable_indexonlyscan;
110-
RESET enable_bitmapscan;
111107
SET enable_seqscan = off;
112108

113109
EXPLAIN (costs off)
@@ -133,8 +129,6 @@ CREATE INDEX test_int4_h_a_idx ON test_int4_h_a USING rum
133129
(t rum_tsvector_hash_addon_ops, id)
134130
WITH (attach = 'id', to = 't', order_by_attach='t');
135131

136-
SET enable_bitmapscan=OFF;
137-
138132
EXPLAIN (costs off)
139133
SELECT count(*) FROM test_int4_h_a WHERE id < 400;
140134
SELECT count(*) FROM test_int4_h_a WHERE id < 400;

‎sql/int8.sql

+1-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ SELECT id FROM test_int8_o WHERE t @@ 'wr&qh' AND id >= 400::int8 ORDER BY id;
4040

4141
RESET enable_indexscan;
4242
RESET enable_indexonlyscan;
43-
RESET enable_bitmapscan;
4443
SET enable_seqscan = off;
4544

4645
EXPLAIN (costs off)
@@ -66,8 +65,6 @@ CREATE INDEX test_int8_a_idx ON test_int8_a USING rum
6665
(t rum_tsvector_addon_ops, id)
6766
WITH (attach = 'id', to = 't', order_by_attach='t');
6867

69-
SET enable_bitmapscan=OFF;
70-
7168
EXPLAIN (costs off)
7269
SELECT count(*) FROM test_int8_a WHERE id < 400::int8;
7370
SELECT count(*) FROM test_int8_a WHERE id < 400::int8;
@@ -107,7 +104,6 @@ SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id >= 400::int8 ORDER BY id
107104

108105
RESET enable_indexscan;
109106
RESET enable_indexonlyscan;
110-
RESET enable_bitmapscan;
111107
SET enable_seqscan = off;
112108

113109
EXPLAIN (costs off)
@@ -120,6 +116,7 @@ EXPLAIN (costs off)
120116
SELECT id, id |=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id |=> 400 LIMIT 5;
121117
SELECT id, id |=> 400 FROM test_int8_h_o WHERE t @@ 'wr&qh' ORDER BY id |=> 400 LIMIT 5;
122118

119+
123120
EXPLAIN (costs off)
124121
SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id <= 400::int8 ORDER BY id;
125122
SELECT id FROM test_int8_h_o WHERE t @@ 'wr&qh' AND id <= 400::int8 ORDER BY id;
@@ -133,8 +130,6 @@ CREATE INDEX test_int8_h_a_idx ON test_int8_h_a USING rum
133130
(t rum_tsvector_hash_addon_ops, id)
134131
WITH (attach = 'id', to = 't', order_by_attach='t');
135132

136-
SET enable_bitmapscan=OFF;
137-
138133
EXPLAIN (costs off)
139134
SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8;
140135
SELECT count(*) FROM test_int8_h_a WHERE id < 400::int8;

‎sql/rum.sql

+9
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,14 @@ SELECT (a <=> to_tsquery('pg_catalog.english', 'b:*'))::numeric(10,4) AS distanc
141141
WHERE a @@ to_tsquery('pg_catalog.english', 'b:*')
142142
ORDER BY a <=> to_tsquery('pg_catalog.english', 'b:*');
143143

144+
-- Test correct work of phrase operator when position information is not in index.
145+
create table test_rum_addon as table test_rum;
146+
alter table test_rum_addon add column id serial;
147+
create index on test_rum_addon using rum (a rum_tsvector_addon_ops, id) with (attach = 'id', to='a');
148+
149+
select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way');
150+
explain (costs off) select * from test_rum_addon where a @@ to_tsquery('pg_catalog.english', 'half <-> way');
151+
--
152+
144153
select ('bjarn:6237 stroustrup:6238'::tsvector <=> 'bjarn <-> stroustrup'::tsquery)::numeric(10,5) AS distance;
145154
SELECT ('stroustrup:5508B,6233B,6238B bjarn:6235B,6237B' <=> 'bjarn <-> stroustrup'::tsquery)::numeric(10,5) AS distance;

‎sql/security.sql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Check security CVE-2020-14350
2+
CREATE FUNCTION rum_anyarray_similar(anyarray,anyarray) RETURNS bool AS $$ SELECT false $$ LANGUAGE SQL;
3+
CREATE EXTENSION rum;
4+
DROP FUNCTION rum_anyarray_similar(anyarray,anyarray);
5+

‎src/rum_ts_utils.c

+18-9
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,15 @@ rum_tsquery_pre_consistent(PG_FUNCTION_ARGS)
244244
gcv.map_item_operand = (int *) (extra_data[0]);
245245
gcv.need_recheck = &recheck;
246246

247-
#if PG_VERSION_NUM >= 130000
248-
res = TS_execute(GETQUERY(query),
249-
&gcv,
250-
TS_EXEC_PHRASE_NO_POS | TS_EXEC_SKIP_NOT,
251-
pre_checkcondition_rum);
252-
#else
253247
res = TS_execute(GETQUERY(query),
254248
&gcv,
255-
TS_EXEC_PHRASE_NO_POS,
256-
pre_checkcondition_rum);
249+
TS_EXEC_PHRASE_NO_POS
250+
#if PG_VERSION_NUM >= 130000
251+
| TS_EXEC_SKIP_NOT
257252
#endif
253+
,
254+
pre_checkcondition_rum);
258255
}
259-
260256
PG_RETURN_BOOL(res);
261257
}
262258

@@ -604,6 +600,14 @@ rum_phrase_execute(QueryItem *curitem, void *arg, uint32 flags,
604600

605601
if (curitem->qoperator.oper == OP_PHRASE)
606602
{
603+
/* In case of index where position is not available
604+
* (e.g. addon_ops) output TS_MAYBE even in case both
605+
* lmatch and rmatch are TS_YES. Otherwise we can lose
606+
* results of phrase queries.
607+
*/
608+
if (flags & TS_EXEC_PHRASE_NO_POS)
609+
return TS_MAYBE;
610+
607611
/*
608612
* Compute Loffset and Roffset suitable for phrase match, and
609613
* compute overall width of whole phrase match.
@@ -840,6 +844,11 @@ rum_TS_execute(QueryItem *curitem, void *arg, uint32 flags,
840844
* converting at the topmost phrase operator gives results that
841845
* are bug-compatible with the old implementation, so do it like
842846
* this for now.
847+
*
848+
* Checking for TS_EXEC_PHRASE_NO_POS has been moved inside
849+
* rum_phrase_execute, otherwise we can lose results of phrase
850+
* operator when position information is not available in index
851+
* (e.g. index built with addon_ops)
843852
*/
844853
switch (rum_phrase_execute(curitem, arg, flags, chkcond, NULL))
845854
{

‎src/rumdatapage.c

+28-8
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ RumDataPageAddItem(Page page, void *data, OffsetNumber offset)
736736
if (offset <= maxoff)
737737
memmove(ptr + sizeof(PostingItem),
738738
ptr,
739-
((uint16_t)(maxoff - offset + 1)) * sizeof(PostingItem));
739+
((uint16)(maxoff - offset + 1)) * sizeof(PostingItem));
740740
}
741741
memcpy(ptr, data, sizeof(PostingItem));
742742
RumPageGetOpaque(page)->maxoff++;
@@ -763,7 +763,7 @@ RumPageDeletePostingItem(Page page, OffsetNumber offset)
763763
char *dstptr = RumDataPageGetItem(page, offset),
764764
*sourceptr = RumDataPageGetItem(page, offset + 1);
765765

766-
memmove(dstptr, sourceptr, sizeof(PostingItem) * (uint16_t)(maxoff - offset));
766+
memmove(dstptr, sourceptr, sizeof(PostingItem) * (uint16)(maxoff - offset));
767767
}
768768

769769
RumPageGetOpaque(page)->maxoff--;
@@ -853,7 +853,14 @@ dataPlaceToPage(RumBtree btree, Page page, OffsetNumber off)
853853
ItemPointerData iptr = {{0, 0}, 0};
854854
RumItem copyItem;
855855
bool copyItemEmpty = true;
856-
char pageCopy[BLCKSZ];
856+
/*
857+
* Must have pageCopy MAXALIGNed to use PG macros to access data in
858+
* it. Should not rely on compiler alignment preferences to avoid
859+
* pageCopy overflow related to PG in-memory page items alignment
860+
* inside rumDataPageLeafRead() or elsewhere.
861+
*/
862+
char pageCopyStorage[BLCKSZ + MAXIMUM_ALIGNOF];
863+
char *pageCopy = (char *) MAXALIGN(pageCopyStorage);
857864
int maxoff = RumPageGetOpaque(page)->maxoff;
858865
int freespace,
859866
insertCount = 0;
@@ -1055,7 +1062,14 @@ dataSplitPageLeaf(RumBtree btree, Buffer lbuf, Buffer rbuf,
10551062
RumItem item;
10561063
int totalCount = 0;
10571064
int maxItemIndex = btree->curitem;
1058-
static char lpageCopy[BLCKSZ];
1065+
/*
1066+
* Must have lpageCopy MAXALIGNed to use PG macros to access data in
1067+
* it. Should not rely on compiler alignment preferences to avoid
1068+
* lpageCopy overflow related to PG in-memory page items alignment
1069+
* inside rumDataPageLeafRead() etc.
1070+
*/
1071+
static char lpageCopyStorage[BLCKSZ + MAXIMUM_ALIGNOF];
1072+
char *lpageCopy = (char *) MAXALIGN(lpageCopyStorage);
10591073

10601074
memset(&item, 0, sizeof(item));
10611075
dataPrepareData(btree, newlPage, off);
@@ -1233,8 +1247,14 @@ dataSplitPageInternal(RumBtree btree, Buffer lbuf, Buffer rbuf,
12331247
OffsetNumber maxoff = RumPageGetOpaque(newlPage)->maxoff;
12341248
Size pageSize = PageGetPageSize(newlPage);
12351249
Size freeSpace;
1236-
1237-
static char vector[2 * BLCKSZ];
1250+
/*
1251+
* Must have vector MAXALIGNed to use PG macros to access data in
1252+
* it. Should not rely on compiler alignment preferences to avoid
1253+
* vector overflow related to PG in-memory page items alignment
1254+
* inside rumDataPageLeafRead() etc.
1255+
*/
1256+
static char vectorStorage[2 * BLCKSZ + MAXIMUM_ALIGNOF];
1257+
char *vector = (char *) MAXALIGN(vectorStorage);
12381258

12391259
RumInitPage(rPage, RumPageGetOpaque(newlPage)->flags, pageSize);
12401260
freeSpace = RumDataPageGetFreeSpace(rPage);
@@ -1246,7 +1266,7 @@ dataSplitPageInternal(RumBtree btree, Buffer lbuf, Buffer rbuf,
12461266
Assert(!RumPageIsLeaf(newlPage));
12471267
ptr = vector + (off - 1) * sizeofitem;
12481268
if (maxoff + 1 - off != 0)
1249-
memmove(ptr + sizeofitem, ptr, (uint16_t)(maxoff - off + 1) * sizeofitem);
1269+
memmove(ptr + sizeofitem, ptr, (uint16)(maxoff - off + 1) * sizeofitem);
12501270
memcpy(ptr, &(btree->pitem), sizeofitem);
12511271

12521272
maxoff++;
@@ -1273,7 +1293,7 @@ dataSplitPageInternal(RumBtree btree, Buffer lbuf, Buffer rbuf,
12731293

12741294
ptr = RumDataPageGetItem(rPage, FirstOffsetNumber);
12751295
memcpy(ptr, vector + separator * sizeofitem,
1276-
(uint16_t)(maxoff - separator) * sizeofitem);
1296+
(uint16)(maxoff - separator) * sizeofitem);
12771297
RumPageGetOpaque(rPage)->maxoff = maxoff - separator;
12781298
/* Adjust pd_lower */
12791299
((PageHeader) rPage)->pd_lower = (ptr +

‎src/rumentrypage.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,14 @@ entrySplitPage(RumBtree btree, Buffer lbuf, Buffer rbuf,
428428
Page page;
429429
Page newlPage = PageGetTempPageCopy(lPage);
430430
Size pageSize = PageGetPageSize(newlPage);
431-
432-
static char tupstore[2 * BLCKSZ];
431+
/*
432+
* Must have tupstore MAXALIGNed to use PG macros to access data in
433+
* it. Should not rely on compiler alignment preferences to avoid
434+
* tupstore overflow related to PG in-memory page items alignment
435+
* inside rumDataPageLeafRead() or elsewhere.
436+
*/
437+
static char tupstoreStorage[2 * BLCKSZ + MAXIMUM_ALIGNOF];
438+
char *tupstore = (char *) MAXALIGN(tupstoreStorage);
433439

434440
entryPreparePage(btree, newlPage, off);
435441

‎src/rumget.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ startScanEntry(RumState * rumstate, RumScanEntry entry, Snapshot snapshot)
687687
else if (RumGetNPosting(itup) > 0)
688688
{
689689
entry->nlist = RumGetNPosting(itup);
690-
entry->predictNumberResult = (uint32_t)entry->nlist;
690+
entry->predictNumberResult = (uint32)entry->nlist;
691691
entry->list = (RumItem *) palloc(sizeof(RumItem) * entry->nlist);
692692

693693
rumReadTuple(rumstate, entry->attnum, itup, entry->list, true);
@@ -1104,7 +1104,7 @@ entryGetNextItemList(RumState * rumstate, RumScanEntry entry, Snapshot snapshot)
11041104
else if (RumGetNPosting(itup) > 0)
11051105
{
11061106
entry->nlist = RumGetNPosting(itup);
1107-
entry->predictNumberResult = (uint32_t)entry->nlist;
1107+
entry->predictNumberResult = (uint32)entry->nlist;
11081108
entry->list = (RumItem *) palloc(sizeof(RumItem) * entry->nlist);
11091109

11101110
rumReadTuple(rumstate, entry->attnum, itup, entry->list, true);

‎t/001_wal.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ sub test_index_replay
2323
if ($server_version < 100000)
2424
{
2525
$caughtup_query =
26-
"SELECT pg_current_xlog_location() <= write_location FROM pg_stat_replication WHERE application_name = '$applname';";
26+
"SELECT pg_current_xlog_location() <= replay_location FROM pg_stat_replication WHERE application_name = '$applname';";
2727
}
2828
else
2929
{
3030
$caughtup_query =
31-
"SELECT pg_current_wal_lsn() <= write_lsn FROM pg_stat_replication WHERE application_name = '$applname';";
31+
"SELECT pg_current_wal_lsn() <= replay_lsn FROM pg_stat_replication WHERE application_name = '$applname';";
3232
}
3333
$node_master->poll_query_until('postgres', $caughtup_query)
3434
or die "Timed out while waiting for standby 1 to catch up";

0 commit comments

Comments
 (0)
Please sign in to comment.