Skip to content

Commit 367b99b

Browse files
committed
Fix gin_leafpage_items().
On closer inspection, commit 84ad68d broke gin_leafpage_items(), because the aligned copy of the page got palloc'd in a short-lived context whereas it needs to be in the SRF's multi_call_memory_ctx. This was not exposed by the regression test, because the regression test doesn't actually exercise the function in a meaningful way. Fix the code bug, and extend the test in what I hope is a portable fashion.
1 parent 927d7bb commit 367b99b

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

contrib/pageinspect/expected/gin.out

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE test1 (x int, y int[]);
22
INSERT INTO test1 VALUES (1, ARRAY[11, 111]);
3-
CREATE INDEX test1_y_idx ON test1 USING gin (y);
3+
CREATE INDEX test1_y_idx ON test1 USING gin (y) WITH (fastupdate = off);
44
\x
55
SELECT * FROM gin_metapage_info(get_raw_page('test1_y_idx', 0));
66
-[ RECORD 1 ]----+-----------
@@ -27,4 +27,11 @@ flags | {leaf}
2727
SELECT * FROM gin_leafpage_items(get_raw_page('test1_y_idx', 1));
2828
ERROR: input page is not a compressed GIN data leaf page
2929
DETAIL: Flags 0002, expected 0083
30-
DROP TABLE test1;
30+
INSERT INTO test1 SELECT x, ARRAY[1,10] FROM generate_series(2,10000) x;
31+
SELECT COUNT(*) > 0
32+
FROM gin_leafpage_items(get_raw_page('test1_y_idx',
33+
(pg_relation_size('test1_y_idx') /
34+
current_setting('block_size')::bigint)::int - 1));
35+
-[ RECORD 1 ]
36+
?column? | t
37+

contrib/pageinspect/ginfuncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
197197
Page page;
198198
GinPageOpaque opaq;
199199

200+
fctx = SRF_FIRSTCALL_INIT();
201+
mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
202+
200203
page = get_page_from_raw(raw_page);
201204

202205
if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GinPageOpaqueData)))
@@ -216,9 +219,6 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
216219
opaq->flags,
217220
(GIN_DATA | GIN_LEAF | GIN_COMPRESSED))));
218221

219-
fctx = SRF_FIRSTCALL_INIT();
220-
mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
221-
222222
inter_call_data = palloc(sizeof(gin_leafpage_items_state));
223223

224224
/* Build a tuple descriptor for our result type */

contrib/pageinspect/sql/gin.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE test1 (x int, y int[]);
22
INSERT INTO test1 VALUES (1, ARRAY[11, 111]);
3-
CREATE INDEX test1_y_idx ON test1 USING gin (y);
3+
CREATE INDEX test1_y_idx ON test1 USING gin (y) WITH (fastupdate = off);
44

55
\x
66

@@ -11,4 +11,9 @@ SELECT * FROM gin_page_opaque_info(get_raw_page('test1_y_idx', 1));
1111

1212
SELECT * FROM gin_leafpage_items(get_raw_page('test1_y_idx', 1));
1313

14-
DROP TABLE test1;
14+
INSERT INTO test1 SELECT x, ARRAY[1,10] FROM generate_series(2,10000) x;
15+
16+
SELECT COUNT(*) > 0
17+
FROM gin_leafpage_items(get_raw_page('test1_y_idx',
18+
(pg_relation_size('test1_y_idx') /
19+
current_setting('block_size')::bigint)::int - 1));

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