Skip to content

Commit 0e14dfe

Browse files
committed
Intercept temp table lookups further up to map temp names.
1 parent cb36c0f commit 0e14dfe

File tree

5 files changed

+25
-34
lines changed

5 files changed

+25
-34
lines changed

src/backend/catalog/heap.c

Lines changed: 2 additions & 12 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.93 1999/07/17 20:16:48 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.94 1999/09/04 22:00:29 momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -237,8 +237,7 @@ heap_create(char *relname,
237237
if (istemp)
238238
{
239239
/* replace relname of caller */
240-
snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
241-
MyProcPid, uniqueId++);
240+
snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u", MyProcPid, uniqueId++);
242241
}
243242

244243
/* ----------------
@@ -789,15 +788,6 @@ heap_create_with_catalog(char *relname,
789788
(istemp && get_temp_rel_by_name(relname) != NULL))
790789
elog(ERROR, "Relation '%s' already exists", relname);
791790

792-
/* invalidate cache so non-temp table is masked by temp */
793-
if (istemp)
794-
{
795-
Oid relid = RelnameFindRelid(relname);
796-
797-
if (relid != InvalidOid)
798-
RelationForgetRelation(relid);
799-
}
800-
801791
/* save user relation name because heap_create changes it */
802792
if (istemp)
803793
{

src/backend/catalog/index.c

Lines changed: 1 addition & 10 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.87 1999/07/20 17:14:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.88 1999/09/04 22:00:29 momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -975,15 +975,6 @@ index_create(char *heapRelationName,
975975
numatts,
976976
attNums);
977977

978-
/* invalidate cache so possible non-temp index is masked by temp */
979-
if (istemp)
980-
{
981-
Oid relid = RelnameFindRelid(indexRelationName);
982-
983-
if (relid != InvalidOid)
984-
RelationForgetRelation(relid);
985-
}
986-
987978
/* save user relation name because heap_create changes it */
988979
if (istemp)
989980
{

src/backend/catalog/indexing.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.43 1999/09/04 19:55:49 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.44 1999/09/04 22:00:29 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -24,7 +24,6 @@
2424
#include "catalog/pg_index.h"
2525
#include "miscadmin.h"
2626
#include "utils/syscache.h"
27-
#include "utils/temprel.h"
2827

2928
/*
3029
* Names of indices on the following system catalogs:
@@ -449,15 +448,7 @@ ClassNameIndexScan(Relation heapRelation, char *relName)
449448
Relation idesc;
450449
ScanKeyData skey[1];
451450
HeapTuple tuple;
452-
char *hold_rel;
453451

454-
/*
455-
* we have to do this before looking in system tables because temp
456-
* table namespace takes precedence
457-
*/
458-
if ((hold_rel = get_temp_rel_by_name(relName)) != NULL)
459-
relName = hold_rel;
460-
461452
ScanKeyEntryInitialize(&skey[0],
462453
(bits16) 0x0,
463454
(AttrNumber) 1,

src/backend/utils/cache/syscache.c

Lines changed: 12 additions & 1 deletion
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.34 1999/08/09 03:13:30 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.35 1999/09/04 22:00:30 momjian Exp $
1111
*
1212
* NOTES
1313
* These routines allow the parser/planner/executor to perform
@@ -35,6 +35,7 @@
3535
#include "catalog/pg_shadow.h"
3636
#include "catalog/pg_type.h"
3737
#include "utils/catcache.h"
38+
#include "utils/temprel.h"
3839

3940
extern bool AMI_OVERRIDE; /* XXX style */
4041

@@ -487,6 +488,16 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
487488
cacheId);
488489
}
489490

491+
/* temp table name remapping */
492+
if (cacheId == RELNAME)
493+
{
494+
char *nontemp_relname;
495+
496+
if ((nontemp_relname =
497+
get_temp_rel_by_name(DatumGetPointer(key1))) != NULL)
498+
key1 = PointerGetDatum(nontemp_relname);
499+
}
500+
490501
tp = SearchSysCache(SysCache[cacheId], key1, key2, key3, key4);
491502
if (!HeapTupleIsValid(tp))
492503
{

src/backend/utils/cache/temprel.c

Lines changed: 9 additions & 1 deletion
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.12 1999/09/04 21:45:48 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.13 1999/09/04 22:00:30 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -117,6 +117,8 @@ remove_temp_relation(Oid relid)
117117
MemoryContext oldcxt;
118118
List *l,
119119
*prev;
120+
121+
elog(NOTICE,"oid = %d", relid);
120122

121123
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
122124

@@ -126,8 +128,11 @@ remove_temp_relation(Oid relid)
126128
{
127129
TempTable *temp_rel = lfirst(l);
128130

131+
elog(NOTICE,"check oid = %d", temp_rel->relid);
132+
129133
if (temp_rel->relid == relid)
130134
{
135+
elog(NOTICE,"removed");
131136
pfree(temp_rel->user_relname);
132137
pfree(temp_rel->relname);
133138
pfree(temp_rel);
@@ -212,7 +217,10 @@ get_temp_rel_by_name(char *user_relname)
212217
TempTable *temp_rel = lfirst(l);
213218

214219
if (strcmp(temp_rel->user_relname, user_relname) == 0)
220+
{
221+
elog(NOTICE,"found");
215222
return temp_rel->relname;
223+
}
216224
}
217225
return NULL;
218226
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy