Commit a03c0d93 authored by Tom Lane's avatar Tom Lane

Code review for CLUSTER ALL patch. Fix bogus locking, incorrect transaction

stop/start nesting, other infelicities.
parent 2e1f2c31
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v 1.22 2002/11/18 17:12:06 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/cluster.sgml,v 1.23 2002/12/30 18:42:12 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -108,14 +108,16 @@ CLUSTER ...@@ -108,14 +108,16 @@ CLUSTER
<para> <para>
When a table is clustered, <productname>PostgreSQL</productname> When a table is clustered, <productname>PostgreSQL</productname>
remembers on which index it was clustered. In calls to remembers on which index it was clustered. The form
<command>CLUSTER <replaceable class="parameter">tablename</replaceable></command>, <command>CLUSTER <replaceable class="parameter">tablename</replaceable></command>,
the table is clustered on the same index that it was clustered before. re-clusters the table on the same index that it was clustered before.
</para> </para>
<para> <para>
A simple <command>CLUSTER</command> clusters all the tables in the database <command>CLUSTER</command> without any parameter re-clusters all the tables
that the calling user owns and uses the saved cluster information. This in the
current database that the calling user owns, or all tables if called
by a superuser. (Never-clustered tables are not touched.) This
form of <command>CLUSTER</command> cannot be called from inside a form of <command>CLUSTER</command> cannot be called from inside a
transaction or function. transaction or function.
</para> </para>
...@@ -157,15 +159,15 @@ CLUSTER ...@@ -157,15 +159,15 @@ CLUSTER
</para> </para>
<para> <para>
<command>CLUSTER</command> preserves GRANT, inheritance, index, foreign <command>CLUSTER</command> preserves GRANT, inheritance, index, foreign
key, and other ancillary information about the table. key, and other ancillary information about the table.
</para> </para>
<para> <para>
Because <command>CLUSTER</command> remembers the clustering information, Because <command>CLUSTER</command> remembers the clustering information,
one can cluster the tables one wants clustered manually the first time, and one can cluster the tables one wants clustered manually the first time, and
setup a timed event similar to <command>VACUUM</command> so that the tables setup a timed event similar to <command>VACUUM</command> so that the tables
are periodically and automatically clustered. are periodically re-clustered.
</para> </para>
<para> <para>
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.62 2002/12/16 18:39:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.63 2002/12/30 18:42:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -355,7 +355,7 @@ RemoveRelation(const RangeVar *relation, DropBehavior behavior) ...@@ -355,7 +355,7 @@ RemoveRelation(const RangeVar *relation, DropBehavior behavior)
* Removes all the rows from a relation. * Removes all the rows from a relation.
* *
* Note: This routine only does safety and permissions checks; * Note: This routine only does safety and permissions checks;
* rebuild_rel in cluster.c does the actual work. * rebuild_relation in cluster.c does the actual work.
*/ */
void void
TruncateRelation(const RangeVar *relation) TruncateRelation(const RangeVar *relation)
...@@ -366,7 +366,6 @@ TruncateRelation(const RangeVar *relation) ...@@ -366,7 +366,6 @@ TruncateRelation(const RangeVar *relation)
Relation fkeyRel; Relation fkeyRel;
SysScanDesc fkeyScan; SysScanDesc fkeyScan;
HeapTuple tuple; HeapTuple tuple;
List *indexes;
/* Grab exclusive lock in preparation for truncate */ /* Grab exclusive lock in preparation for truncate */
rel = heap_openrv(relation, AccessExclusiveLock); rel = heap_openrv(relation, AccessExclusiveLock);
...@@ -433,17 +432,13 @@ TruncateRelation(const RangeVar *relation) ...@@ -433,17 +432,13 @@ TruncateRelation(const RangeVar *relation)
systable_endscan(fkeyScan); systable_endscan(fkeyScan);
heap_close(fkeyRel, AccessShareLock); heap_close(fkeyRel, AccessShareLock);
/* Save the information of all indexes on the relation. */
indexes = get_indexattr_list(rel, InvalidOid);
/* Keep the lock until transaction commit */
heap_close(rel, NoLock);
/* /*
* Do the real work using the same technique as cluster, but * Do the real work using the same technique as cluster, but
* without the code copy portion * without the data-copying portion
*/ */
rebuild_rel(relid, InvalidOid, indexes, false); rebuild_relation(rel, InvalidOid);
/* NB: rebuild_relation does heap_close() */
} }
/*---------- /*----------
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.186 2002/12/30 15:31:48 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.187 2002/12/30 18:42:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -187,7 +187,6 @@ ProcessUtility(Node *parsetree, ...@@ -187,7 +187,6 @@ ProcessUtility(Node *parsetree,
CommandDest dest, CommandDest dest,
char *completionTag) char *completionTag)
{ {
if (completionTag) if (completionTag)
completionTag[0] = '\0'; completionTag[0] = '\0';
...@@ -195,7 +194,6 @@ ProcessUtility(Node *parsetree, ...@@ -195,7 +194,6 @@ ProcessUtility(Node *parsetree,
{ {
/* /*
* ******************************** transactions ******************************** * ******************************** transactions ********************************
*
*/ */
case T_TransactionStmt: case T_TransactionStmt:
{ {
...@@ -742,11 +740,7 @@ ProcessUtility(Node *parsetree, ...@@ -742,11 +740,7 @@ ProcessUtility(Node *parsetree,
break; break;
case T_ClusterStmt: case T_ClusterStmt:
{ cluster((ClusterStmt *) parsetree);
ClusterStmt *stmt = (ClusterStmt *) parsetree;
cluster(stmt);
}
break; break;
case T_VacuumStmt: case T_VacuumStmt:
...@@ -874,7 +868,6 @@ ProcessUtility(Node *parsetree, ...@@ -874,7 +868,6 @@ ProcessUtility(Node *parsetree,
switch (stmt->reindexType) switch (stmt->reindexType)
{ {
char *relname;
case INDEX: case INDEX:
CheckOwnership(stmt->relation, false); CheckOwnership(stmt->relation, false);
ReindexIndex(stmt->relation, stmt->force); ReindexIndex(stmt->relation, stmt->force);
...@@ -884,8 +877,7 @@ ProcessUtility(Node *parsetree, ...@@ -884,8 +877,7 @@ ProcessUtility(Node *parsetree,
ReindexTable(stmt->relation, stmt->force); ReindexTable(stmt->relation, stmt->force);
break; break;
case DATABASE: case DATABASE:
relname = (char *) stmt->name; ReindexDatabase(stmt->name, stmt->force, false);
ReindexDatabase(relname, stmt->force, false);
break; break;
} }
break; break;
......
...@@ -6,22 +6,19 @@ ...@@ -6,22 +6,19 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994-5, Regents of the University of California * Portions Copyright (c) 1994-5, Regents of the University of California
* *
* $Id: cluster.h,v 1.17 2002/11/23 04:05:52 momjian Exp $ * $Id: cluster.h,v 1.18 2002/12/30 18:42:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef CLUSTER_H #ifndef CLUSTER_H
#define CLUSTER_H #define CLUSTER_H
#include <nodes/parsenodes.h> #include "nodes/parsenodes.h"
/* #include "utils/rel.h"
* functions
*/
extern void cluster(ClusterStmt *stmt);
extern List *get_indexattr_list(Relation OldHeap, Oid OldIndex);
extern void rebuild_rel(Oid tableOid, Oid indexOid,
List *indexes, bool dataCopy);
extern void cluster(ClusterStmt *stmt);
extern void rebuild_relation(Relation OldHeap, Oid indexOid);
#endif /* CLUSTER_H */ #endif /* CLUSTER_H */
...@@ -304,7 +304,7 @@ INSERT INTO clstr_3 VALUES (2); ...@@ -304,7 +304,7 @@ INSERT INTO clstr_3 VALUES (2);
INSERT INTO clstr_3 VALUES (1); INSERT INTO clstr_3 VALUES (1);
-- "CLUSTER <tablename>" on a table that hasn't been clustered -- "CLUSTER <tablename>" on a table that hasn't been clustered
CLUSTER clstr_2; CLUSTER clstr_2;
ERROR: CLUSTER: No previously clustered index found on table clstr_2 ERROR: CLUSTER: No previously clustered index found on table "clstr_2"
CLUSTER clstr_1_pkey ON clstr_1; CLUSTER clstr_1_pkey ON clstr_1;
CLUSTER clstr_2_pkey ON clstr_2; CLUSTER clstr_2_pkey ON clstr_2;
SELECT * FROM clstr_1 UNION ALL SELECT * FROM clstr_1 UNION ALL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment