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

Commitdc5c771

Browse files
committed
Commit to make clearer distinction for temp names and real names.
Thanks to Tom Lane for ideas.
1 parentbf5d51e commitdc5c771

File tree

9 files changed

+70
-33
lines changed

9 files changed

+70
-33
lines changed

‎src/backend/catalog/heap.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.107 1999/11/07 23:08:00 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.108 1999/11/16 04:13:55 momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -290,7 +290,7 @@ heap_create(char *relname,
290290
* ----------------
291291
*/
292292
MemSet((char*)rel->rd_rel,0,sizeof*rel->rd_rel);
293-
strcpy(RelationGetRelationName(rel),relname);
293+
strcpy(RelationGetPhysicalRelationName(rel),relname);
294294
rel->rd_rel->relkind=RELKIND_UNCATALOGED;
295295
rel->rd_rel->relnatts=natts;
296296
if (tupDesc->constr)
@@ -798,7 +798,7 @@ heap_create_with_catalog(char *relname,
798798

799799
/* temp tables can mask non-temp tables */
800800
if ((!istemp&&RelnameFindRelid(relname))||
801-
(istemp&&get_temp_rel_by_name(relname)!=NULL))
801+
(istemp&&get_temp_rel_by_username(relname)!=NULL))
802802
elog(ERROR,"Relation '%s' already exists",relname);
803803

804804
/* save user relation name because heap_create changes it */
@@ -810,7 +810,7 @@ heap_create_with_catalog(char *relname,
810810
}
811811

812812
/* ----------------
813-
*get_temp_rel_by_name() couldn't check the simultaneous
813+
*get_temp_rel_by_username() couldn't check the simultaneous
814814
*creation. Uniqueness will be really checked by unique
815815
*indexes of system tables but we couldn't check it here.
816816
*We have to pospone to create the disk file for this
@@ -1448,7 +1448,7 @@ heap_destroy_with_catalog(char *relname)
14481448
{
14491449
Relationrel;
14501450
Oidrid;
1451-
boolistemp= (get_temp_rel_by_name(relname)!=NULL);
1451+
boolistemp= (get_temp_rel_by_username(relname)!=NULL);
14521452

14531453
/* ----------------
14541454
*Open and lock the relation.
@@ -1518,9 +1518,6 @@ heap_destroy_with_catalog(char *relname)
15181518

15191519
DeleteComments(RelationGetRelid(rel));
15201520

1521-
if (istemp)
1522-
remove_temp_relation(rid);
1523-
15241521
/* ----------------
15251522
*delete type tuple.here we want to see the effects
15261523
*of the deletions we just did, so we use setheapoverride().
@@ -1565,6 +1562,9 @@ heap_destroy_with_catalog(char *relname)
15651562
* ----------------
15661563
*/
15671564
RelationForgetRelation(rid);
1565+
1566+
if (istemp)
1567+
remove_temp_relation(rid);
15681568
}
15691569

15701570
/*

‎src/backend/catalog/index.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.94 1999/11/04 08:00:56 inoue Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.95 1999/11/16 04:13:55 momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -120,7 +120,7 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName, bool istemp)
120120
indoid=RelnameFindRelid(indexRelationName);
121121

122122
if ((!istemp&&OidIsValid(indoid))||
123-
(istemp&&get_temp_rel_by_name(indexRelationName)!=NULL))
123+
(istemp&&get_temp_rel_by_username(indexRelationName)!=NULL))
124124
elog(ERROR,"Cannot create index: '%s' already exists",
125125
indexRelationName);
126126

@@ -948,7 +948,7 @@ index_create(char *heapRelationName,
948948
Oidheapoid;
949949
Oidindexoid;
950950
PredInfo*predInfo;
951-
boolistemp= (get_temp_rel_by_name(heapRelationName)!=NULL);
951+
boolistemp= (get_temp_rel_by_username(heapRelationName)!=NULL);
952952
char*temp_relname=NULL;
953953

954954
/* ----------------
@@ -1182,9 +1182,6 @@ index_destroy(Oid indexId)
11821182
}
11831183
heap_close(attributeRelation,RowExclusiveLock);
11841184

1185-
/* does something only if it is a temp index */
1186-
remove_temp_relation(indexId);
1187-
11881185
/* ----------------
11891186
* fix INDEX relation
11901187
* ----------------
@@ -1211,6 +1208,9 @@ index_destroy(Oid indexId)
12111208
index_close(userindexRelation);
12121209

12131210
RelationForgetRelation(indexId);
1211+
1212+
/* does something only if it is a temp index */
1213+
remove_temp_relation(indexId);
12141214
}
12151215

12161216
/* ----------------------------------------------------------------

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.65 1999/11/07 23:08:14 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.66 1999/11/16 04:13:56 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -622,7 +622,7 @@ BufferAlloc(Relation reln,
622622
}
623623

624624
/* record the database name and relation name for this buffer */
625-
strcpy(buf->sb_relname,RelationGetRelationName(reln));
625+
strcpy(buf->sb_relname,RelationGetPhysicalRelationName(reln));
626626
strcpy(buf->sb_dbname,DatabaseName);
627627

628628
INIT_BUFFERTAG(&(buf->tag),reln,blockNum);

‎src/backend/storage/smgr/md.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.59 1999/11/07 23:08:19 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.60 1999/11/16 04:13:56 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -121,7 +121,7 @@ mdcreate(Relation reln)
121121
char*path;
122122

123123
Assert(reln->rd_unlinked&&reln->rd_fd<0);
124-
path=relpath(RelationGetRelationName(reln));
124+
path=relpath(RelationGetPhysicalRelationName(reln));
125125
#ifndef__CYGWIN32__
126126
fd=FileNameOpenFile(path,O_RDWR |O_CREAT |O_EXCL,0600);
127127
#else
@@ -319,7 +319,7 @@ mdopen(Relation reln)
319319
intvfd;
320320

321321
Assert(reln->rd_fd<0);
322-
path=relpath(RelationGetRelationName(reln));
322+
path=relpath(RelationGetPhysicalRelationName(reln));
323323

324324
#ifndef__CYGWIN32__
325325
fd=FileNameOpenFile(path,O_RDWR,0600);
@@ -1011,7 +1011,7 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
10111011
*fullpath;
10121012

10131013
/* be sure we have enough space for the '.segno', if any */
1014-
path=relpath(RelationGetRelationName(reln));
1014+
path=relpath(RelationGetPhysicalRelationName(reln));
10151015

10161016
dofree= false;
10171017
if (segno>0)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.76 1999/11/07 23:08:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.77 1999/11/16 04:13:58 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -962,7 +962,7 @@ formrdesc(char *relationName,
962962
relation->rd_rel= (Form_pg_class)
963963
palloc((Size) (sizeof(*relation->rd_rel)));
964964
MemSet(relation->rd_rel,0,sizeof(FormData_pg_class));
965-
strcpy(RelationGetRelationName(relation),relationName);
965+
strcpy(RelationGetPhysicalRelationName(relation),relationName);
966966

967967
/* ----------------
968968
initialize attribute tuple form
@@ -1177,7 +1177,7 @@ RelationNameGetRelation(char *relationName)
11771177
*we only index temp rels by their real names.
11781178
* ----------------
11791179
*/
1180-
temprelname=get_temp_rel_by_name(relationName);
1180+
temprelname=get_temp_rel_by_username(relationName);
11811181
if (temprelname)
11821182
relationName=temprelname;
11831183

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.38 1999/11/01 02:29:25 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.39 1999/11/16 04:13:59 momjian Exp $
1111
*
1212
* NOTES
1313
* These routines allow the parser/planner/executor to perform
@@ -472,7 +472,7 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
472472
char*nontemp_relname;
473473

474474
if ((nontemp_relname=
475-
get_temp_rel_by_name(DatumGetPointer(key1)))!=NULL)
475+
get_temp_rel_by_username(DatumGetPointer(key1)))!=NULL)
476476
key1=PointerGetDatum(nontemp_relname);
477477
}
478478

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.15 1999/11/07 23:08:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.16 1999/11/16 04:13:59 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -150,7 +150,6 @@ remove_temp_relation(Oid relid)
150150
prev=l;
151151
l=lnext(l);
152152
}
153-
154153
}
155154

156155
MemoryContextSwitchTo(oldcxt);
@@ -203,7 +202,7 @@ invalidate_temp_relations(void)
203202
}
204203

205204
char*
206-
get_temp_rel_by_name(char*user_relname)
205+
get_temp_rel_by_username(char*user_relname)
207206
{
208207
List*l;
209208

@@ -216,3 +215,22 @@ get_temp_rel_by_name(char *user_relname)
216215
}
217216
returnNULL;
218217
}
218+
219+
char*
220+
get_temp_rel_by_physicalname(char*relname)
221+
{
222+
List*l;
223+
224+
/* already physical, needed for bootstrapping temp tables */
225+
if (strncmp(relname,"pg_temp.",strlen("pg_temp."))==0)
226+
returnrelname;
227+
228+
foreach(l,temp_rels)
229+
{
230+
TempTable*temp_rel=lfirst(l);
231+
232+
if (strcmp(temp_rel->relname,relname)==0)
233+
returntemp_rel->user_relname;
234+
}
235+
returnNULL;
236+
}

‎src/include/utils/rel.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: rel.h,v 1.29 1999/11/07 23:08:33 momjian Exp $
9+
* $Id: rel.h,v 1.30 1999/11/16 04:14:03 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -20,7 +20,6 @@
2020
#include"rewrite/prs2lock.h"
2121
#include"storage/fd.h"
2222

23-
2423
/*
2524
* LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
2625
* to declare them here so we can have a LockInfoData field in a Relation.
@@ -176,7 +175,26 @@ typedef Relation *RelationPtr;
176175
*
177176
* Returns a Relation Name
178177
*/
179-
#defineRelationGetRelationName(relation) (NameStr((relation)->rd_rel->relname))
178+
/* added to prevent circular dependency. bjm 1999/11/15 */
179+
char*get_temp_rel_by_physicalname(char*relname);
180+
#defineRelationGetRelationName(relation) \
181+
(\
182+
(strncmp(RelationGetPhysicalRelationName(relation), \
183+
"pg_temp.", strlen("pg_temp.")) != 0) \
184+
? \
185+
RelationGetPhysicalRelationName(relation) \
186+
: \
187+
get_temp_rel_by_physicalname( \
188+
RelationGetPhysicalRelationName(relation)) \
189+
)
190+
191+
192+
/*
193+
* RelationGetPhysicalRelationName
194+
*
195+
* Returns a Relation Name
196+
*/
197+
#defineRelationGetPhysicalRelationName(relation) (NameStr((relation)->rd_rel->relname))
180198

181199
/*
182200
* RelationGetNumberOfAttributes

‎src/include/utils/temprel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: temprel.h,v 1.5 1999/09/04 19:55:50 momjian Exp $
9+
* $Id: temprel.h,v 1.6 1999/11/16 04:14:03 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -19,6 +19,7 @@ voidcreate_temp_relation(char *relname, HeapTuple pg_class_tuple);
1919
voidremove_all_temp_relations(void);
2020
voidinvalidate_temp_relations(void);
2121
voidremove_temp_relation(Oidrelid);
22-
char*get_temp_rel_by_name(char*user_relname);
22+
char*get_temp_rel_by_username(char*user_relname);
23+
char*get_temp_rel_by_physicalname(char*relname);
2324

2425
#endif/* TEMPREL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp