8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.212 2004/11/20 20:19:52 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.213 2004/12/12 05:07:47 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -257,8 +257,8 @@ static Relation RelationSysNameCacheGetRelation(const char *relationName);
257
257
static bool load_relcache_init_file (void );
258
258
static void write_relcache_init_file (void );
259
259
260
- static void formrdesc (const char * relationName , int natts ,
261
- FormData_pg_attribute * att );
260
+ static void formrdesc (const char * relationName , Oid relationReltype ,
261
+ bool hasoids , int natts , FormData_pg_attribute * att );
262
262
263
263
static HeapTuple ScanPgRelation (RelationBuildDescInfo buildinfo , bool indexOK );
264
264
static Relation AllocateRelationDesc (Relation relation , Form_pg_class relp );
@@ -1265,16 +1265,15 @@ LookupOpclassInfo(Oid operatorClassOid,
1265
1265
* NOTE: we assume we are already switched into CacheMemoryContext.
1266
1266
*/
1267
1267
static void
1268
- formrdesc (const char * relationName ,
1269
- int natts ,
1270
- FormData_pg_attribute * att )
1268
+ formrdesc (const char * relationName , Oid relationReltype ,
1269
+ bool hasoids , int natts , FormData_pg_attribute * att )
1271
1270
{
1272
1271
Relation relation ;
1273
1272
int i ;
1274
1273
bool has_not_null ;
1275
1274
1276
1275
/*
1277
- * allocate new relation desc clear all fields of reldesc
1276
+ * allocate new relation desc, clear all fields of reldesc
1278
1277
*/
1279
1278
relation = (Relation ) palloc0 (sizeof (RelationData ));
1280
1279
relation -> rd_targblock = InvalidBlockNumber ;
@@ -1306,6 +1305,7 @@ formrdesc(const char *relationName,
1306
1305
1307
1306
namestrcpy (& relation -> rd_rel -> relname , relationName );
1308
1307
relation -> rd_rel -> relnamespace = PG_CATALOG_NAMESPACE ;
1308
+ relation -> rd_rel -> reltype = relationReltype ;
1309
1309
1310
1310
/*
1311
1311
* It's important to distinguish between shared and non-shared
@@ -1318,7 +1318,7 @@ formrdesc(const char *relationName,
1318
1318
relation -> rd_rel -> relpages = 1 ;
1319
1319
relation -> rd_rel -> reltuples = 1 ;
1320
1320
relation -> rd_rel -> relkind = RELKIND_RELATION ;
1321
- relation -> rd_rel -> relhasoids = true ;
1321
+ relation -> rd_rel -> relhasoids = hasoids ;
1322
1322
relation -> rd_rel -> relnatts = (int16 ) natts ;
1323
1323
1324
1324
/*
@@ -1327,12 +1327,10 @@ formrdesc(const char *relationName,
1327
1327
* Unlike the case with the relation tuple, this data had better be right
1328
1328
* because it will never be replaced. The input values must be
1329
1329
* correctly defined by macros in src/include/catalog/ headers.
1330
- *
1331
- * Note however that rd_att's tdtypeid, tdtypmod, tdhasoid fields are not
1332
- * right at this point. They will be fixed later when the real
1333
- * pg_class row is loaded.
1334
1330
*/
1335
- relation -> rd_att = CreateTemplateTupleDesc (natts , false);
1331
+ relation -> rd_att = CreateTemplateTupleDesc (natts , hasoids );
1332
+ relation -> rd_att -> tdtypeid = relationReltype ;
1333
+ relation -> rd_att -> tdtypmod = -1 ; /* unnecessary, but... */
1336
1334
1337
1335
/*
1338
1336
* initialize tuple desc info
@@ -1380,10 +1378,12 @@ formrdesc(const char *relationName,
1380
1378
/*
1381
1379
* initialize the rel-has-index flag, using hardwired knowledge
1382
1380
*/
1383
- relation -> rd_rel -> relhasindex = false;
1384
-
1385
- /* In bootstrap mode, we have no indexes */
1386
- if (!IsBootstrapProcessingMode ())
1381
+ if (IsBootstrapProcessingMode ())
1382
+ {
1383
+ /* In bootstrap mode, we have no indexes */
1384
+ relation -> rd_rel -> relhasindex = false;
1385
+ }
1386
+ else
1387
1387
{
1388
1388
/* Otherwise, all the rels formrdesc is used for have indexes */
1389
1389
relation -> rd_rel -> relhasindex = true;
@@ -2348,14 +2348,14 @@ RelationCacheInitialize(void)
2348
2348
if (IsBootstrapProcessingMode () ||
2349
2349
!load_relcache_init_file ())
2350
2350
{
2351
- formrdesc (RelationRelationName ,
2352
- Natts_pg_class , Desc_pg_class );
2353
- formrdesc (AttributeRelationName ,
2354
- Natts_pg_attribute , Desc_pg_attribute );
2355
- formrdesc (ProcedureRelationName ,
2356
- Natts_pg_proc , Desc_pg_proc );
2357
- formrdesc (TypeRelationName ,
2358
- Natts_pg_type , Desc_pg_type );
2351
+ formrdesc (RelationRelationName , PG_CLASS_RELTYPE_OID ,
2352
+ true, Natts_pg_class , Desc_pg_class );
2353
+ formrdesc (AttributeRelationName , PG_ATTRIBUTE_RELTYPE_OID ,
2354
+ false, Natts_pg_attribute , Desc_pg_attribute );
2355
+ formrdesc (ProcedureRelationName , PG_PROC_RELTYPE_OID ,
2356
+ true, Natts_pg_proc , Desc_pg_proc );
2357
+ formrdesc (TypeRelationName , PG_TYPE_RELTYPE_OID ,
2358
+ true, Natts_pg_type , Desc_pg_type );
2359
2359
2360
2360
#define NUM_CRITICAL_RELS 4 /* fix if you change list above */
2361
2361
}
@@ -3422,16 +3422,22 @@ write_relcache_init_file(void)
3422
3422
/*
3423
3423
* OK, rename the temp file to its final name, deleting any
3424
3424
* previously-existing init file.
3425
+ *
3426
+ * Note: a failure here is possible under Cygwin, if some other
3427
+ * backend is holding open an unlinked-but-not-yet-gone init file.
3428
+ * So treat this as a noncritical failure; just remove the useless
3429
+ * temp file on failure.
3425
3430
*/
3426
- rename (tempfilename , finalfilename );
3427
- LWLockRelease ( RelCacheInitLock );
3431
+ if ( rename (tempfilename , finalfilename ) < 0 )
3432
+ unlink ( tempfilename );
3428
3433
}
3429
3434
else
3430
3435
{
3431
3436
/* Delete the already-obsolete temp file */
3432
3437
unlink (tempfilename );
3433
- LWLockRelease (RelCacheInitLock );
3434
3438
}
3439
+
3440
+ LWLockRelease (RelCacheInitLock );
3435
3441
}
3436
3442
3437
3443
/*
0 commit comments