From c14299fd45175c0b8db7cdef380b95d8106eb0a0 Mon Sep 17 00:00:00 2001 From: Tender Wang Date: Wed, 21 Aug 2024 18:13:53 +0800 Subject: [PATCH v1] Small code simplification Oversight in 7ff9afbbd, we can do the same way for ATExecAddColumn(). --- src/backend/commands/tablecmds.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index dfba5f357b..4f410f3213 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7029,6 +7029,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, attrdesc; HeapTuple reltup; Form_pg_attribute attribute; + Form_pg_class relform; int newattnum; char relkind; Expr *defval; @@ -7161,10 +7162,11 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, reltup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(myrelid)); if (!HeapTupleIsValid(reltup)) elog(ERROR, "cache lookup failed for relation %u", myrelid); - relkind = ((Form_pg_class) GETSTRUCT(reltup))->relkind; + relform = (Form_pg_class) GETSTRUCT(reltup); + relkind = relform->relkind; /* Determine the new attribute's number */ - newattnum = ((Form_pg_class) GETSTRUCT(reltup))->relnatts + 1; + newattnum = relform->relnatts + 1; if (newattnum > MaxHeapAttributeNumber) ereport(ERROR, (errcode(ERRCODE_TOO_MANY_COLUMNS), @@ -7193,7 +7195,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, /* * Update pg_class tuple as appropriate */ - ((Form_pg_class) GETSTRUCT(reltup))->relnatts = newattnum; + relform->relnatts = newattnum; CatalogTupleUpdate(pgclass, &reltup->t_self, reltup); -- 2.34.1