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

Commitcc38651

Browse files
committed
Avoid trying to fetch metapage of an SPGist partitioned index.
This is necessary when spgcanreturn() is invoked on a partitionedindex, and the failure might be reachable in other scenarios aswell. The rest of what spgGetCache() does is perfectly sensiblefor a partitioned index, so we should allow it to go through.I think the main takeaway from this is that we lack sufficient testcoverage for non-btree partitioned indexes. Therefore, I addedsimple test cases for brin and gin as well as spgist (hash andgist AMs were covered already in indexing.sql).Per bug #18256 from Alexander Lakhin. Although the known test caseonly fails since v16 (3c56904), I've got no faith at all that therearen't other ways to reach this problem; so back-patch to allsupported branches.Discussion:https://postgr.es/m/18256-0b0e1b6e4a620f1b@postgresql.org
1 parent57d55e2 commitcc38651

File tree

3 files changed

+77
-11
lines changed

3 files changed

+77
-11
lines changed

‎src/backend/access/spgist/spgutils.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ spgGetCache(Relation index)
110110
Oidatttype;
111111
spgConfigInin;
112112
FmgrInfo*procinfo;
113-
Buffermetabuffer;
114-
SpGistMetaPageData*metadata;
115113

116114
cache=MemoryContextAllocZero(index->rd_indexcxt,
117115
sizeof(SpGistCache));
@@ -156,19 +154,28 @@ spgGetCache(Relation index)
156154
fillTypeDesc(&cache->attPrefixType,cache->config.prefixType);
157155
fillTypeDesc(&cache->attLabelType,cache->config.labelType);
158156

159-
/* Last, get the lastUsedPages data from the metapage */
160-
metabuffer=ReadBuffer(index,SPGIST_METAPAGE_BLKNO);
161-
LockBuffer(metabuffer,BUFFER_LOCK_SHARE);
157+
/*
158+
* Finally, if it's a real index (not a partitioned one), get the
159+
* lastUsedPages data from the metapage
160+
*/
161+
if (index->rd_rel->relkind!=RELKIND_PARTITIONED_INDEX)
162+
{
163+
Buffermetabuffer;
164+
SpGistMetaPageData*metadata;
165+
166+
metabuffer=ReadBuffer(index,SPGIST_METAPAGE_BLKNO);
167+
LockBuffer(metabuffer,BUFFER_LOCK_SHARE);
162168

163-
metadata=SpGistPageGetMeta(BufferGetPage(metabuffer));
169+
metadata=SpGistPageGetMeta(BufferGetPage(metabuffer));
164170

165-
if (metadata->magicNumber!=SPGIST_MAGIC_NUMBER)
166-
elog(ERROR,"index \"%s\" is not an SP-GiST index",
167-
RelationGetRelationName(index));
171+
if (metadata->magicNumber!=SPGIST_MAGIC_NUMBER)
172+
elog(ERROR,"index \"%s\" is not an SP-GiST index",
173+
RelationGetRelationName(index));
168174

169-
cache->lastUsedPages=metadata->lastUsedPages;
175+
cache->lastUsedPages=metadata->lastUsedPages;
170176

171-
UnlockReleaseBuffer(metabuffer);
177+
UnlockReleaseBuffer(metabuffer);
178+
}
172179

173180
index->rd_amcache= (void*)cache;
174181
}

‎src/test/regress/expected/indexing.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,45 @@ select tableoid::regclass, * from idxpart order by a;
12801280
idxpart2 | 857142 | six
12811281
(8 rows)
12821282

1283+
drop table idxpart;
1284+
-- Test some other non-btree index types
1285+
create table idxpart (a int, b text, c int[]) partition by range (a);
1286+
create table idxpart1 partition of idxpart for values from (0) to (100000);
1287+
set enable_seqscan to off;
1288+
create index idxpart_brin on idxpart using brin(b);
1289+
explain (costs off) select * from idxpart where b = 'abcd';
1290+
QUERY PLAN
1291+
-------------------------------------------
1292+
Bitmap Heap Scan on idxpart1 idxpart
1293+
Recheck Cond: (b = 'abcd'::text)
1294+
-> Bitmap Index Scan on idxpart1_b_idx
1295+
Index Cond: (b = 'abcd'::text)
1296+
(4 rows)
1297+
1298+
drop index idxpart_brin;
1299+
create index idxpart_spgist on idxpart using spgist(b);
1300+
explain (costs off) select * from idxpart where b = 'abcd';
1301+
QUERY PLAN
1302+
-------------------------------------------
1303+
Bitmap Heap Scan on idxpart1 idxpart
1304+
Recheck Cond: (b = 'abcd'::text)
1305+
-> Bitmap Index Scan on idxpart1_b_idx
1306+
Index Cond: (b = 'abcd'::text)
1307+
(4 rows)
1308+
1309+
drop index idxpart_spgist;
1310+
create index idxpart_gin on idxpart using gin(c);
1311+
explain (costs off) select * from idxpart where c @> array[42];
1312+
QUERY PLAN
1313+
----------------------------------------------
1314+
Bitmap Heap Scan on idxpart1 idxpart
1315+
Recheck Cond: (c @> '{42}'::integer[])
1316+
-> Bitmap Index Scan on idxpart1_c_idx
1317+
Index Cond: (c @> '{42}'::integer[])
1318+
(4 rows)
1319+
1320+
drop index idxpart_gin;
1321+
reset enable_seqscan;
12831322
drop table idxpart;
12841323
-- intentionally leave some objects around
12851324
create table idxpart (a int) partition by range (a);

‎src/test/regress/sql/indexing.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,26 @@ insert into idxpart values (857142, 'six');
668668
select tableoid::regclass,*from idxpartorder by a;
669669
droptable idxpart;
670670

671+
-- Test some other non-btree index types
672+
createtableidxpart (aint, btext, cint[]) partition by range (a);
673+
createtableidxpart1 partition of idxpart forvaluesfrom (0) to (100000);
674+
set enable_seqscan to off;
675+
676+
createindexidxpart_brinon idxpart using brin(b);
677+
explain (costs off)select*from idxpartwhere b='abcd';
678+
dropindex idxpart_brin;
679+
680+
createindexidxpart_spgiston idxpart using spgist(b);
681+
explain (costs off)select*from idxpartwhere b='abcd';
682+
dropindex idxpart_spgist;
683+
684+
createindexidxpart_ginon idxpart using gin(c);
685+
explain (costs off)select*from idxpartwhere c @> array[42];
686+
dropindex idxpart_gin;
687+
688+
reset enable_seqscan;
689+
droptable idxpart;
690+
671691
-- intentionally leave some objects around
672692
createtableidxpart (aint) partition by range (a);
673693
createtableidxpart1 partition of idxpart forvaluesfrom (0) to (100);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp