From 8f11bb191963026db6904e66c8fcf94bcd15ca51 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 10 Sep 2007 22:02:05 +0000 Subject: Make CLUSTER and REINDEX silently skip remote temp tables in their database-wide editions. Per report from bitsandbytes88 hotmail.com and subsequent discussion. --- src/backend/commands/cluster.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/cluster.c') diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 665c66cad5e..506e3d7894b 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.154 2006/10/04 00:29:50 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.154.2.1 2007/09/10 22:02:05 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -102,6 +102,15 @@ cluster(ClusterStmt *stmt) aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS, RelationGetRelationName(rel)); + /* + * Reject clustering a remote temp table ... their local buffer manager + * is not going to cope. + */ + if (isOtherTempNamespace(RelationGetNamespace(rel))) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot cluster temporary tables of other sessions"))); + if (stmt->indexname == NULL) { ListCell *index; @@ -271,6 +280,21 @@ cluster_rel(RelToCluster *rvtc, bool recheck) return; } + /* + * Silently skip a temp table for a remote session. Only doing this + * check in the "recheck" case is appropriate (which currently means + * somebody is executing a database-wide CLUSTER), because there is + * another check in cluster() which will stop any attempt to cluster + * remote temp tables by name. There is another check in + * check_index_is_clusterable which is redundant, but we leave it for + * extra safety. + */ + if (isOtherTempNamespace(RelationGetNamespace(OldHeap))) + { + relation_close(OldHeap, AccessExclusiveLock); + return; + } + /* * Check that the index still exists */ -- cgit v1.2.3