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

Commit996659f

Browse files
committed
Fix handling of type tuple associated with a temp relation. We have
to apply the tempname->realname mapping to type name lookup as wellas relation name lookup, else the type tuple will not be found whenwanted. This fixes bugs like this one:create temp table foo (f1 int);select foo.f2 from foo;ERROR: Unable to locate type name 'foo' in catalog
1 parenta1dfaef commit996659f

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

‎src/backend/parser/parse_relation.c

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.43 2000/06/12 19:40:42 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.44 2000/06/20 01:41:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include<ctype.h>
1616

1717
#include"postgres.h"
18+
1819
#include"access/heapam.h"
1920
#include"access/htup.h"
2021
#include"catalog/pg_type.h"
@@ -27,43 +28,39 @@
2728
#include"utils/lsyscache.h"
2829

2930

31+
/*
32+
* Information defining the "system" attributes of every relation.
33+
*/
3034
staticstruct
3135
{
32-
char*field;
33-
intcode;
36+
char*attrname;/* name of system attribute */
37+
intattrnum;/* its attribute number (always < 0) */
38+
Oidattrtype;/* its type id */
3439
}special_attr[]=
3540

3641
{
3742
{
38-
"ctid",SelfItemPointerAttributeNumber
43+
"ctid",SelfItemPointerAttributeNumber,TIDOID
3944
},
4045
{
41-
"oid",ObjectIdAttributeNumber
46+
"oid",ObjectIdAttributeNumber,OIDOID
4247
},
4348
{
44-
"xmin",MinTransactionIdAttributeNumber
49+
"xmin",MinTransactionIdAttributeNumber,XIDOID
4550
},
4651
{
47-
"cmin",MinCommandIdAttributeNumber
52+
"cmin",MinCommandIdAttributeNumber,CIDOID
4853
},
4954
{
50-
"xmax",MaxTransactionIdAttributeNumber
55+
"xmax",MaxTransactionIdAttributeNumber,XIDOID
5156
},
5257
{
53-
"cmax",MaxCommandIdAttributeNumber
58+
"cmax",MaxCommandIdAttributeNumber,CIDOID
5459
},
5560
};
5661

57-
#defineSPECIALS ((int) (sizeof(special_attr)/sizeof(*special_attr)))
62+
#defineSPECIALS ((int) (sizeof(special_attr)/sizeof(special_attr[0])))
5863

59-
staticchar*attnum_type[SPECIALS]= {
60-
"tid",
61-
"oid",
62-
"xid",
63-
"cid",
64-
"xid",
65-
"cid",
66-
};
6764

6865
#ifdefNOT_USED
6966
/* refnameRangeTableEntries()
@@ -459,8 +456,8 @@ specialAttNum(char *a)
459456
inti;
460457

461458
for (i=0;i<SPECIALS;i++)
462-
if (!strcmp(special_attr[i].field,a))
463-
returnspecial_attr[i].code;
459+
if (strcmp(special_attr[i].attrname,a)==0)
460+
returnspecial_attr[i].attrnum;
464461

465462
returnInvalidAttrNumber;
466463
}
@@ -485,10 +482,8 @@ attnameIsSet(Relation rd, char *name)
485482
/* First check if this is a system attribute */
486483
for (i=0;i<SPECIALS;i++)
487484
{
488-
if (!strcmp(special_attr[i].field,name))
489-
{
485+
if (strcmp(special_attr[i].attrname,name)==0)
490486
return false;/* no sys attr is a set */
491-
}
492487
}
493488
returnget_attisset(RelationGetRelid(rd),name);
494489
}
@@ -516,13 +511,21 @@ attnumAttNelems(Relation rd, int attid)
516511
Oid
517512
attnumTypeId(Relationrd,intattid)
518513
{
519-
520514
if (attid<0)
521-
returntypeTypeId(typenameType(attnum_type[-attid-1]));
515+
{
516+
inti;
517+
518+
for (i=0;i<SPECIALS;i++)
519+
{
520+
if (special_attr[i].attrnum==attid)
521+
returnspecial_attr[i].attrtype;
522+
}
523+
/* negative but not a valid system attr? */
524+
elog(ERROR,"attnumTypeId: bogus attribute number %d",attid);
525+
}
522526

523527
/*
524-
* -1 because varattno (where attid comes from) returns one more than
525-
* index
528+
* -1 because attid is 1-based
526529
*/
527530
returnrd->rd_att->attrs[attid-1]->atttypid;
528531
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.54 2000/06/17 04:56:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.55 2000/06/20 01:41:22 tgl Exp $
1212
*
1313
* NOTES
1414
* These routines allow the parser/planner/executor to perform
@@ -482,14 +482,20 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
482482
cacheId);
483483
}
484484

485-
/* temp table name remapping */
486-
if (cacheId==RELNAME)
485+
/*
486+
* If someone tries to look up a relname, translate temp relation
487+
* names to real names. Less obviously, apply the same translation
488+
* to type names, so that the type tuple of a temp table will be found
489+
* when sought. This is a kluge ... temp table substitution should be
490+
* happening at a higher level ...
491+
*/
492+
if (cacheId==RELNAME||cacheId==TYPENAME)
487493
{
488494
char*nontemp_relname;
489495

490-
if ((nontemp_relname=
491-
get_temp_rel_by_username(DatumGetPointer(key1)))!=NULL)
492-
key1=PointerGetDatum(nontemp_relname);
496+
nontemp_relname=get_temp_rel_by_username(DatumGetCString(key1));
497+
if (nontemp_relname!=NULL)
498+
key1=CStringGetDatum(nontemp_relname);
493499
}
494500

495501
tp=SearchSysCache(SysCache[cacheId],key1,key2,key3,key4);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp