summaryrefslogtreecommitdiff
path: root/src/backend/tcop/utility.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2012-01-06 22:42:26 -0500
committerRobert Haas <rhaas@postgresql.org>2012-01-06 22:42:26 -0500
commit1489e2f26a4c0318938b3085f50976512f321d84 (patch)
treebc26ed1939cc2239a302e7c387efefe55550835d /src/backend/tcop/utility.c
parent33aaa139e6302e81b4fbf2570be20188bb974c4f (diff)
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.
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r--src/backend/tcop/utility.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 704bbe9cedf..de16a61454b 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -699,12 +699,23 @@ standard_ProcessUtility(Node *parsetree,
case T_AlterTableStmt:
{
+ AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
+ Oid relid;
List *stmts;
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 ... */
- stmts = transformAlterTableStmt((AlterTableStmt *) parsetree,
- queryString);
+ stmts = transformAlterTableStmt(atstmt, queryString);
/* ... and do it */
foreach(l, stmts)
@@ -714,7 +725,7 @@ standard_ProcessUtility(Node *parsetree,
if (IsA(stmt, AlterTableStmt))
{
/* Do the table alteration proper */
- AlterTable((AlterTableStmt *) stmt);
+ AlterTable(relid, lockmode, (AlterTableStmt *) stmt);
}
else
{