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

Commit8a3f745

Browse files
committed
Do not access indclass through Form_pg_index
Normally, accessing variable-length members of catalog structures pastthe first one doesn't work at all. Here, it happened to work becauseindnatts was checked to be 1, and so the defined FormData_pg_indexlayout, using int2vector[1] and oidvector[1] for variable-lengtharrays, happened to match the actual memory layout. But it's a veryfragile assumption, and it's not in a performance-critical path, socode it properly using heap_getattr() instead.bug analysis by Tom Lane
1 parenteb6af01 commit8a3f745

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎src/backend/utils/cache/relcache.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3351,15 +3351,30 @@ RelationGetIndexList(Relation relation)
33513351
while (HeapTupleIsValid(htup=systable_getnext(indscan)))
33523352
{
33533353
Form_pg_indexindex= (Form_pg_index)GETSTRUCT(htup);
3354+
DatumindclassDatum;
3355+
oidvector*indclass;
3356+
boolisnull;
33543357

33553358
/* Add index's OID to result list in the proper order */
33563359
result=insert_ordered_oid(result,index->indexrelid);
33573360

3361+
/*
3362+
* indclass cannot be referenced directly through the C struct, because
3363+
* it comes after the variable-width indkey field. Must extract the
3364+
* datum the hard way...
3365+
*/
3366+
indclassDatum=heap_getattr(htup,
3367+
Anum_pg_index_indclass,
3368+
GetPgIndexDescriptor(),
3369+
&isnull);
3370+
Assert(!isnull);
3371+
indclass= (oidvector*)DatumGetPointer(indclassDatum);
3372+
33583373
/* Check to see if it is a unique, non-partial btree index on OID */
33593374
if (index->indnatts==1&&
33603375
index->indisunique&&index->indimmediate&&
33613376
index->indkey.values[0]==ObjectIdAttributeNumber&&
3362-
index->indclass.values[0]==OID_BTREE_OPS_OID&&
3377+
indclass->values[0]==OID_BTREE_OPS_OID&&
33633378
heap_attisnull(htup,Anum_pg_index_indpred))
33643379
oidIndex=index->indexrelid;
33653380
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp