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

Commitc59839a

Browse files
committed
Consolidate tables of known system attributes into one table.
1 parentb00c6c8 commitc59839a

File tree

3 files changed

+47
-70
lines changed

3 files changed

+47
-70
lines changed

‎src/backend/catalog/heap.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.177 2001/10/06 23:21:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.178 2001/10/22 22:47:57 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -151,6 +151,7 @@ static Form_pg_attribute SysAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6, &a7};
151151

152152
/*
153153
* This function returns a Form_pg_attribute pointer for a system attribute.
154+
* Note that we elog if the presented attno is invalid.
154155
*/
155156
Form_pg_attribute
156157
SystemAttributeDefinition(AttrNumberattno,boolrelhasoids)
@@ -164,6 +165,30 @@ SystemAttributeDefinition(AttrNumber attno, bool relhasoids)
164165
returnSysAtt[-attno-1];
165166
}
166167

168+
/*
169+
* If the given name is a system attribute name, return a Form_pg_attribute
170+
* pointer for a prototype definition. If not, return NULL.
171+
*/
172+
Form_pg_attribute
173+
SystemAttributeByName(constchar*attname,boolrelhasoids)
174+
{
175+
intj;
176+
177+
for (j=0;j< (int)lengthof(SysAtt);j++)
178+
{
179+
Form_pg_attributeatt=SysAtt[j];
180+
181+
if (relhasoids||att->attnum!=ObjectIdAttributeNumber)
182+
{
183+
if (strcmp(NameStr(att->attname),attname)==0)
184+
returnatt;
185+
}
186+
}
187+
188+
returnNULL;
189+
}
190+
191+
167192
/* ----------------------------------------------------------------
168193
*XXX END OF UGLY HARD CODED BADNESS XXX
169194
* ---------------------------------------------------------------- */
@@ -350,16 +375,10 @@ CheckAttributeNames(TupleDesc tupdesc, bool relhasoids)
350375
*/
351376
for (i=0;i<natts;i++)
352377
{
353-
for (j=0;j< (int)lengthof(SysAtt);j++)
354-
{
355-
if (relhasoids||SysAtt[j]->attnum!=ObjectIdAttributeNumber)
356-
{
357-
if (strcmp(NameStr(SysAtt[j]->attname),
358-
NameStr(tupdesc->attrs[i]->attname))==0)
359-
elog(ERROR,"name of column \"%s\" conflicts with an existing system column",
360-
NameStr(SysAtt[j]->attname));
361-
}
362-
}
378+
if (SystemAttributeByName(NameStr(tupdesc->attrs[i]->attname),
379+
relhasoids)!=NULL)
380+
elog(ERROR,"name of column \"%s\" conflicts with an existing system column",
381+
NameStr(tupdesc->attrs[i]->attname));
363382
if (tupdesc->attrs[i]->atttypid==UNKNOWNOID)
364383
elog(NOTICE,"Attribute '%s' has an unknown type"
365384
"\n\tProceeding with relation creation anyway",

‎src/backend/parser/parse_relation.c

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.56 2001/08/10 18:57:37 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.57 2001/10/22 22:47:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -18,6 +18,7 @@
1818

1919
#include"access/heapam.h"
2020
#include"access/htup.h"
21+
#include"catalog/heap.h"
2122
#include"catalog/pg_type.h"
2223
#include"nodes/makefuncs.h"
2324
#include"parser/parsetree.h"
@@ -43,43 +44,6 @@ static intspecialAttNum(char *a);
4344
staticvoidwarnAutoRange(ParseState*pstate,char*refname);
4445

4546

46-
/*
47-
* Information defining the "system" attributes of every relation.
48-
*/
49-
staticstruct
50-
{
51-
char*attrname;/* name of system attribute */
52-
intattrnum;/* its attribute number (always < 0) */
53-
Oidattrtype;/* its type id */
54-
}special_attr[]=
55-
56-
{
57-
{
58-
"ctid",SelfItemPointerAttributeNumber,TIDOID
59-
},
60-
{
61-
"oid",ObjectIdAttributeNumber,OIDOID
62-
},
63-
{
64-
"xmin",MinTransactionIdAttributeNumber,XIDOID
65-
},
66-
{
67-
"cmin",MinCommandIdAttributeNumber,CIDOID
68-
},
69-
{
70-
"xmax",MaxTransactionIdAttributeNumber,XIDOID
71-
},
72-
{
73-
"cmax",MaxCommandIdAttributeNumber,CIDOID
74-
},
75-
{
76-
"tableoid",TableOidAttributeNumber,OIDOID
77-
}
78-
};
79-
80-
#defineSPECIALS ((int) lengthof(special_attr))
81-
82-
8347
/*
8448
* refnameRangeOrJoinEntry
8549
* Given a refname, look to see if it matches any RTE or join table.
@@ -1001,39 +965,31 @@ attnameAttNum(Relation rd, char *a)
1001965
staticint
1002966
specialAttNum(char*a)
1003967
{
1004-
inti;
1005-
1006-
for (i=0;i<SPECIALS;i++)
1007-
if (strcmp(special_attr[i].attrname,a)==0)
1008-
returnspecial_attr[i].attrnum;
968+
Form_pg_attributesysatt;
1009969

970+
sysatt=SystemAttributeByName(a, true/* "oid" will be accepted */);
971+
if (sysatt!=NULL)
972+
returnsysatt->attnum;
1010973
returnInvalidAttrNumber;
1011974
}
1012975

1013976

1014-
/* given attribute id, return type of that attribute */
1015977
/*
978+
* given attribute id, return type of that attribute
979+
*
1016980
*This should only be used if the relation is already
1017981
*heap_open()'ed. Use the cache version get_atttype()
1018982
*for access to non-opened relations.
1019-
*
1020-
* Note: we don't bother to check rd->rd_rel->relhasoids; we assume that
1021-
* the caller will only ask about OID if that column has been found valid.
1022983
*/
1023984
Oid
1024985
attnumTypeId(Relationrd,intattid)
1025986
{
1026-
if (attid<0)
987+
if (attid <=0)
1027988
{
1028-
inti;
989+
Form_pg_attributesysatt;
1029990

1030-
for (i=0;i<SPECIALS;i++)
1031-
{
1032-
if (special_attr[i].attrnum==attid)
1033-
returnspecial_attr[i].attrtype;
1034-
}
1035-
/* negative but not a valid system attr? */
1036-
elog(ERROR,"attnumTypeId: bogus attribute number %d",attid);
991+
sysatt=SystemAttributeDefinition(attid,rd->rd_rel->relhasoids);
992+
returnsysatt->atttypid;
1037993
}
1038994

1039995
/*

‎src/include/catalog/heap.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*-------------------------------------------------------------------------
22
*
33
* heap.h
4-
* prototypes for functions inlib/catalog/heap.c
4+
* prototypes for functions inbackend/catalog/heap.c
55
*
66
*
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: heap.h,v 1.37 2001/08/10 18:57:39 tgl Exp $
10+
* $Id: heap.h,v 1.38 2001/10/22 22:47:57 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -47,8 +47,10 @@ extern void AddRelationRawConstraints(Relation rel,
4747

4848
externintRemoveCheckConstraint(Relationrel,constchar*constrName,boolinh);
4949

50-
5150
externForm_pg_attributeSystemAttributeDefinition(AttrNumberattno,
5251
boolrelhasoids);
5352

53+
externForm_pg_attributeSystemAttributeByName(constchar*attname,
54+
boolrelhasoids);
55+
5456
#endif/* HEAP_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp