Skip to content

Commit 9bb842f

Browse files
author
Richard Guo
committed
Small code simplification
Apply the same code simplification to ATExecAddColumn as was done in 7ff9afb: apply GETSTRUCT() once instead of doing it repeatedly in the same function. Author: Tender Wang Discussion: https://postgr.es/m/CAHewXNkO9+U437jvKT14s0MCu6Qpf6G-p2mZK5J9mAi4cHDgpQ@mail.gmail.com
1 parent 490f869 commit 9bb842f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/commands/tablecmds.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -7028,6 +7028,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
70287028
Relation pgclass,
70297029
attrdesc;
70307030
HeapTuple reltup;
7031+
Form_pg_class relform;
70317032
Form_pg_attribute attribute;
70327033
int newattnum;
70337034
char relkind;
@@ -7161,10 +7162,11 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
71617162
reltup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(myrelid));
71627163
if (!HeapTupleIsValid(reltup))
71637164
elog(ERROR, "cache lookup failed for relation %u", myrelid);
7164-
relkind = ((Form_pg_class) GETSTRUCT(reltup))->relkind;
7165+
relform = (Form_pg_class) GETSTRUCT(reltup);
7166+
relkind = relform->relkind;
71657167

71667168
/* Determine the new attribute's number */
7167-
newattnum = ((Form_pg_class) GETSTRUCT(reltup))->relnatts + 1;
7169+
newattnum = relform->relnatts + 1;
71687170
if (newattnum > MaxHeapAttributeNumber)
71697171
ereport(ERROR,
71707172
(errcode(ERRCODE_TOO_MANY_COLUMNS),
@@ -7193,7 +7195,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
71937195
/*
71947196
* Update pg_class tuple as appropriate
71957197
*/
7196-
((Form_pg_class) GETSTRUCT(reltup))->relnatts = newattnum;
7198+
relform->relnatts = newattnum;
71977199

71987200
CatalogTupleUpdate(pgclass, &reltup->t_self, reltup);
71997201

0 commit comments

Comments
 (0)