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
-->
......@@ -108,14 +108,16 @@ CLUSTER
<para>
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>,
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>
A simple <command>CLUSTER</command> clusters all the tables in the database
that the calling user owns and uses the saved cluster information. This
<command>CLUSTER</command> without any parameter re-clusters all the tables
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
transaction or function.
</para>
......@@ -165,7 +167,7 @@ CLUSTER
Because <command>CLUSTER</command> remembers the clustering information,
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
are periodically and automatically clustered.
are periodically re-clustered.
</para>
<para>
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* 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)
* Removes all the rows from a relation.
*
* 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
TruncateRelation(const RangeVar *relation)
......@@ -366,7 +366,6 @@ TruncateRelation(const RangeVar *relation)
Relation fkeyRel;
SysScanDesc fkeyScan;
HeapTuple tuple;
List *indexes;
/* Grab exclusive lock in preparation for truncate */
rel = heap_openrv(relation, AccessExclusiveLock);
......@@ -433,17 +432,13 @@ TruncateRelation(const RangeVar *relation)
systable_endscan(fkeyScan);
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
* 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 @@
*
*
* 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,
CommandDest dest,
char *completionTag)
{
if (completionTag)
completionTag[0] = '\0';
......@@ -195,7 +194,6 @@ ProcessUtility(Node *parsetree,
{
/*
* ******************************** transactions ********************************
*
*/
case T_TransactionStmt:
{
......@@ -742,11 +740,7 @@ ProcessUtility(Node *parsetree,
break;
case T_ClusterStmt:
{
ClusterStmt *stmt = (ClusterStmt *) parsetree;
cluster(stmt);
}
cluster((ClusterStmt *) parsetree);
break;
case T_VacuumStmt:
......@@ -874,7 +868,6 @@ ProcessUtility(Node *parsetree,
switch (stmt->reindexType)
{
char *relname;
case INDEX:
CheckOwnership(stmt->relation, false);
ReindexIndex(stmt->relation, stmt->force);
......@@ -884,8 +877,7 @@ ProcessUtility(Node *parsetree,
ReindexTable(stmt->relation, stmt->force);
break;
case DATABASE:
relname = (char *) stmt->name;
ReindexDatabase(relname, stmt->force, false);
ReindexDatabase(stmt->name, stmt->force, false);
break;
}
break;
......
......@@ -6,22 +6,19 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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
#define CLUSTER_H
#include <nodes/parsenodes.h>
/*
* functions
*/
extern void cluster(ClusterStmt *stmt);
#include "nodes/parsenodes.h"
#include "utils/rel.h"
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 */
......@@ -304,7 +304,7 @@ INSERT INTO clstr_3 VALUES (2);
INSERT INTO clstr_3 VALUES (1);
-- "CLUSTER <tablename>" on a table that hasn't been clustered
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_2_pkey ON clstr_2;
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