1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

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.
This commit is contained in:
Robert Haas
2011-12-21 15:17:28 -05:00
parent d573e239f0
commit cbe24a6dd8
4 changed files with 47 additions and 43 deletions

View File

@ -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