Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit984791e

Browse files
committed
Upgrade formrdesc() so that it can correctly initialize the tupledesc
(rd_att) field of a nailed-in-cache relcache entry. This fixes the bugreported by Alvaro 8-Dec-2004; I believe it probably also explainsGrant Finnemore's report of 10-Sep-2004.In an unrelated change in the same file, put back 7.4's response tofailure to rename() the relcache init file, ie, unlink the uselesstemp file. I did not put back the warning message, since there mightactually be some reason not to have that.
1 parent12b1b5d commit984791e

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

‎src/backend/utils/cache/relcache.c

Lines changed: 34 additions & 28 deletions
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.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 $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -257,8 +257,8 @@ static Relation RelationSysNameCacheGetRelation(const char *relationName);
257257
staticboolload_relcache_init_file(void);
258258
staticvoidwrite_relcache_init_file(void);
259259

260-
staticvoidformrdesc(constchar*relationName,intnatts,
261-
FormData_pg_attribute*att);
260+
staticvoidformrdesc(constchar*relationName,OidrelationReltype,
261+
boolhasoids,intnatts,FormData_pg_attribute*att);
262262

263263
staticHeapTupleScanPgRelation(RelationBuildDescInfobuildinfo,boolindexOK);
264264
staticRelationAllocateRelationDesc(Relationrelation,Form_pg_classrelp);
@@ -1265,16 +1265,15 @@ LookupOpclassInfo(Oid operatorClassOid,
12651265
* NOTE: we assume we are already switched into CacheMemoryContext.
12661266
*/
12671267
staticvoid
1268-
formrdesc(constchar*relationName,
1269-
intnatts,
1270-
FormData_pg_attribute*att)
1268+
formrdesc(constchar*relationName,OidrelationReltype,
1269+
boolhasoids,intnatts,FormData_pg_attribute*att)
12711270
{
12721271
Relationrelation;
12731272
inti;
12741273
boolhas_not_null;
12751274

12761275
/*
1277-
* allocate new relation desc clear all fields of reldesc
1276+
* allocate new relation desc, clear all fields of reldesc
12781277
*/
12791278
relation= (Relation)palloc0(sizeof(RelationData));
12801279
relation->rd_targblock=InvalidBlockNumber;
@@ -1306,6 +1305,7 @@ formrdesc(const char *relationName,
13061305

13071306
namestrcpy(&relation->rd_rel->relname,relationName);
13081307
relation->rd_rel->relnamespace=PG_CATALOG_NAMESPACE;
1308+
relation->rd_rel->reltype=relationReltype;
13091309

13101310
/*
13111311
* It's important to distinguish between shared and non-shared
@@ -1318,7 +1318,7 @@ formrdesc(const char *relationName,
13181318
relation->rd_rel->relpages=1;
13191319
relation->rd_rel->reltuples=1;
13201320
relation->rd_rel->relkind=RELKIND_RELATION;
1321-
relation->rd_rel->relhasoids=true;
1321+
relation->rd_rel->relhasoids=hasoids;
13221322
relation->rd_rel->relnatts= (int16)natts;
13231323

13241324
/*
@@ -1327,12 +1327,10 @@ formrdesc(const char *relationName,
13271327
* Unlike the case with the relation tuple, this data had better be right
13281328
* because it will never be replaced. The input values must be
13291329
* 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.
13341330
*/
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... */
13361334

13371335
/*
13381336
* initialize tuple desc info
@@ -1380,10 +1378,12 @@ formrdesc(const char *relationName,
13801378
/*
13811379
* initialize the rel-has-index flag, using hardwired knowledge
13821380
*/
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
13871387
{
13881388
/* Otherwise, all the rels formrdesc is used for have indexes */
13891389
relation->rd_rel->relhasindex= true;
@@ -2348,14 +2348,14 @@ RelationCacheInitialize(void)
23482348
if (IsBootstrapProcessingMode()||
23492349
!load_relcache_init_file())
23502350
{
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);
23592359

23602360
#defineNUM_CRITICAL_RELS4/* fix if you change list above */
23612361
}
@@ -3422,16 +3422,22 @@ write_relcache_init_file(void)
34223422
/*
34233423
* OK, rename the temp file to its final name, deleting any
34243424
* 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.
34253430
*/
3426-
rename(tempfilename,finalfilename);
3427-
LWLockRelease(RelCacheInitLock);
3431+
if (rename(tempfilename,finalfilename)<0)
3432+
unlink(tempfilename);
34283433
}
34293434
else
34303435
{
34313436
/* Delete the already-obsolete temp file */
34323437
unlink(tempfilename);
3433-
LWLockRelease(RelCacheInitLock);
34343438
}
3439+
3440+
LWLockRelease(RelCacheInitLock);
34353441
}
34363442

34373443
/*

‎src/include/catalog/pg_type.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.156 2004/08/29 05:06:55 momjian Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.157 2004/12/12 05:07:50 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -305,9 +305,13 @@ DESCR("array of INDEX_MAX_KEYS oids, used in system tables");
305305
#defineOIDVECTOROID30
306306

307307
DATA(insertOID=71 (pg_typePGNSPPGUID-1fct \05412470record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));
308+
#definePG_TYPE_RELTYPE_OID 71
308309
DATA(insertOID=75 (pg_attributePGNSPPGUID-1fct \05412490record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));
310+
#definePG_ATTRIBUTE_RELTYPE_OID 75
309311
DATA(insertOID=81 (pg_procPGNSPPGUID-1fct \05412550record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));
312+
#definePG_PROC_RELTYPE_OID 81
310313
DATA(insertOID=83 (pg_classPGNSPPGUID-1fct \05412590record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));
314+
#definePG_CLASS_RELTYPE_OID 83
311315
DATA(insertOID=86 (pg_shadowPGNSPPGUID-1fct \05412600record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));
312316
DATA(insertOID=87 (pg_groupPGNSPPGUID-1fct \05412610record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));
313317
DATA(insertOID=88 (pg_databasePGNSPPGUID-1fct \05412620record_inrecord_outrecord_recvrecord_send-dxf0-10_null__null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp