Commit 5d7c703a authored by Peter Eisentraut's avatar Peter Eisentraut

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: default avatarMichael Paquier <michael@paquier.xyz>
parent c903bb7b
...@@ -5917,6 +5917,7 @@ static ObjectAddress ...@@ -5917,6 +5917,7 @@ static ObjectAddress
ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
{ {
HeapTuple tuple; HeapTuple tuple;
Form_pg_attribute attTup;
AttrNumber attnum; AttrNumber attnum;
Relation attr_rel; Relation attr_rel;
List *indexoidlist; List *indexoidlist;
...@@ -5929,14 +5930,13 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) ...@@ -5929,14 +5930,13 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
attr_rel = heap_open(AttributeRelationId, RowExclusiveLock); attr_rel = heap_open(AttributeRelationId, RowExclusiveLock);
tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName); tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN), (errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" of relation \"%s\" does not exist", errmsg("column \"%s\" of relation \"%s\" does not exist",
colName, RelationGetRelationName(rel)))); colName, RelationGetRelationName(rel))));
attTup = (Form_pg_attribute) GETSTRUCT(tuple);
attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum; attnum = attTup->attnum;
/* Prevent them from altering a system attribute */ /* Prevent them from altering a system attribute */
if (attnum <= 0) if (attnum <= 0)
...@@ -5945,7 +5945,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) ...@@ -5945,7 +5945,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
errmsg("cannot alter system column \"%s\"", errmsg("cannot alter system column \"%s\"",
colName))); colName)));
if (get_attidentity(RelationGetRelid(rel), attnum)) if (attTup->attidentity)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("column \"%s\" of relation \"%s\" is an identity column", errmsg("column \"%s\" of relation \"%s\" is an identity column",
...@@ -6014,9 +6014,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) ...@@ -6014,9 +6014,9 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
/* /*
* Okay, actually perform the catalog change ... if needed * 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); CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple);
...@@ -6128,6 +6128,7 @@ static ObjectAddress ...@@ -6128,6 +6128,7 @@ static ObjectAddress
ATExecColumnDefault(Relation rel, const char *colName, ATExecColumnDefault(Relation rel, const char *colName,
Node *newDefault, LOCKMODE lockmode) Node *newDefault, LOCKMODE lockmode)
{ {
TupleDesc tupdesc = RelationGetDescr(rel);
AttrNumber attnum; AttrNumber attnum;
ObjectAddress address; ObjectAddress address;
...@@ -6148,7 +6149,7 @@ ATExecColumnDefault(Relation rel, const char *colName, ...@@ -6148,7 +6149,7 @@ ATExecColumnDefault(Relation rel, const char *colName,
errmsg("cannot alter system column \"%s\"", errmsg("cannot alter system column \"%s\"",
colName))); colName)));
if (get_attidentity(RelationGetRelid(rel), attnum)) if (TupleDescAttr(tupdesc, attnum - 1)->attidentity)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("column \"%s\" of relation \"%s\" is an identity column", errmsg("column \"%s\" of relation \"%s\" is an identity column",
......
...@@ -2919,6 +2919,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, ...@@ -2919,6 +2919,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
const char *queryString) const char *queryString)
{ {
Relation rel; Relation rel;
TupleDesc tupdesc;
ParseState *pstate; ParseState *pstate;
CreateStmtContext cxt; CreateStmtContext cxt;
List *result; List *result;
...@@ -2938,6 +2939,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, ...@@ -2938,6 +2939,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
/* Caller is responsible for locking the relation */ /* Caller is responsible for locking the relation */
rel = relation_open(relid, NoLock); rel = relation_open(relid, NoLock);
tupdesc = RelationGetDescr(rel);
/* Set up pstate */ /* Set up pstate */
pstate = make_parsestate(NULL); pstate = make_parsestate(NULL);
...@@ -3067,7 +3069,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, ...@@ -3067,7 +3069,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
* if attribute not found, something will error about it * if attribute not found, something will error about it
* later * later
*/ */
if (attnum != InvalidAttrNumber && get_attidentity(relid, attnum)) if (attnum != InvalidAttrNumber &&
TupleDescAttr(tupdesc, attnum - 1)->attidentity)
{ {
Oid seq_relid = getOwnedSequence(relid, attnum); Oid seq_relid = getOwnedSequence(relid, attnum);
Oid typeOid = typenameTypeId(pstate, def->typeName); Oid typeOid = typenameTypeId(pstate, def->typeName);
......
...@@ -821,38 +821,6 @@ get_attnum(Oid relid, const char *attname) ...@@ -821,38 +821,6 @@ get_attnum(Oid relid, const char *attname)
return InvalidAttrNumber; 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 * get_atttype
* *
......
...@@ -85,7 +85,6 @@ extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, ...@@ -85,7 +85,6 @@ extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype,
int16 procnum); int16 procnum);
extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok); extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok);
extern AttrNumber get_attnum(Oid relid, const char *attname); 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 Oid get_atttype(Oid relid, AttrNumber attnum);
extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
Oid *typid, int32 *typmod, Oid *collid); Oid *typid, int32 *typmod, Oid *collid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment