]> granicus.if.org Git - postgresql/commitdiff
Make CLUSTER and REINDEX silently skip remote temp tables in their
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 10 Sep 2007 22:02:05 +0000 (22:02 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 10 Sep 2007 22:02:05 +0000 (22:02 +0000)
database-wide editions.

Per report from bitsandbytes88 <at> hotmail.com and subsequent discussion.

src/backend/commands/cluster.c
src/backend/commands/indexcmds.c

index 665c66cad5e16941344250faac2420e79a2a9401..506e3d7894b8dc285d5ae242e6eb9d44ed9d2251 100644 (file)
@@ -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
                 */
index 87dec1909d8a1cc35c4dd1fcb90a6dd6ca4c9b3a..04593017485166c62435edc8c42eabc5079b9226 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.149.2.1 2007/08/25 19:08:25 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.149.2.2 2007/09/10 22:02:05 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1217,6 +1217,10 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
                if (classtuple->relkind != RELKIND_RELATION)
                        continue;
 
+               /* Skip temp tables of other backends; we can't reindex them at all */
+               if (isOtherTempNamespace(classtuple->relnamespace))
+                       continue;
+
                /* Check user/system classification, and optionally skip */
                if (IsSystemClass(classtuple))
                {