From 2003c5b4fdad1cd444ddb1fad2bdc9ab09db2fd2 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 18 Oct 2018 19:27:18 +0200 Subject: [PATCH 1/2] 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. --- src/backend/commands/tablecmds.c | 4 ++-- src/backend/parser/parse_utilcmd.c | 3 ++- src/backend/utils/cache/lsyscache.c | 32 ----------------------------- src/include/utils/lsyscache.h | 1 - 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 3e112b4ef4..7ff25a9eff 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -5945,7 +5945,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) errmsg("cannot alter system column \"%s\"", colName))); - if (get_attidentity(RelationGetRelid(rel), attnum)) + if (TupleDescAttr(RelationGetDescr(rel), attnum - 1)->attidentity) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("column \"%s\" of relation \"%s\" is an identity column", @@ -6148,7 +6148,7 @@ ATExecColumnDefault(Relation rel, const char *colName, errmsg("cannot alter system column \"%s\"", colName))); - if (get_attidentity(RelationGetRelid(rel), attnum)) + if (TupleDescAttr(RelationGetDescr(rel), attnum - 1)->attidentity) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("column \"%s\" of relation \"%s\" is an identity column", diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index d8387d4356..212eedfa87 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3067,7 +3067,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, * if attribute not found, something will error about it * later */ - if (attnum != InvalidAttrNumber && get_attidentity(relid, attnum)) + if (attnum != InvalidAttrNumber && + TupleDescAttr(RelationGetDescr(rel), attnum - 1)->attidentity) { Oid seq_relid = getOwnedSequence(relid, attnum); Oid typeOid = typenameTypeId(pstate, def->typeName); diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 12b2532d95..c5fcaa9542 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -821,38 +821,6 @@ get_attnum(Oid relid, const char *attname) return InvalidAttrNumber; } -/* - * get_attidentity - * - * Given the relation id and the attribute name, - * return the "attidentity" field from the attribute relation. - * - * Returns '\0' if not found. - * - * Since no identity is represented by '\0', this can also be used as a - * Boolean test. - */ -char -get_attidentity(Oid relid, AttrNumber attnum) -{ - HeapTuple tp; - - tp = SearchSysCache2(ATTNUM, - ObjectIdGetDatum(relid), - Int16GetDatum(attnum)); - if (HeapTupleIsValid(tp)) - { - Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp); - char result; - - result = att_tup->attidentity; - ReleaseSysCache(tp); - return result; - } - else - return '\0'; -} - /* * get_atttype * diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8c57de77c0..151081c693 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -85,7 +85,6 @@ extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum); extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok); extern AttrNumber get_attnum(Oid relid, const char *attname); -extern char get_attidentity(Oid relid, AttrNumber attnum); extern Oid get_atttype(Oid relid, AttrNumber attnum); extern int32 get_atttypmod(Oid relid, AttrNumber attnum); extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, base-commit: a7a1b44516e7db89104c06440f759c2831fcb0ff -- 2.19.1