|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -203,8 +203,9 @@ static bool load_relcache_init_file(bool shared);
|
203 | 203 | static void write_relcache_init_file(bool shared);
|
204 | 204 | static void write_item(const void *data, Size len, FILE *fp);
|
205 | 205 |
|
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); |
208 | 209 |
|
209 | 210 | static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK);
|
210 | 211 | static Relation AllocateRelationDesc(Relation relation, Form_pg_class relp);
|
@@ -1374,8 +1375,9 @@ LookupOpclassInfo(Oid operatorClassOid,
|
1374 | 1375 | * NOTE: we assume we are already switched into CacheMemoryContext.
|
1375 | 1376 | */
|
1376 | 1377 | 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) |
1379 | 1381 | {
|
1380 | 1382 | Relation relation;
|
1381 | 1383 | int i;
|
@@ -1420,6 +1422,7 @@ formrdesc(const char *relationName, bool isshared,
|
1420 | 1422 |
|
1421 | 1423 | namestrcpy(&relation->rd_rel->relname, relationName);
|
1422 | 1424 | relation->rd_rel->relnamespace = PG_CATALOG_NAMESPACE;
|
| 1425 | + relation->rd_rel->reltype = relationReltype; |
1423 | 1426 |
|
1424 | 1427 | /*
|
1425 | 1428 | * It's important to distinguish between shared and non-shared relations,
|
@@ -1451,6 +1454,9 @@ formrdesc(const char *relationName, bool isshared,
|
1451 | 1454 | relation->rd_att = CreateTemplateTupleDesc(natts, hasoids);
|
1452 | 1455 | relation->rd_att->tdrefcount = 1; /* mark as refcounted */
|
1453 | 1456 |
|
| 1457 | + relation->rd_att->tdtypeid = relationReltype; |
| 1458 | + relation->rd_att->tdtypmod = -1; /* unnecessary, but... */ |
| 1459 | + |
1454 | 1460 | /*
|
1455 | 1461 | * initialize tuple desc info
|
1456 | 1462 | */
|
@@ -2558,7 +2564,7 @@ RelationCacheInitializePhase2(void)
|
2558 | 2564 | */
|
2559 | 2565 | if (!load_relcache_init_file(true))
|
2560 | 2566 | {
|
2561 |
| - formrdesc("pg_database", true, |
| 2567 | + formrdesc("pg_database", DatabaseRelation_Rowtype_Id, true, |
2562 | 2568 | true, Natts_pg_database, Desc_pg_database);
|
2563 | 2569 |
|
2564 | 2570 | #define NUM_CRITICAL_SHARED_RELS 1 /* fix if you change list above */
|
@@ -2604,13 +2610,13 @@ RelationCacheInitializePhase3(void)
|
2604 | 2610 | {
|
2605 | 2611 | needNewCacheFile = true;
|
2606 | 2612 |
|
2607 |
| - formrdesc("pg_class", false, |
| 2613 | + formrdesc("pg_class", RelationRelation_Rowtype_Id, false, |
2608 | 2614 | true, Natts_pg_class, Desc_pg_class);
|
2609 |
| - formrdesc("pg_attribute", false, |
| 2615 | + formrdesc("pg_attribute", AttributeRelation_Rowtype_Id, false, |
2610 | 2616 | false, Natts_pg_attribute, Desc_pg_attribute);
|
2611 |
| - formrdesc("pg_proc", false, |
| 2617 | + formrdesc("pg_proc", ProcedureRelation_Rowtype_Id, false, |
2612 | 2618 | true, Natts_pg_proc, Desc_pg_proc);
|
2613 |
| - formrdesc("pg_type", false, |
| 2619 | + formrdesc("pg_type", TypeRelation_Rowtype_Id, false, |
2614 | 2620 | true, Natts_pg_type, Desc_pg_type);
|
2615 | 2621 |
|
2616 | 2622 | #define NUM_CRITICAL_LOCAL_RELS 4 /* fix if you change list above */
|
@@ -2738,11 +2744,14 @@ RelationCacheInitializePhase3(void)
|
2738 | 2744 | RelationParseRelOptions(relation, htup);
|
2739 | 2745 |
|
2740 | 2746 | /*
|
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.) |
2742 | 2751 | */
|
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); |
2746 | 2755 |
|
2747 | 2756 | ReleaseSysCache(htup);
|
2748 | 2757 |
|
|
0 commit comments