Commit 1489e2f2 authored by Robert Haas's avatar Robert Haas

Improve behavior of concurrent ALTER TABLE, and do some refactoring.

ALTER TABLE (and ALTER VIEW, ALTER SEQUENCE, etc.) now use a
RangeVarGetRelid callback to check permissions before acquiring a table
lock.  We also now use the same callback for all forms of ALTER TABLE,
rather than having separate, almost-identical callbacks for ALTER TABLE
.. SET SCHEMA and ALTER TABLE .. RENAME, and no callback at all for
everything else.

I went ahead and changed the code so that no form of ALTER TABLE works
on foreign tables; you must use ALTER FOREIGN TABLE instead.  In 9.1,
it was possible to use ALTER TABLE .. SET SCHEMA or ALTER TABLE ..
RENAME on a foreign table, but not any other form of ALTER TABLE, which
did not seem terribly useful or consistent.

Patch by me; review by Noah Misch.
parent 33aaa139
...@@ -192,8 +192,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) ...@@ -192,8 +192,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
case OBJECT_TABLE: case OBJECT_TABLE:
case OBJECT_VIEW: case OBJECT_VIEW:
case OBJECT_FOREIGN_TABLE: case OBJECT_FOREIGN_TABLE:
AlterTableNamespace(stmt->relation, stmt->newschema, AlterTableNamespace(stmt);
stmt->objectType, AccessExclusiveLock);
break; break;
case OBJECT_TSPARSER: case OBJECT_TSPARSER:
......
This diff is collapsed.
...@@ -699,12 +699,23 @@ standard_ProcessUtility(Node *parsetree, ...@@ -699,12 +699,23 @@ standard_ProcessUtility(Node *parsetree,
case T_AlterTableStmt: case T_AlterTableStmt:
{ {
AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
Oid relid;
List *stmts; List *stmts;
ListCell *l; ListCell *l;
LOCKMODE lockmode;
/*
* Figure out lock mode, and acquire lock. This also does
* basic permissions checks, so that we won't wait for a lock
* on (for example) a relation on which we have no
* permissions.
*/
lockmode = AlterTableGetLockLevel(atstmt->cmds);
relid = AlterTableLookupRelation(atstmt, lockmode);
/* Run parse analysis ... */ /* Run parse analysis ... */
stmts = transformAlterTableStmt((AlterTableStmt *) parsetree, stmts = transformAlterTableStmt(atstmt, queryString);
queryString);
/* ... and do it */ /* ... and do it */
foreach(l, stmts) foreach(l, stmts)
...@@ -714,7 +725,7 @@ standard_ProcessUtility(Node *parsetree, ...@@ -714,7 +725,7 @@ standard_ProcessUtility(Node *parsetree,
if (IsA(stmt, AlterTableStmt)) if (IsA(stmt, AlterTableStmt))
{ {
/* Do the table alteration proper */ /* Do the table alteration proper */
AlterTable((AlterTableStmt *) stmt); AlterTable(relid, lockmode, (AlterTableStmt *) stmt);
} }
else else
{ {
......
...@@ -24,7 +24,9 @@ extern Oid DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId); ...@@ -24,7 +24,9 @@ extern Oid DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId);
extern void RemoveRelations(DropStmt *drop); extern void RemoveRelations(DropStmt *drop);
extern void AlterTable(AlterTableStmt *stmt); extern Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode);
extern void AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt *stmt);
extern LOCKMODE AlterTableGetLockLevel(List *cmds); extern LOCKMODE AlterTableGetLockLevel(List *cmds);
...@@ -32,8 +34,7 @@ extern void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, L ...@@ -32,8 +34,7 @@ extern void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, L
extern void AlterTableInternal(Oid relid, List *cmds, bool recurse); extern void AlterTableInternal(Oid relid, List *cmds, bool recurse);
extern void AlterTableNamespace(RangeVar *relation, const char *newschema, extern void AlterTableNamespace(AlterObjectSchemaStmt *stmt);
ObjectType stmttype, LOCKMODE lockmode);
extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid, extern void AlterRelationNamespaceInternal(Relation classRel, Oid relOid,
Oid oldNspOid, Oid newNspOid, Oid oldNspOid, Oid newNspOid,
......
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