From cbe24a6dd8fb224b9585f25b882d5ffdb55a0ba5 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Wed, 21 Dec 2011 15:17:28 -0500 Subject: Improve behavior of concurrent CLUSTER. In the previous coding, a user could queue up for an AccessExclusiveLock on a table they did not have permission to cluster, thus potentially interfering with access by authorized users who got stuck waiting behind the AccessExclusiveLock. This approach avoids that. cluster() has the same permissions-checking requirements as REINDEX TABLE, so this commit moves the now-shared callback to tablecmds.c and renames it, per discussion with Noah Misch. --- src/backend/commands/cluster.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/backend/commands/cluster.c') diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index e805e28a39e..997c1bde6b5 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -25,6 +25,7 @@ #include "catalog/dependency.h" #include "catalog/heap.h" #include "catalog/index.h" +#include "catalog/namespace.h" #include "catalog/toasting.h" #include "commands/cluster.h" #include "commands/tablecmds.h" @@ -106,15 +107,12 @@ cluster(ClusterStmt *stmt, bool isTopLevel) indexOid = InvalidOid; Relation rel; - /* Find and lock the table */ - rel = heap_openrv(stmt->relation, AccessExclusiveLock); - - tableOid = RelationGetRelid(rel); - - /* Check permissions */ - if (!pg_class_ownercheck(tableOid, GetUserId())) - aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS, - RelationGetRelationName(rel)); + /* Find, lock, and check permissions on the table */ + tableOid = RangeVarGetRelidExtended(stmt->relation, + AccessExclusiveLock, + false, false, + RangeVarCallbackOwnsTable, NULL); + rel = heap_open(tableOid, NoLock); /* * Reject clustering a remote temp table ... their local buffer -- cgit v1.2.3