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

Commit5d7c703

Browse files
committed
Remove get_attidentity()
All existing uses can get this information more easily from therelation descriptor, so the detour through the syscache is notnecessary.Reviewed-by: Michael Paquier <michael@paquier.xyz>
1 parentc903bb7 commit5d7c703

File tree

4 files changed

+12
-41
lines changed

4 files changed

+12
-41
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5917,6 +5917,7 @@ static ObjectAddress
59175917
ATExecDropNotNull(Relationrel,constchar*colName,LOCKMODElockmode)
59185918
{
59195919
HeapTupletuple;
5920+
Form_pg_attributeattTup;
59205921
AttrNumberattnum;
59215922
Relationattr_rel;
59225923
List*indexoidlist;
@@ -5929,14 +5930,13 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
59295930
attr_rel=heap_open(AttributeRelationId,RowExclusiveLock);
59305931

59315932
tuple=SearchSysCacheCopyAttName(RelationGetRelid(rel),colName);
5932-
59335933
if (!HeapTupleIsValid(tuple))
59345934
ereport(ERROR,
59355935
(errcode(ERRCODE_UNDEFINED_COLUMN),
59365936
errmsg("column \"%s\" of relation \"%s\" does not exist",
59375937
colName,RelationGetRelationName(rel))));
5938-
5939-
attnum=((Form_pg_attribute)GETSTRUCT(tuple))->attnum;
5938+
attTup= (Form_pg_attribute)GETSTRUCT(tuple);
5939+
attnum=attTup->attnum;
59405940

59415941
/* Prevent them from altering a system attribute */
59425942
if (attnum <=0)
@@ -5945,7 +5945,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
59455945
errmsg("cannot alter system column \"%s\"",
59465946
colName)));
59475947

5948-
if (get_attidentity(RelationGetRelid(rel),attnum))
5948+
if (attTup->attidentity)
59495949
ereport(ERROR,
59505950
(errcode(ERRCODE_SYNTAX_ERROR),
59515951
errmsg("column \"%s\" of relation \"%s\" is an identity column",
@@ -6014,9 +6014,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
60146014
/*
60156015
* Okay, actually perform the catalog change ... if needed
60166016
*/
6017-
if (((Form_pg_attribute)GETSTRUCT(tuple))->attnotnull)
6017+
if (attTup->attnotnull)
60186018
{
6019-
((Form_pg_attribute)GETSTRUCT(tuple))->attnotnull= false;
6019+
attTup->attnotnull= false;
60206020

60216021
CatalogTupleUpdate(attr_rel,&tuple->t_self,tuple);
60226022

@@ -6128,6 +6128,7 @@ static ObjectAddress
61286128
ATExecColumnDefault(Relationrel,constchar*colName,
61296129
Node*newDefault,LOCKMODElockmode)
61306130
{
6131+
TupleDesctupdesc=RelationGetDescr(rel);
61316132
AttrNumberattnum;
61326133
ObjectAddressaddress;
61336134

@@ -6148,7 +6149,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
61486149
errmsg("cannot alter system column \"%s\"",
61496150
colName)));
61506151

6151-
if (get_attidentity(RelationGetRelid(rel),attnum))
6152+
if (TupleDescAttr(tupdesc,attnum-1)->attidentity)
61526153
ereport(ERROR,
61536154
(errcode(ERRCODE_SYNTAX_ERROR),
61546155
errmsg("column \"%s\" of relation \"%s\" is an identity column",

‎src/backend/parser/parse_utilcmd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
29192919
constchar*queryString)
29202920
{
29212921
Relationrel;
2922+
TupleDesctupdesc;
29222923
ParseState*pstate;
29232924
CreateStmtContextcxt;
29242925
List*result;
@@ -2938,6 +2939,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
29382939

29392940
/* Caller is responsible for locking the relation */
29402941
rel=relation_open(relid,NoLock);
2942+
tupdesc=RelationGetDescr(rel);
29412943

29422944
/* Set up pstate */
29432945
pstate=make_parsestate(NULL);
@@ -3067,7 +3069,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
30673069
* if attribute not found, something will error about it
30683070
* later
30693071
*/
3070-
if (attnum!=InvalidAttrNumber&&get_attidentity(relid,attnum))
3072+
if (attnum!=InvalidAttrNumber&&
3073+
TupleDescAttr(tupdesc,attnum-1)->attidentity)
30713074
{
30723075
Oidseq_relid=getOwnedSequence(relid,attnum);
30733076
OidtypeOid=typenameTypeId(pstate,def->typeName);

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -821,38 +821,6 @@ get_attnum(Oid relid, const char *attname)
821821
returnInvalidAttrNumber;
822822
}
823823

824-
/*
825-
* get_attidentity
826-
*
827-
*Given the relation id and the attribute name,
828-
*return the "attidentity" field from the attribute relation.
829-
*
830-
*Returns '\0' if not found.
831-
*
832-
*Since no identity is represented by '\0', this can also be used as a
833-
*Boolean test.
834-
*/
835-
char
836-
get_attidentity(Oidrelid,AttrNumberattnum)
837-
{
838-
HeapTupletp;
839-
840-
tp=SearchSysCache2(ATTNUM,
841-
ObjectIdGetDatum(relid),
842-
Int16GetDatum(attnum));
843-
if (HeapTupleIsValid(tp))
844-
{
845-
Form_pg_attributeatt_tup= (Form_pg_attribute)GETSTRUCT(tp);
846-
charresult;
847-
848-
result=att_tup->attidentity;
849-
ReleaseSysCache(tp);
850-
returnresult;
851-
}
852-
else
853-
return'\0';
854-
}
855-
856824
/*
857825
* get_atttype
858826
*

‎src/include/utils/lsyscache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype,
8585
int16procnum);
8686
externchar*get_attname(Oidrelid,AttrNumberattnum,boolmissing_ok);
8787
externAttrNumberget_attnum(Oidrelid,constchar*attname);
88-
externcharget_attidentity(Oidrelid,AttrNumberattnum);
8988
externOidget_atttype(Oidrelid,AttrNumberattnum);
9089
externvoidget_atttypetypmodcoll(Oidrelid,AttrNumberattnum,
9190
Oid*typid,int32*typmod,Oid*collid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp