Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit367b99b

Browse files
committed
Fix gin_leafpage_items().
On closer inspection, commit84ad68d broke gin_leafpage_items(),because the aligned copy of the page got palloc'd in a short-livedcontext whereas it needs to be in the SRF's multi_call_memory_ctx.This was not exposed by the regression test, because the regressiontest doesn't actually exercise the function in a meaningful way.Fix the code bug, and extend the test in what I hope is a portablefashion.
1 parent927d7bb commit367b99b

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
Pagepage;
198198
GinPageOpaqueopaq;
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
CREATETABLEtest1 (xint, yint[]);
22
INSERT INTO test1VALUES (1, ARRAY[11,111]);
3-
CREATEINDEXtest1_y_idxON test1 USING gin (y);
3+
CREATEINDEXtest1_y_idxON 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-
DROPTABLE test1;
14+
INSERT INTO test1SELECT x, ARRAY[1,10]FROM generate_series(2,10000) x;
15+
16+
SELECTCOUNT(*)>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)

[8]ページ先頭

©2009-2025 Movatter.jp