Skip to content

Commit 5d7c703

Browse files
committed
Remove get_attidentity()
All existing uses can get this information more easily from the relation descriptor, so the detour through the syscache is not necessary. Reviewed-by: Michael Paquier <michael@paquier.xyz>
1 parent c903bb7 commit 5d7c703

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(Relation rel, const char *colName, LOCKMODE lockmode)
59185918
{
59195919
HeapTuple tuple;
5920+
Form_pg_attribute attTup;
59205921
AttrNumber attnum;
59215922
Relation attr_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(Relation rel, const char *colName,
61296129
Node *newDefault, LOCKMODE lockmode)
61306130
{
6131+
TupleDesc tupdesc = RelationGetDescr(rel);
61316132
AttrNumber attnum;
61326133
ObjectAddress address;
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
const char *queryString)
29202920
{
29212921
Relation rel;
2922+
TupleDesc tupdesc;
29222923
ParseState *pstate;
29232924
CreateStmtContext cxt;
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
Oid seq_relid = getOwnedSequence(relid, attnum);
30733076
Oid typeOid = 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
return InvalidAttrNumber;
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(Oid relid, AttrNumber attnum)
837-
{
838-
HeapTuple tp;
839-
840-
tp = SearchSysCache2(ATTNUM,
841-
ObjectIdGetDatum(relid),
842-
Int16GetDatum(attnum));
843-
if (HeapTupleIsValid(tp))
844-
{
845-
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
846-
char result;
847-
848-
result = att_tup->attidentity;
849-
ReleaseSysCache(tp);
850-
return result;
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
int16 procnum);
8686
extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok);
8787
extern AttrNumber get_attnum(Oid relid, const char *attname);
88-
extern char get_attidentity(Oid relid, AttrNumber attnum);
8988
extern Oid get_atttype(Oid relid, AttrNumber attnum);
9089
extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
9190
Oid *typid, int32 *typmod, Oid *collid);

0 commit comments

Comments
 (0)