Commit ca70c3cf authored by Tom Lane's avatar Tom Lane

Revert my ill-considered change that made formrdesc not insert the correct

relation rowtype OID into the relcache entries it builds.  This ensures
that catcache copies of the relation tupdescs will be fully correct.
While the deficiency doesn't seem to have any effect in the current
sources, we have been bitten by not-quite-right catcache tupdescs before,
so it seems like a good idea to maintain the rule that they should be right.
parent 49856352
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.291 2009/09/26 18:24:49 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.292 2009/09/26 23:08:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -203,8 +203,9 @@ static bool load_relcache_init_file(bool shared); ...@@ -203,8 +203,9 @@ static bool load_relcache_init_file(bool shared);
static void write_relcache_init_file(bool shared); static void write_relcache_init_file(bool shared);
static void write_item(const void *data, Size len, FILE *fp); static void write_item(const void *data, Size len, FILE *fp);
static void formrdesc(const char *relationName, bool isshared, static void formrdesc(const char *relationName, Oid relationReltype,
bool hasoids, int natts, const FormData_pg_attribute *attrs); bool isshared, bool hasoids,
int natts, const FormData_pg_attribute *attrs);
static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK); static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK);
static Relation AllocateRelationDesc(Relation relation, Form_pg_class relp); static Relation AllocateRelationDesc(Relation relation, Form_pg_class relp);
...@@ -1374,8 +1375,9 @@ LookupOpclassInfo(Oid operatorClassOid, ...@@ -1374,8 +1375,9 @@ LookupOpclassInfo(Oid operatorClassOid,
* NOTE: we assume we are already switched into CacheMemoryContext. * NOTE: we assume we are already switched into CacheMemoryContext.
*/ */
static void static void
formrdesc(const char *relationName, bool isshared, formrdesc(const char *relationName, Oid relationReltype,
bool hasoids, int natts, const FormData_pg_attribute *attrs) bool isshared, bool hasoids,
int natts, const FormData_pg_attribute *attrs)
{ {
Relation relation; Relation relation;
int i; int i;
...@@ -1420,6 +1422,7 @@ formrdesc(const char *relationName, bool isshared, ...@@ -1420,6 +1422,7 @@ formrdesc(const char *relationName, bool isshared,
namestrcpy(&relation->rd_rel->relname, relationName); namestrcpy(&relation->rd_rel->relname, relationName);
relation->rd_rel->relnamespace = PG_CATALOG_NAMESPACE; relation->rd_rel->relnamespace = PG_CATALOG_NAMESPACE;
relation->rd_rel->reltype = relationReltype;
/* /*
* It's important to distinguish between shared and non-shared relations, * It's important to distinguish between shared and non-shared relations,
...@@ -1451,6 +1454,9 @@ formrdesc(const char *relationName, bool isshared, ...@@ -1451,6 +1454,9 @@ formrdesc(const char *relationName, bool isshared,
relation->rd_att = CreateTemplateTupleDesc(natts, hasoids); relation->rd_att = CreateTemplateTupleDesc(natts, hasoids);
relation->rd_att->tdrefcount = 1; /* mark as refcounted */ relation->rd_att->tdrefcount = 1; /* mark as refcounted */
relation->rd_att->tdtypeid = relationReltype;
relation->rd_att->tdtypmod = -1; /* unnecessary, but... */
/* /*
* initialize tuple desc info * initialize tuple desc info
*/ */
...@@ -2558,7 +2564,7 @@ RelationCacheInitializePhase2(void) ...@@ -2558,7 +2564,7 @@ RelationCacheInitializePhase2(void)
*/ */
if (!load_relcache_init_file(true)) if (!load_relcache_init_file(true))
{ {
formrdesc("pg_database", true, formrdesc("pg_database", DatabaseRelation_Rowtype_Id, true,
true, Natts_pg_database, Desc_pg_database); true, Natts_pg_database, Desc_pg_database);
#define NUM_CRITICAL_SHARED_RELS 1 /* fix if you change list above */ #define NUM_CRITICAL_SHARED_RELS 1 /* fix if you change list above */
...@@ -2604,13 +2610,13 @@ RelationCacheInitializePhase3(void) ...@@ -2604,13 +2610,13 @@ RelationCacheInitializePhase3(void)
{ {
needNewCacheFile = true; needNewCacheFile = true;
formrdesc("pg_class", false, formrdesc("pg_class", RelationRelation_Rowtype_Id, false,
true, Natts_pg_class, Desc_pg_class); true, Natts_pg_class, Desc_pg_class);
formrdesc("pg_attribute", false, formrdesc("pg_attribute", AttributeRelation_Rowtype_Id, false,
false, Natts_pg_attribute, Desc_pg_attribute); false, Natts_pg_attribute, Desc_pg_attribute);
formrdesc("pg_proc", false, formrdesc("pg_proc", ProcedureRelation_Rowtype_Id, false,
true, Natts_pg_proc, Desc_pg_proc); true, Natts_pg_proc, Desc_pg_proc);
formrdesc("pg_type", false, formrdesc("pg_type", TypeRelation_Rowtype_Id, false,
true, Natts_pg_type, Desc_pg_type); true, Natts_pg_type, Desc_pg_type);
#define NUM_CRITICAL_LOCAL_RELS 4 /* fix if you change list above */ #define NUM_CRITICAL_LOCAL_RELS 4 /* fix if you change list above */
...@@ -2738,11 +2744,14 @@ RelationCacheInitializePhase3(void) ...@@ -2738,11 +2744,14 @@ RelationCacheInitializePhase3(void)
RelationParseRelOptions(relation, htup); RelationParseRelOptions(relation, htup);
/* /*
* Also update the derived fields in rd_att. * Check the values in rd_att were set up correctly. (We cannot
* just copy them over now: formrdesc must have set up the
* rd_att data correctly to start with, because it may already
* have been copied into one or more catcache entries.)
*/ */
relation->rd_att->tdtypeid = relp->reltype; Assert(relation->rd_att->tdtypeid == relp->reltype);
relation->rd_att->tdtypmod = -1; /* unnecessary, but... */ Assert(relation->rd_att->tdtypmod == -1);
relation->rd_att->tdhasoid = relp->relhasoids; Assert(relation->rd_att->tdhasoid == relp->relhasoids);
ReleaseSysCache(htup); ReleaseSysCache(htup);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment