aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2018-10-23 14:45:29 +0200
committerPeter Eisentraut <peter_e@gmx.net>2018-10-23 14:47:14 +0200
commit5d7c703a44101f0d686fb66f4ff671429f46a84c (patch)
tree2b101e37b1756b229a4b3da3a9c4dacb9381e696 /src
parentc903bb7b1c3ce82e21d6bd1af1dc45a58cd88455 (diff)
downloadpostgresql-5d7c703a44101f0d686fb66f4ff671429f46a84c.tar.gz
postgresql-5d7c703a44101f0d686fb66f4ff671429f46a84c.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/tablecmds.c15
-rw-r--r--src/backend/parser/parse_utilcmd.c5
-rw-r--r--src/backend/utils/cache/lsyscache.c32
-rw-r--r--src/include/utils/lsyscache.h1
4 files changed, 12 insertions, 41 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 3e112b4ef42..153aec263ef 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5917,6 +5917,7 @@ static ObjectAddress
ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
{
HeapTuple tuple;
+ Form_pg_attribute attTup;
AttrNumber attnum;
Relation attr_rel;
List *indexoidlist;
@@ -5929,14 +5930,13 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
attr_rel = heap_open(AttributeRelationId, RowExclusiveLock);
tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName);
-
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" of relation \"%s\" does not exist",
colName, RelationGetRelationName(rel))));
-
- attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum;
+ attTup = (Form_pg_attribute) GETSTRUCT(tuple);
+ attnum = attTup->attnum;
/* Prevent them from altering a system attribute */
if (attnum <= 0)
@@ -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 (attTup->attidentity)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("column \"%s\" of relation \"%s\" is an identity column",
@@ -6014,9 +6014,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
/*
* Okay, actually perform the catalog change ... if needed
*/
- if (((Form_pg_attribute) GETSTRUCT(tuple))->attnotnull)
+ if (attTup->attnotnull)
{
- ((Form_pg_attribute) GETSTRUCT(tuple))->attnotnull = false;
+ attTup->attnotnull = false;
CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple);
@@ -6128,6 +6128,7 @@ static ObjectAddress
ATExecColumnDefault(Relation rel, const char *colName,
Node *newDefault, LOCKMODE lockmode)
{
+ TupleDesc tupdesc = RelationGetDescr(rel);
AttrNumber attnum;
ObjectAddress address;
@@ -6148,7 +6149,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
errmsg("cannot alter system column \"%s\"",
colName)));
- if (get_attidentity(RelationGetRelid(rel), attnum))
+ if (TupleDescAttr(tupdesc, 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 d8387d43569..a6a2de94ea4 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -2919,6 +2919,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
const char *queryString)
{
Relation rel;
+ TupleDesc tupdesc;
ParseState *pstate;
CreateStmtContext cxt;
List *result;
@@ -2938,6 +2939,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
/* Caller is responsible for locking the relation */
rel = relation_open(relid, NoLock);
+ tupdesc = RelationGetDescr(rel);
/* Set up pstate */
pstate = make_parsestate(NULL);
@@ -3067,7 +3069,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(tupdesc, 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 c53bda98671..892ddc0d486 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -822,38 +822,6 @@ get_attnum(Oid relid, const char *attname)
}
/*
- * 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
*
* Given the relation OID and the attribute number with the relation,
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index 23ed5324b5b..ff1705ad2b8 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 void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
Oid *typid, int32 *typmod, Oid *collid);