mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Intercept temp table lookups further up to map temp names.
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.93 1999/07/17 20:16:48 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.94 1999/09/04 22:00:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* INTERFACE ROUTINES
|
* INTERFACE ROUTINES
|
||||||
@ -237,8 +237,7 @@ heap_create(char *relname,
|
|||||||
if (istemp)
|
if (istemp)
|
||||||
{
|
{
|
||||||
/* replace relname of caller */
|
/* replace relname of caller */
|
||||||
snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
|
snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u", MyProcPid, uniqueId++);
|
||||||
MyProcPid, uniqueId++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
@ -789,15 +788,6 @@ heap_create_with_catalog(char *relname,
|
|||||||
(istemp && get_temp_rel_by_name(relname) != NULL))
|
(istemp && get_temp_rel_by_name(relname) != NULL))
|
||||||
elog(ERROR, "Relation '%s' already exists", relname);
|
elog(ERROR, "Relation '%s' already exists", relname);
|
||||||
|
|
||||||
/* invalidate cache so non-temp table is masked by temp */
|
|
||||||
if (istemp)
|
|
||||||
{
|
|
||||||
Oid relid = RelnameFindRelid(relname);
|
|
||||||
|
|
||||||
if (relid != InvalidOid)
|
|
||||||
RelationForgetRelation(relid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save user relation name because heap_create changes it */
|
/* save user relation name because heap_create changes it */
|
||||||
if (istemp)
|
if (istemp)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.87 1999/07/20 17:14:05 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.88 1999/09/04 22:00:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* INTERFACE ROUTINES
|
* INTERFACE ROUTINES
|
||||||
@ -975,15 +975,6 @@ index_create(char *heapRelationName,
|
|||||||
numatts,
|
numatts,
|
||||||
attNums);
|
attNums);
|
||||||
|
|
||||||
/* invalidate cache so possible non-temp index is masked by temp */
|
|
||||||
if (istemp)
|
|
||||||
{
|
|
||||||
Oid relid = RelnameFindRelid(indexRelationName);
|
|
||||||
|
|
||||||
if (relid != InvalidOid)
|
|
||||||
RelationForgetRelation(relid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save user relation name because heap_create changes it */
|
/* save user relation name because heap_create changes it */
|
||||||
if (istemp)
|
if (istemp)
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.43 1999/09/04 19:55:49 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.44 1999/09/04 22:00:29 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -24,7 +24,6 @@
|
|||||||
#include "catalog/pg_index.h"
|
#include "catalog/pg_index.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
#include "utils/temprel.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Names of indices on the following system catalogs:
|
* Names of indices on the following system catalogs:
|
||||||
@ -449,14 +448,6 @@ ClassNameIndexScan(Relation heapRelation, char *relName)
|
|||||||
Relation idesc;
|
Relation idesc;
|
||||||
ScanKeyData skey[1];
|
ScanKeyData skey[1];
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
char *hold_rel;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* we have to do this before looking in system tables because temp
|
|
||||||
* table namespace takes precedence
|
|
||||||
*/
|
|
||||||
if ((hold_rel = get_temp_rel_by_name(relName)) != NULL)
|
|
||||||
relName = hold_rel;
|
|
||||||
|
|
||||||
ScanKeyEntryInitialize(&skey[0],
|
ScanKeyEntryInitialize(&skey[0],
|
||||||
(bits16) 0x0,
|
(bits16) 0x0,
|
||||||
|
13
src/backend/utils/cache/syscache.c
vendored
13
src/backend/utils/cache/syscache.c
vendored
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.34 1999/08/09 03:13:30 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.35 1999/09/04 22:00:30 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* These routines allow the parser/planner/executor to perform
|
* These routines allow the parser/planner/executor to perform
|
||||||
@ -35,6 +35,7 @@
|
|||||||
#include "catalog/pg_shadow.h"
|
#include "catalog/pg_shadow.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "utils/catcache.h"
|
#include "utils/catcache.h"
|
||||||
|
#include "utils/temprel.h"
|
||||||
|
|
||||||
extern bool AMI_OVERRIDE; /* XXX style */
|
extern bool AMI_OVERRIDE; /* XXX style */
|
||||||
|
|
||||||
@ -487,6 +488,16 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
|
|||||||
cacheId);
|
cacheId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* temp table name remapping */
|
||||||
|
if (cacheId == RELNAME)
|
||||||
|
{
|
||||||
|
char *nontemp_relname;
|
||||||
|
|
||||||
|
if ((nontemp_relname =
|
||||||
|
get_temp_rel_by_name(DatumGetPointer(key1))) != NULL)
|
||||||
|
key1 = PointerGetDatum(nontemp_relname);
|
||||||
|
}
|
||||||
|
|
||||||
tp = SearchSysCache(SysCache[cacheId], key1, key2, key3, key4);
|
tp = SearchSysCache(SysCache[cacheId], key1, key2, key3, key4);
|
||||||
if (!HeapTupleIsValid(tp))
|
if (!HeapTupleIsValid(tp))
|
||||||
{
|
{
|
||||||
|
10
src/backend/utils/cache/temprel.c
vendored
10
src/backend/utils/cache/temprel.c
vendored
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.12 1999/09/04 21:45:48 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.13 1999/09/04 22:00:30 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -118,6 +118,8 @@ remove_temp_relation(Oid relid)
|
|||||||
List *l,
|
List *l,
|
||||||
*prev;
|
*prev;
|
||||||
|
|
||||||
|
elog(NOTICE,"oid = %d", relid);
|
||||||
|
|
||||||
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
|
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);
|
||||||
|
|
||||||
prev = NIL;
|
prev = NIL;
|
||||||
@ -126,8 +128,11 @@ remove_temp_relation(Oid relid)
|
|||||||
{
|
{
|
||||||
TempTable *temp_rel = lfirst(l);
|
TempTable *temp_rel = lfirst(l);
|
||||||
|
|
||||||
|
elog(NOTICE,"check oid = %d", temp_rel->relid);
|
||||||
|
|
||||||
if (temp_rel->relid == relid)
|
if (temp_rel->relid == relid)
|
||||||
{
|
{
|
||||||
|
elog(NOTICE,"removed");
|
||||||
pfree(temp_rel->user_relname);
|
pfree(temp_rel->user_relname);
|
||||||
pfree(temp_rel->relname);
|
pfree(temp_rel->relname);
|
||||||
pfree(temp_rel);
|
pfree(temp_rel);
|
||||||
@ -212,7 +217,10 @@ get_temp_rel_by_name(char *user_relname)
|
|||||||
TempTable *temp_rel = lfirst(l);
|
TempTable *temp_rel = lfirst(l);
|
||||||
|
|
||||||
if (strcmp(temp_rel->user_relname, user_relname) == 0)
|
if (strcmp(temp_rel->user_relname, user_relname) == 0)
|
||||||
|
{
|
||||||
|
elog(NOTICE,"found");
|
||||||
return temp_rel->relname;
|
return temp_rel->relname;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user