Handle sequence metadata access changes

Sequences used to have a pretty weird representation: C code could read
their attributes by loading the single tuple stored in their relation.

Now each sequence has a corresponding tuple in pg_sequence, and there
are syscache entries for each, meaning we can (and must) use syscache
methods to look up attributes for sequences.
pull/1439/head
Jason Petersen 2017-04-20 21:48:35 -06:00
parent 6fbfe33c51
commit aba4f2eff3
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
1 changed files with 14 additions and 1 deletions

View File

@ -210,8 +210,20 @@ Form_pg_sequence
pg_get_sequencedef(Oid sequenceRelationId)
{
Form_pg_sequence pgSequenceForm = NULL;
SysScanDesc scanDescriptor = NULL;
HeapTuple heapTuple = NULL;
#if (PG_VERSION_NUM >= 100000)
heapTuple = SearchSysCache1(SEQRELID, sequenceRelationId);
if (!HeapTupleIsValid(heapTuple))
{
elog(ERROR, "cache lookup failed for sequence %u", sequenceRelationId);
}
pgSequenceForm = (Form_pg_sequence) GETSTRUCT(heapTuple);
ReleaseSysCache(heapTuple);
#else
SysScanDesc scanDescriptor = NULL;
Relation sequenceRel = NULL;
AclResult permissionCheck = ACLCHECK_NO_PRIV;
@ -241,6 +253,7 @@ pg_get_sequencedef(Oid sequenceRelationId)
systable_endscan(scanDescriptor);
heap_close(sequenceRel, AccessShareLock);
#endif
return pgSequenceForm;
}