Code review for transaction-safe-TRUNCATE patch: minor cleanups.
authorTom Lane
Mon, 30 Dec 2002 19:45:17 +0000 (19:45 +0000)
committerTom Lane
Mon, 30 Dec 2002 19:45:17 +0000 (19:45 +0000)
doc/src/sgml/release.sgml
src/backend/commands/cluster.c
src/backend/commands/tablecmds.c

index 6d2595009b3db6494d4c5a2b45141d34957c1bc7..57fa4052b8bb0fbc14bf2fe96a63a332f1eefb7b 100644 (file)
@@ -1,5 +1,5 @@
 
 
 
@@ -29,6 +29,7 @@ Information schema
 Domains now support CHECK constraints
 psql backslash commands for listing conversions, casts, and schemas
 TRUNCATE TABLE is transaction-safe
+CLUSTER can re-cluster a previously clustered table, or all such tables
 Statement-level triggers
 System can use either hash- or sort-based strategy for grouped aggregation
 ON COMMIT options for temp tables
index 0361ede00929e20d2576ca61e03bbec6cc53ded0..4858504f58d38dd527e6062f99e1c045f8f41c2e 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.103 2002/12/30 18:42:13 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.104 2002/12/30 19:45:15 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,7 +26,6 @@
 #include "catalog/index.h"
 #include "catalog/indexing.h"
 #include "catalog/namespace.h"
-#include "catalog/pg_constraint.h"
 #include "commands/cluster.h"
 #include "commands/tablecmds.h"
 #include "miscadmin.h"
@@ -111,9 +110,9 @@ cluster(ClusterStmt *stmt)
        RelToCluster    rvtc;
 
        /* Find and lock the table */
-       tableOid = RangeVarGetRelid(stmt->relation, false);
+       rel = heap_openrv(stmt->relation, AccessExclusiveLock);
 
-       rel = heap_open(tableOid, AccessExclusiveLock);
+       tableOid = RelationGetRelid(rel);
 
        /* Check permissions */
        if (!check_cluster_permitted(tableOid))
@@ -325,6 +324,13 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
        elog(ERROR, "CLUSTER: cannot cluster system relation \"%s\"",
             RelationGetRelationName(OldHeap));
 
+   /*
+    * Don't allow cluster on temp tables of other backends ... their
+    * local buffer manager is not going to cope.
+    */
+   if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
+       elog(ERROR, "CLUSTER cannot be used on temp tables of other processes");
+
    /* Drop relcache refcnt on OldIndex, but keep lock */
    index_close(OldIndex);
 
index 29edb61638e507ac8a60a04a73ef66610475af5e..3f9cad16ce4ce139560414de9bfc81372e585c44 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.63 2002/12/30 18:42:14 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.64 2002/12/30 19:45:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -423,8 +423,7 @@ TruncateRelation(const RangeVar *relation)
        Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple);
 
        if (con->contype == 'f' && con->conrelid != relid)
-           elog(ERROR, "TRUNCATE cannot be used as table %s references "
-                       "this one via foreign key constraint %s",
+           elog(ERROR, "TRUNCATE cannot be used as table %s references this one via foreign key constraint %s",
                 get_rel_name(con->conrelid),
                 NameStr(con->conname));
    }
@@ -439,6 +438,11 @@ TruncateRelation(const RangeVar *relation)
    rebuild_relation(rel, InvalidOid);
 
    /* NB: rebuild_relation does heap_close() */
+
+   /*
+    * You might think we need to truncate the rel's toast table here too,
+    * but actually we don't; it will have been rebuilt in an empty state.
+    */
 }
 
 /*----------