Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ca70c3c

Browse files
committed
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.
1 parent 4985635 commit ca70c3c

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/backend/utils/cache/relcache.c

+23-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.291 2009/09/26 18:24:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.292 2009/09/26 23:08:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -203,8 +203,9 @@ static bool load_relcache_init_file(bool shared);
203203
static void write_relcache_init_file(bool shared);
204204
static void write_item(const void *data, Size len, FILE *fp);
205205

206-
static void formrdesc(const char *relationName, bool isshared,
207-
bool hasoids, int natts, const FormData_pg_attribute *attrs);
206+
static void formrdesc(const char *relationName, Oid relationReltype,
207+
bool isshared, bool hasoids,
208+
int natts, const FormData_pg_attribute *attrs);
208209

209210
static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK);
210211
static Relation AllocateRelationDesc(Relation relation, Form_pg_class relp);
@@ -1374,8 +1375,9 @@ LookupOpclassInfo(Oid operatorClassOid,
13741375
* NOTE: we assume we are already switched into CacheMemoryContext.
13751376
*/
13761377
static void
1377-
formrdesc(const char *relationName, bool isshared,
1378-
bool hasoids, int natts, const FormData_pg_attribute *attrs)
1378+
formrdesc(const char *relationName, Oid relationReltype,
1379+
bool isshared, bool hasoids,
1380+
int natts, const FormData_pg_attribute *attrs)
13791381
{
13801382
Relation relation;
13811383
int i;
@@ -1420,6 +1422,7 @@ formrdesc(const char *relationName, bool isshared,
14201422

14211423
namestrcpy(&relation->rd_rel->relname, relationName);
14221424
relation->rd_rel->relnamespace = PG_CATALOG_NAMESPACE;
1425+
relation->rd_rel->reltype = relationReltype;
14231426

14241427
/*
14251428
* It's important to distinguish between shared and non-shared relations,
@@ -1451,6 +1454,9 @@ formrdesc(const char *relationName, bool isshared,
14511454
relation->rd_att = CreateTemplateTupleDesc(natts, hasoids);
14521455
relation->rd_att->tdrefcount = 1; /* mark as refcounted */
14531456

1457+
relation->rd_att->tdtypeid = relationReltype;
1458+
relation->rd_att->tdtypmod = -1; /* unnecessary, but... */
1459+
14541460
/*
14551461
* initialize tuple desc info
14561462
*/
@@ -2558,7 +2564,7 @@ RelationCacheInitializePhase2(void)
25582564
*/
25592565
if (!load_relcache_init_file(true))
25602566
{
2561-
formrdesc("pg_database", true,
2567+
formrdesc("pg_database", DatabaseRelation_Rowtype_Id, true,
25622568
true, Natts_pg_database, Desc_pg_database);
25632569

25642570
#define NUM_CRITICAL_SHARED_RELS 1 /* fix if you change list above */
@@ -2604,13 +2610,13 @@ RelationCacheInitializePhase3(void)
26042610
{
26052611
needNewCacheFile = true;
26062612

2607-
formrdesc("pg_class", false,
2613+
formrdesc("pg_class", RelationRelation_Rowtype_Id, false,
26082614
true, Natts_pg_class, Desc_pg_class);
2609-
formrdesc("pg_attribute", false,
2615+
formrdesc("pg_attribute", AttributeRelation_Rowtype_Id, false,
26102616
false, Natts_pg_attribute, Desc_pg_attribute);
2611-
formrdesc("pg_proc", false,
2617+
formrdesc("pg_proc", ProcedureRelation_Rowtype_Id, false,
26122618
true, Natts_pg_proc, Desc_pg_proc);
2613-
formrdesc("pg_type", false,
2619+
formrdesc("pg_type", TypeRelation_Rowtype_Id, false,
26142620
true, Natts_pg_type, Desc_pg_type);
26152621

26162622
#define NUM_CRITICAL_LOCAL_RELS 4 /* fix if you change list above */
@@ -2738,11 +2744,14 @@ RelationCacheInitializePhase3(void)
27382744
RelationParseRelOptions(relation, htup);
27392745

27402746
/*
2741-
* Also update the derived fields in rd_att.
2747+
* Check the values in rd_att were set up correctly. (We cannot
2748+
* just copy them over now: formrdesc must have set up the
2749+
* rd_att data correctly to start with, because it may already
2750+
* have been copied into one or more catcache entries.)
27422751
*/
2743-
relation->rd_att->tdtypeid = relp->reltype;
2744-
relation->rd_att->tdtypmod = -1; /* unnecessary, but... */
2745-
relation->rd_att->tdhasoid = relp->relhasoids;
2752+
Assert(relation->rd_att->tdtypeid == relp->reltype);
2753+
Assert(relation->rd_att->tdtypmod == -1);
2754+
Assert(relation->rd_att->tdhasoid == relp->relhasoids);
27462755

27472756
ReleaseSysCache(htup);
27482757

0 commit comments

Comments
 (0)