summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r--src/backend/utils/cache/catcache.c86
-rw-r--r--src/backend/utils/cache/inval.c4
-rw-r--r--src/backend/utils/cache/lsyscache.c4
-rw-r--r--src/backend/utils/cache/plancache.c4
-rw-r--r--src/backend/utils/cache/relcache.c125
-rw-r--r--src/backend/utils/cache/relfilenodemap.c22
-rw-r--r--src/backend/utils/cache/syscache.c71
-rw-r--r--src/backend/utils/cache/typcache.c2
8 files changed, 113 insertions, 205 deletions
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 5ddbf6eab10..b31fd5acea7 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -338,39 +338,31 @@ CatalogCacheComputeTupleHashValue(CatCache *cache, int nkeys, HeapTuple tuple)
switch (nkeys)
{
case 4:
- v4 = (cc_keyno[3] == ObjectIdAttributeNumber)
- ? ObjectIdGetDatum(HeapTupleGetOid(tuple))
- : fastgetattr(tuple,
- cc_keyno[3],
- cc_tupdesc,
- &isNull);
+ v4 = fastgetattr(tuple,
+ cc_keyno[3],
+ cc_tupdesc,
+ &isNull);
Assert(!isNull);
/* FALLTHROUGH */
case 3:
- v3 = (cc_keyno[2] == ObjectIdAttributeNumber)
- ? ObjectIdGetDatum(HeapTupleGetOid(tuple))
- : fastgetattr(tuple,
- cc_keyno[2],
- cc_tupdesc,
- &isNull);
+ v3 = fastgetattr(tuple,
+ cc_keyno[2],
+ cc_tupdesc,
+ &isNull);
Assert(!isNull);
/* FALLTHROUGH */
case 2:
- v2 = (cc_keyno[1] == ObjectIdAttributeNumber)
- ? ObjectIdGetDatum(HeapTupleGetOid(tuple))
- : fastgetattr(tuple,
- cc_keyno[1],
- cc_tupdesc,
- &isNull);
+ v2 = fastgetattr(tuple,
+ cc_keyno[1],
+ cc_tupdesc,
+ &isNull);
Assert(!isNull);
/* FALLTHROUGH */
case 1:
- v1 = (cc_keyno[0] == ObjectIdAttributeNumber)
- ? ObjectIdGetDatum(HeapTupleGetOid(tuple))
- : fastgetattr(tuple,
- cc_keyno[0],
- cc_tupdesc,
- &isNull);
+ v1 = fastgetattr(tuple,
+ cc_keyno[0],
+ cc_tupdesc,
+ &isNull);
Assert(!isNull);
break;
default:
@@ -998,8 +990,8 @@ CatalogCacheInitializeCache(CatCache *cache)
}
else
{
- if (cache->cc_keyno[i] != ObjectIdAttributeNumber)
- elog(FATAL, "only sys attr supported in caches is OID");
+ if (cache->cc_keyno[i] < 0)
+ elog(FATAL, "sys attributes are not supported in caches");
keytype = OIDOID;
}
@@ -1935,9 +1927,7 @@ CatCacheFreeKeys(TupleDesc tupdesc, int nkeys, int *attnos, Datum *keys)
int attnum = attnos[i];
Form_pg_attribute att;
- /* only valid system attribute is the oid, which is by value */
- if (attnum == ObjectIdAttributeNumber)
- continue;
+ /* system attribute are not supported in caches */
Assert(attnum > 0);
att = TupleDescAttr(tupdesc, attnum - 1);
@@ -1966,33 +1956,25 @@ CatCacheCopyKeys(TupleDesc tupdesc, int nkeys, int *attnos,
for (i = 0; i < nkeys; i++)
{
int attnum = attnos[i];
+ Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1);
+ Datum src = srckeys[i];
+ NameData srcname;
- if (attnum == ObjectIdAttributeNumber)
+ /*
+ * Must be careful in case the caller passed a C string where a
+ * NAME is wanted: convert the given argument to a correctly
+ * padded NAME. Otherwise the memcpy() done by datumCopy() could
+ * fall off the end of memory.
+ */
+ if (att->atttypid == NAMEOID)
{
- dstkeys[i] = srckeys[i];
+ namestrcpy(&srcname, DatumGetCString(src));
+ src = NameGetDatum(&srcname);
}
- else
- {
- Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1);
- Datum src = srckeys[i];
- NameData srcname;
- /*
- * Must be careful in case the caller passed a C string where a
- * NAME is wanted: convert the given argument to a correctly
- * padded NAME. Otherwise the memcpy() done by datumCopy() could
- * fall off the end of memory.
- */
- if (att->atttypid == NAMEOID)
- {
- namestrcpy(&srcname, DatumGetCString(src));
- src = NameGetDatum(&srcname);
- }
-
- dstkeys[i] = datumCopy(src,
- att->attbyval,
- att->attlen);
- }
+ dstkeys[i] = datumCopy(src,
+ att->attbyval,
+ att->attlen);
}
}
diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c
index f3ded4def90..51574937959 100644
--- a/src/backend/utils/cache/inval.c
+++ b/src/backend/utils/cache/inval.c
@@ -1166,7 +1166,7 @@ CacheInvalidateHeapTuple(Relation relation,
{
Form_pg_class classtup = (Form_pg_class) GETSTRUCT(tuple);
- relationId = HeapTupleGetOid(tuple);
+ relationId = classtup->oid;
if (classtup->relisshared)
databaseId = InvalidOid;
else
@@ -1292,7 +1292,7 @@ CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
PrepareInvalidationState();
- relationId = HeapTupleGetOid(classTuple);
+ relationId = classtup->oid;
if (classtup->relisshared)
databaseId = InvalidOid;
else
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 892ddc0d486..7a263cc1fdc 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -1653,7 +1653,7 @@ get_func_rows(Oid funcid)
Oid
get_relname_relid(const char *relname, Oid relnamespace)
{
- return GetSysCacheOid2(RELNAMENSP,
+ return GetSysCacheOid2(RELNAMENSP, Anum_pg_class_oid,
PointerGetDatum(relname),
ObjectIdGetDatum(relnamespace));
}
@@ -2056,7 +2056,7 @@ getTypeIOParam(HeapTuple typeTuple)
if (OidIsValid(typeStruct->typelem))
return typeStruct->typelem;
else
- return HeapTupleGetOid(typeTuple);
+ return typeStruct->oid;
}
/*
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index fc7e8dbe269..9ec81c5f367 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -1663,12 +1663,12 @@ PlanCacheComputeResultDesc(List *stmt_list)
case PORTAL_ONE_SELECT:
case PORTAL_ONE_MOD_WITH:
query = linitial_node(Query, stmt_list);
- return ExecCleanTypeFromTL(query->targetList, false);
+ return ExecCleanTypeFromTL(query->targetList);
case PORTAL_ONE_RETURNING:
query = QueryListGetPrimaryStmt(stmt_list);
Assert(query->returningList);
- return ExecCleanTypeFromTL(query->returningList, false);
+ return ExecCleanTypeFromTL(query->returningList);
case PORTAL_UTIL_SELECT:
query = linitial_node(Query, stmt_list);
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index aecbd4a9437..c3071db1cdf 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -261,8 +261,7 @@ static void write_relcache_init_file(bool shared);
static void write_item(const void *data, Size len, FILE *fp);
static void formrdesc(const char *relationName, Oid relationReltype,
- bool isshared, bool hasoids,
- int natts, const FormData_pg_attribute *attrs);
+ bool isshared, int natts, const FormData_pg_attribute *attrs);
static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic);
static Relation AllocateRelationDesc(Form_pg_class relp);
@@ -328,7 +327,7 @@ ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic)
* form a scan key
*/
ScanKeyInit(&key[0],
- ObjectIdAttributeNumber,
+ Anum_pg_class_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(targetRelId));
@@ -414,8 +413,7 @@ AllocateRelationDesc(Form_pg_class relp)
relation->rd_rel = relationForm;
/* and allocate attribute tuple form storage */
- relation->rd_att = CreateTemplateTupleDesc(relationForm->relnatts,
- relationForm->relhasoids);
+ relation->rd_att = CreateTemplateTupleDesc(relationForm->relnatts);
/* which we mark as a reference-counted tupdesc */
relation->rd_att->tdrefcount = 1;
@@ -505,7 +503,6 @@ RelationBuildTupleDesc(Relation relation)
/* copy some fields from pg_class row to rd_att */
relation->rd_att->tdtypeid = relation->rd_rel->reltype;
relation->rd_att->tdtypmod = -1; /* unnecessary, but... */
- relation->rd_att->tdhasoid = relation->rd_rel->relhasoids;
constr = (TupleConstr *) MemoryContextAlloc(CacheMemoryContext,
sizeof(TupleConstr));
@@ -789,7 +786,7 @@ RelationBuildRuleLock(Relation relation)
rule = (RewriteRule *) MemoryContextAlloc(rulescxt,
sizeof(RewriteRule));
- rule->ruleId = HeapTupleGetOid(rewrite_tuple);
+ rule->ruleId = rewrite_form->oid;
rule->event = rewrite_form->ev_type - '0';
rule->enabled = rewrite_form->ev_enabled;
@@ -1090,8 +1087,8 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
/*
* get information from the pg_class_tuple
*/
- relid = HeapTupleGetOid(pg_class_tuple);
relp = (Form_pg_class) GETSTRUCT(pg_class_tuple);
+ relid = relp->oid;
Assert(relid == targetRelId);
/*
@@ -1641,7 +1638,7 @@ LookupOpclassInfo(Oid operatorClassOid,
* work while bootstrapping.
*/
ScanKeyInit(&skey[0],
- ObjectIdAttributeNumber,
+ Anum_pg_opclass_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(operatorClassOid));
rel = heap_open(OperatorClassRelationId, AccessShareLock);
@@ -1725,7 +1722,7 @@ LookupOpclassInfo(Oid operatorClassOid,
*/
static void
formrdesc(const char *relationName, Oid relationReltype,
- bool isshared, bool hasoids,
+ bool isshared,
int natts, const FormData_pg_attribute *attrs)
{
Relation relation;
@@ -1789,7 +1786,6 @@ formrdesc(const char *relationName, Oid relationReltype,
relation->rd_rel->reltuples = 0;
relation->rd_rel->relallvisible = 0;
relation->rd_rel->relkind = RELKIND_RELATION;
- relation->rd_rel->relhasoids = hasoids;
relation->rd_rel->relnatts = (int16) natts;
/*
@@ -1799,7 +1795,7 @@ formrdesc(const char *relationName, Oid relationReltype,
* because it will never be replaced. The data comes from
* src/include/catalog/ headers via genbki.pl.
*/
- relation->rd_att = CreateTemplateTupleDesc(natts, hasoids);
+ relation->rd_att = CreateTemplateTupleDesc(natts);
relation->rd_att->tdrefcount = 1; /* mark as refcounted */
relation->rd_att->tdtypeid = relationReltype;
@@ -2964,7 +2960,6 @@ AtEOXact_cleanup(Relation relation, bool isCommit)
{
list_free(relation->rd_indexlist);
relation->rd_indexlist = NIL;
- relation->rd_oidindex = InvalidOid;
relation->rd_pkindex = InvalidOid;
relation->rd_replidindex = InvalidOid;
relation->rd_indexvalid = 0;
@@ -3077,7 +3072,6 @@ AtEOSubXact_cleanup(Relation relation, bool isCommit,
{
list_free(relation->rd_indexlist);
relation->rd_indexlist = NIL;
- relation->rd_oidindex = InvalidOid;
relation->rd_pkindex = InvalidOid;
relation->rd_replidindex = InvalidOid;
relation->rd_indexvalid = 0;
@@ -3208,7 +3202,6 @@ RelationBuildLocalRelation(const char *relname,
rel->rd_rel->relnamespace = relnamespace;
rel->rd_rel->relkind = relkind;
- rel->rd_rel->relhasoids = rel->rd_att->tdhasoid;
rel->rd_rel->relnatts = natts;
rel->rd_rel->reltype = InvalidOid;
/* needed when bootstrapping: */
@@ -3508,15 +3501,15 @@ RelationCacheInitializePhase2(void)
if (!load_relcache_init_file(true))
{
formrdesc("pg_database", DatabaseRelation_Rowtype_Id, true,
- true, Natts_pg_database, Desc_pg_database);
+ Natts_pg_database, Desc_pg_database);
formrdesc("pg_authid", AuthIdRelation_Rowtype_Id, true,
- true, Natts_pg_authid, Desc_pg_authid);
+ Natts_pg_authid, Desc_pg_authid);
formrdesc("pg_auth_members", AuthMemRelation_Rowtype_Id, true,
- false, Natts_pg_auth_members, Desc_pg_auth_members);
+ Natts_pg_auth_members, Desc_pg_auth_members);
formrdesc("pg_shseclabel", SharedSecLabelRelation_Rowtype_Id, true,
- false, Natts_pg_shseclabel, Desc_pg_shseclabel);
+ Natts_pg_shseclabel, Desc_pg_shseclabel);
formrdesc("pg_subscription", SubscriptionRelation_Rowtype_Id, true,
- true, Natts_pg_subscription, Desc_pg_subscription);
+ Natts_pg_subscription, Desc_pg_subscription);
#define NUM_CRITICAL_SHARED_RELS 5 /* fix if you change list above */
}
@@ -3567,13 +3560,13 @@ RelationCacheInitializePhase3(void)
needNewCacheFile = true;
formrdesc("pg_class", RelationRelation_Rowtype_Id, false,
- true, Natts_pg_class, Desc_pg_class);
+ Natts_pg_class, Desc_pg_class);
formrdesc("pg_attribute", AttributeRelation_Rowtype_Id, false,
- false, Natts_pg_attribute, Desc_pg_attribute);
+ Natts_pg_attribute, Desc_pg_attribute);
formrdesc("pg_proc", ProcedureRelation_Rowtype_Id, false,
- true, Natts_pg_proc, Desc_pg_proc);
+ Natts_pg_proc, Desc_pg_proc);
formrdesc("pg_type", TypeRelation_Rowtype_Id, false,
- true, Natts_pg_type, Desc_pg_type);
+ Natts_pg_type, Desc_pg_type);
#define NUM_CRITICAL_LOCAL_RELS 4 /* fix if you change list above */
}
@@ -3725,7 +3718,6 @@ RelationCacheInitializePhase3(void)
*/
Assert(relation->rd_att->tdtypeid == relp->reltype);
Assert(relation->rd_att->tdtypmod == -1);
- Assert(relation->rd_att->tdhasoid == relp->relhasoids);
ReleaseSysCache(htup);
@@ -3868,8 +3860,7 @@ load_critical_index(Oid indexoid, Oid heapoid)
* extracting fields.
*/
static TupleDesc
-BuildHardcodedDescriptor(int natts, const FormData_pg_attribute *attrs,
- bool hasoids)
+BuildHardcodedDescriptor(int natts, const FormData_pg_attribute *attrs)
{
TupleDesc result;
MemoryContext oldcxt;
@@ -3877,7 +3868,7 @@ BuildHardcodedDescriptor(int natts, const FormData_pg_attribute *attrs,
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
- result = CreateTemplateTupleDesc(natts, hasoids);
+ result = CreateTemplateTupleDesc(natts);
result->tdtypeid = RECORDOID; /* not right, but we don't care */
result->tdtypmod = -1;
@@ -3906,8 +3897,7 @@ GetPgClassDescriptor(void)
/* Already done? */
if (pgclassdesc == NULL)
pgclassdesc = BuildHardcodedDescriptor(Natts_pg_class,
- Desc_pg_class,
- true);
+ Desc_pg_class);
return pgclassdesc;
}
@@ -3920,8 +3910,7 @@ GetPgIndexDescriptor(void)
/* Already done? */
if (pgindexdesc == NULL)
pgindexdesc = BuildHardcodedDescriptor(Natts_pg_index,
- Desc_pg_index,
- false);
+ Desc_pg_index);
return pgindexdesc;
}
@@ -4145,7 +4134,7 @@ RelationGetFKeyList(Relation relation)
continue;
info = makeNode(ForeignKeyCacheInfo);
- info->conoid = HeapTupleGetOid(htup);
+ info->conoid = constraint->oid;
info->conrelid = constraint->conrelid;
info->confrelid = constraint->confrelid;
@@ -4248,11 +4237,6 @@ RelationGetFKeyList(Relation relation)
* since the caller will typically be doing syscache lookups on the relevant
* indexes, and syscache lookup could cause SI messages to be processed!
*
- * We also update rd_oidindex, which this module treats as effectively part
- * of the index list. rd_oidindex is valid when rd_indexvalid isn't zero;
- * it is the pg_class OID of a unique index on OID when the relation has one,
- * and InvalidOid if there is no such index.
- *
* In exactly the same way, we update rd_pkindex, which is the OID of the
* relation's primary key index if any, else InvalidOid; and rd_replidindex,
* which is the pg_class OID of an index to be used as the relation's
@@ -4268,7 +4252,6 @@ RelationGetIndexList(Relation relation)
List *result;
List *oldlist;
char replident = relation->rd_rel->relreplident;
- Oid oidIndex = InvalidOid;
Oid pkeyIndex = InvalidOid;
Oid candidateIndex = InvalidOid;
MemoryContext oldcxt;
@@ -4284,7 +4267,6 @@ RelationGetIndexList(Relation relation)
* if we get some sort of error partway through.
*/
result = NIL;
- oidIndex = InvalidOid;
/* Prepare to scan pg_index for entries having indrelid = this rel. */
ScanKeyInit(&skey,
@@ -4299,9 +4281,6 @@ RelationGetIndexList(Relation relation)
while (HeapTupleIsValid(htup = systable_getnext(indscan)))
{
Form_pg_index index = (Form_pg_index) GETSTRUCT(htup);
- Datum indclassDatum;
- oidvector *indclass;
- bool isnull;
/*
* Ignore any indexes that are currently being dropped. This will
@@ -4316,18 +4295,6 @@ RelationGetIndexList(Relation relation)
result = insert_ordered_oid(result, index->indexrelid);
/*
- * indclass cannot be referenced directly through the C struct,
- * because it comes after the variable-width indkey field. Must
- * extract the datum the hard way...
- */
- indclassDatum = heap_getattr(htup,
- Anum_pg_index_indclass,
- GetPgIndexDescriptor(),
- &isnull);
- Assert(!isnull);
- indclass = (oidvector *) DatumGetPointer(indclassDatum);
-
- /*
* Invalid, non-unique, non-immediate or predicate indexes aren't
* interesting for either oid indexes or replication identity indexes,
* so don't check them.
@@ -4337,12 +4304,6 @@ RelationGetIndexList(Relation relation)
!heap_attisnull(htup, Anum_pg_index_indpred, NULL))
continue;
- /* Check to see if is a usable btree index on OID */
- if (index->indnatts == 1 &&
- index->indkey.values[0] == ObjectIdAttributeNumber &&
- indclass->values[0] == OID_BTREE_OPS_OID)
- oidIndex = index->indexrelid;
-
/* remember primary key index if any */
if (index->indisprimary)
pkeyIndex = index->indexrelid;
@@ -4360,7 +4321,6 @@ RelationGetIndexList(Relation relation)
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
oldlist = relation->rd_indexlist;
relation->rd_indexlist = list_copy(result);
- relation->rd_oidindex = oidIndex;
relation->rd_pkindex = pkeyIndex;
if (replident == REPLICA_IDENTITY_DEFAULT && OidIsValid(pkeyIndex))
relation->rd_replidindex = pkeyIndex;
@@ -4435,7 +4395,11 @@ RelationGetStatExtList(Relation relation)
NULL, 1, &skey);
while (HeapTupleIsValid(htup = systable_getnext(indscan)))
- result = insert_ordered_oid(result, HeapTupleGetOid(htup));
+ {
+ Oid oid = ((Form_pg_statistic_ext) GETSTRUCT(htup))->oid;
+
+ result = insert_ordered_oid(result, oid);
+ }
systable_endscan(indscan);
@@ -4510,7 +4474,7 @@ insert_ordered_oid(List *list, Oid datum)
* touch rd_keyattr, rd_pkattr or rd_idattr.
*/
void
-RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex)
+RelationSetIndexList(Relation relation, List *indexIds)
{
MemoryContext oldcxt;
@@ -4522,7 +4486,6 @@ RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex)
/* Okay to replace old list */
list_free(relation->rd_indexlist);
relation->rd_indexlist = indexIds;
- relation->rd_oidindex = oidIndex;
/*
* For the moment, assume the target rel hasn't got a pk or replica index.
@@ -4536,34 +4499,6 @@ RelationSetIndexList(Relation relation, List *indexIds, Oid oidIndex)
}
/*
- * RelationGetOidIndex -- get the pg_class OID of the relation's OID index
- *
- * Returns InvalidOid if there is no such index.
- */
-Oid
-RelationGetOidIndex(Relation relation)
-{
- List *ilist;
-
- /*
- * If relation doesn't have OIDs at all, caller is probably confused. (We
- * could just silently return InvalidOid, but it seems better to throw an
- * assertion.)
- */
- Assert(relation->rd_rel->relhasoids);
-
- if (relation->rd_indexvalid == 0)
- {
- /* RelationGetIndexList does the heavy lifting. */
- ilist = RelationGetIndexList(relation);
- list_free(ilist);
- Assert(relation->rd_indexvalid != 0);
- }
-
- return relation->rd_oidindex;
-}
-
-/*
* RelationGetPrimaryKeyIndex -- get OID of the relation's primary key index
*
* Returns InvalidOid if there is no such index.
@@ -5472,8 +5407,7 @@ load_relcache_init_file(bool shared)
rel->rd_rel = relform;
/* initialize attribute tuple forms */
- rel->rd_att = CreateTemplateTupleDesc(relform->relnatts,
- relform->relhasoids);
+ rel->rd_att = CreateTemplateTupleDesc(relform->relnatts);
rel->rd_att->tdrefcount = 1; /* mark as refcounted */
rel->rd_att->tdtypeid = relform->reltype;
@@ -5677,7 +5611,6 @@ load_relcache_init_file(bool shared)
rel->rd_fkeylist = NIL;
rel->rd_fkeyvalid = false;
rel->rd_indexlist = NIL;
- rel->rd_oidindex = InvalidOid;
rel->rd_pkindex = InvalidOid;
rel->rd_replidindex = InvalidOid;
rel->rd_indexattr = NULL;
diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenodemap.c
index 34679725b3d..74c4636895f 100644
--- a/src/backend/utils/cache/relfilenodemap.c
+++ b/src/backend/utils/cache/relfilenodemap.c
@@ -212,29 +212,17 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode)
while (HeapTupleIsValid(ntp = systable_getnext(scandesc)))
{
+ Form_pg_class classform = (Form_pg_class) GETSTRUCT(ntp);
+
if (found)
elog(ERROR,
"unexpected duplicate for tablespace %u, relfilenode %u",
reltablespace, relfilenode);
found = true;
-#ifdef USE_ASSERT_CHECKING
- {
- bool isnull;
- Oid check;
-
- check = fastgetattr(ntp, Anum_pg_class_reltablespace,
- RelationGetDescr(relation),
- &isnull);
- Assert(!isnull && check == reltablespace);
-
- check = fastgetattr(ntp, Anum_pg_class_relfilenode,
- RelationGetDescr(relation),
- &isnull);
- Assert(!isnull && check == relfilenode);
- }
-#endif
- relid = HeapTupleGetOid(ntp);
+ Assert(classform->reltablespace == reltablespace);
+ Assert(classform->relfilenode == relfilenode);
+ relid = classform->oid;
}
systable_endscan(scandesc);
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c
index 2b381782a32..c26808a8334 100644
--- a/src/backend/utils/cache/syscache.c
+++ b/src/backend/utils/cache/syscache.c
@@ -147,7 +147,7 @@ static const struct cachedesc cacheinfo[] = {
AmOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_am_oid,
0,
0,
0
@@ -246,7 +246,7 @@ static const struct cachedesc cacheinfo[] = {
AuthIdOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_authid_oid,
0,
0,
0
@@ -280,7 +280,7 @@ static const struct cachedesc cacheinfo[] = {
OpclassOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_opclass_oid,
0,
0,
0
@@ -302,7 +302,7 @@ static const struct cachedesc cacheinfo[] = {
CollationOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_collation_oid,
0,
0,
0
@@ -316,7 +316,7 @@ static const struct cachedesc cacheinfo[] = {
Anum_pg_conversion_connamespace,
Anum_pg_conversion_conforencoding,
Anum_pg_conversion_contoencoding,
- ObjectIdAttributeNumber,
+ Anum_pg_conversion_oid
},
8
},
@@ -335,7 +335,7 @@ static const struct cachedesc cacheinfo[] = {
ConstraintOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_constraint_oid,
0,
0,
0
@@ -346,7 +346,7 @@ static const struct cachedesc cacheinfo[] = {
ConversionOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_conversion_oid,
0,
0,
0
@@ -357,7 +357,7 @@ static const struct cachedesc cacheinfo[] = {
DatabaseOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_database_oid,
0,
0,
0
@@ -379,7 +379,7 @@ static const struct cachedesc cacheinfo[] = {
EnumOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_enum_oid,
0,
0,
0
@@ -412,7 +412,7 @@ static const struct cachedesc cacheinfo[] = {
EventTriggerOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_event_trigger_oid,
0,
0,
0
@@ -434,7 +434,7 @@ static const struct cachedesc cacheinfo[] = {
ForeignDataWrapperOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_foreign_data_wrapper_oid,
0,
0,
0
@@ -456,7 +456,7 @@ static const struct cachedesc cacheinfo[] = {
ForeignServerOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_foreign_server_oid,
0,
0,
0
@@ -500,7 +500,7 @@ static const struct cachedesc cacheinfo[] = {
LanguageOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_language_oid,
0,
0,
0
@@ -522,7 +522,7 @@ static const struct cachedesc cacheinfo[] = {
NamespaceOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_namespace_oid,
0,
0,
0
@@ -544,7 +544,7 @@ static const struct cachedesc cacheinfo[] = {
OperatorOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_operator_oid,
0,
0,
0
@@ -566,7 +566,7 @@ static const struct cachedesc cacheinfo[] = {
OpfamilyOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_opfamily_oid,
0,
0,
0
@@ -599,7 +599,7 @@ static const struct cachedesc cacheinfo[] = {
ProcedureOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_proc_oid,
0,
0,
0
@@ -621,7 +621,7 @@ static const struct cachedesc cacheinfo[] = {
PublicationObjectIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_publication_oid,
0,
0,
0
@@ -632,7 +632,7 @@ static const struct cachedesc cacheinfo[] = {
PublicationRelObjectIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_publication_rel_oid,
0,
0,
0
@@ -676,7 +676,7 @@ static const struct cachedesc cacheinfo[] = {
ClassOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_class_oid,
0,
0,
0
@@ -742,7 +742,7 @@ static const struct cachedesc cacheinfo[] = {
StatisticExtOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_statistic_ext_oid,
0,
0,
0
@@ -775,7 +775,7 @@ static const struct cachedesc cacheinfo[] = {
SubscriptionObjectIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_subscription_oid,
0,
0,
0
@@ -797,7 +797,7 @@ static const struct cachedesc cacheinfo[] = {
TablespaceOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_tablespace_oid,
0,
0,
0,
@@ -808,7 +808,7 @@ static const struct cachedesc cacheinfo[] = {
TransformOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_transform_oid,
0,
0,
0,
@@ -852,7 +852,7 @@ static const struct cachedesc cacheinfo[] = {
TSConfigOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_ts_config_oid,
0,
0,
0
@@ -874,7 +874,7 @@ static const struct cachedesc cacheinfo[] = {
TSDictionaryOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_ts_dict_oid,
0,
0,
0
@@ -896,7 +896,7 @@ static const struct cachedesc cacheinfo[] = {
TSParserOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_ts_parser_oid,
0,
0,
0
@@ -918,7 +918,7 @@ static const struct cachedesc cacheinfo[] = {
TSTemplateOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_ts_template_oid,
0,
0,
0
@@ -940,7 +940,7 @@ static const struct cachedesc cacheinfo[] = {
TypeOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_type_oid,
0,
0,
0
@@ -951,7 +951,7 @@ static const struct cachedesc cacheinfo[] = {
UserMappingOidIndexId,
1,
{
- ObjectIdAttributeNumber,
+ Anum_pg_user_mapping_oid,
0,
0,
0
@@ -1213,24 +1213,29 @@ SearchSysCacheExists(int cacheId,
/*
* GetSysCacheOid
*
- * A convenience routine that does SearchSysCache and returns the OID
- * of the found tuple, or InvalidOid if no tuple could be found.
+ * A convenience routine that does SearchSysCache and returns the OID in the
+ * oidcol column of the found tuple, or InvalidOid if no tuple could be found.
* No lock is retained on the syscache entry.
*/
Oid
GetSysCacheOid(int cacheId,
+ AttrNumber oidcol,
Datum key1,
Datum key2,
Datum key3,
Datum key4)
{
HeapTuple tuple;
+ bool isNull;
Oid result;
tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
if (!HeapTupleIsValid(tuple))
return InvalidOid;
- result = HeapTupleGetOid(tuple);
+ result = heap_getattr(tuple, oidcol,
+ SysCache[cacheId]->cc_tupdesc,
+ &isNull);
+ Assert(!isNull); /* columns used as oids should never be NULL */
ReleaseSysCache(tuple);
return result;
}
diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c
index 663d4ed8bbd..09f9d5fdcbd 100644
--- a/src/backend/utils/cache/typcache.c
+++ b/src/backend/utils/cache/typcache.c
@@ -2351,7 +2351,7 @@ load_enum_cache_data(TypeCacheEntry *tcache)
maxitems *= 2;
items = (EnumItem *) repalloc(items, sizeof(EnumItem) * maxitems);
}
- items[numitems].enum_oid = HeapTupleGetOid(enum_tuple);
+ items[numitems].enum_oid = en->oid;
items[numitems].sort_order = en->enumsortorder;
numitems++;
}