Skip to content

Commit 1cdc587

Browse files
committed
OK, here's the final version of ALTER TABLE ... SET WITHOUT CLUSTER.
Has docs + regression test. Christopher Kings-Lynne
1 parent 6f1aa94 commit 1cdc587

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

doc/src/sgml/ref/alter_table.sgml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.70 2004/05/27 03:30:11 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.71 2004/06/02 21:01:08 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -42,6 +42,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
4242
SET WITHOUT OIDS
4343
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
4444
CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable>
45+
SET WITHOUT CLUSTER
4546
</synopsis>
4647
</refsynopsisdiv>
4748

@@ -213,12 +214,24 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
213214
<term><literal>CLUSTER</literal></term>
214215
<listitem>
215216
<para>
216-
This form selects the default controlling index for future <xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
217+
This form selects the default index for future
218+
<xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
217219
operations.
218220
</para>
219221
</listitem>
220222
</varlistentry>
221223

224+
<varlistentry>
225+
<term><literal>SET WITHOUT CLUSTER</literal></term>
226+
<listitem>
227+
<para>
228+
This form removes the most recently used
229+
<xref linkend="SQL-CLUSTER" endterm="sql-cluster-title">
230+
index specification from the table.
231+
</para>
232+
</listitem>
233+
</varlistentry>
234+
222235
<varlistentry>
223236
<term><literal>RENAME</literal></term>
224237
<listitem>

src/backend/commands/tablecmds.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.108 2004/05/26 04:41:12 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.109 2004/06/02 21:01:08 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -233,6 +233,7 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab);
233233
static void ATPostAlterTypeParse(char *cmd, List **wqueue);
234234
static void ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId);
235235
static void ATExecClusterOn(Relation rel, const char *indexName);
236+
static void ATExecDropCluster(Relation rel);
236237
static int ri_trigger_type(Oid tgfoid);
237238
static void update_ri_trigger_args(Oid relid,
238239
const char *oldname,
@@ -1922,8 +1923,9 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
19221923
pass = AT_PASS_MISC;
19231924
break;
19241925
case AT_ClusterOn: /* CLUSTER ON */
1926+
case AT_DropCluster: /* SET WITHOUT CLUSTER */
19251927
ATSimplePermissions(rel, false);
1926-
/* This command never recurses */
1928+
/* These commands never recurse */
19271929
/* No command-specific prep needed */
19281930
pass = AT_PASS_MISC;
19291931
break;
@@ -2083,6 +2085,9 @@ ATExecCmd(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd)
20832085
case AT_ClusterOn: /* CLUSTER ON */
20842086
ATExecClusterOn(rel, cmd->name);
20852087
break;
2088+
case AT_DropCluster: /* SET WITHOUT CLUSTER */
2089+
ATExecDropCluster(rel);
2090+
break;
20862091
case AT_DropOids: /* SET WITHOUT OIDS */
20872092
/*
20882093
* Nothing to do here; we'll have generated a DropColumn subcommand
@@ -5044,6 +5049,19 @@ ATExecClusterOn(Relation rel, const char *indexName)
50445049
mark_index_clustered(rel, indexOid);
50455050
}
50465051

5052+
/*
5053+
* ALTER TABLE SET WITHOUT CLUSTER
5054+
*
5055+
* We have to find any indexes on the table that have indisclustered bit
5056+
* set and turn it off.
5057+
*/
5058+
static void
5059+
ATExecDropCluster(Relation rel)
5060+
{
5061+
mark_index_clustered(rel, InvalidOid);
5062+
}
5063+
5064+
50475065
/*
50485066
* ALTER TABLE CREATE TOAST TABLE
50495067
*

src/backend/parser/gram.y

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.459 2004/06/01 03:28:48 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.460 2004/06/02 21:01:09 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -1277,6 +1277,14 @@ alter_table_cmd:
12771277
n->name = $3;
12781278
$$ = (Node *)n;
12791279
}
1280+
/* ALTER TABLE <name> SET WITHOUT CLUSTER */
1281+
| SET WITHOUT CLUSTER
1282+
{
1283+
AlterTableCmd *n = makeNode(AlterTableCmd);
1284+
n->subtype = AT_DropCluster;
1285+
n->name = NULL;
1286+
$$ = (Node *)n;
1287+
}
12801288
;
12811289

12821290
alter_column_default:

src/include/nodes/parsenodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.256 2004/05/26 13:57:02 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.257 2004/06/02 21:01:09 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -793,6 +793,7 @@ typedef enum AlterTableType
793793
AT_ToastTable, /* create toast table */
794794
AT_ChangeOwner, /* change owner */
795795
AT_ClusterOn, /* CLUSTER ON */
796+
AT_DropCluster, /* SET WITHOUT CLUSTER */
796797
AT_DropOids /* SET WITHOUT OIDS */
797798
} AlterTableType;
798799

src/test/regress/expected/cluster.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ WHERE pg_class.oid=indexrelid
297297
clstr_tst_b_c
298298
(1 row)
299299

300+
-- Try turning off all clustering
301+
ALTER TABLE clstr_tst SET WITHOUT CLUSTER;
302+
SELECT pg_class.relname FROM pg_index, pg_class, pg_class AS pg_class_2
303+
WHERE pg_class.oid=indexrelid
304+
AND indrelid=pg_class_2.oid
305+
AND pg_class_2.relname = 'clstr_tst'
306+
AND indisclustered;
307+
relname
308+
---------
309+
(0 rows)
310+
300311
-- Verify that clustering all tables does in fact cluster the right ones
301312
CREATE USER clstr_user;
302313
CREATE TABLE clstr_1 (a INT PRIMARY KEY);

src/test/regress/sql/cluster.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ WHERE pg_class.oid=indexrelid
9595
AND pg_class_2.relname = 'clstr_tst'
9696
AND indisclustered;
9797

98+
-- Try turning off all clustering
99+
ALTER TABLE clstr_tst SET WITHOUT CLUSTER;
100+
SELECT pg_class.relname FROM pg_index, pg_class, pg_class AS pg_class_2
101+
WHERE pg_class.oid=indexrelid
102+
AND indrelid=pg_class_2.oid
103+
AND pg_class_2.relname = 'clstr_tst'
104+
AND indisclustered;
105+
98106
-- Verify that clustering all tables does in fact cluster the right ones
99107
CREATE USER clstr_user;
100108
CREATE TABLE clstr_1 (a INT PRIMARY KEY);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy