1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.1beta1 Documentation"
13
HREF="index.html"><LINK
16
HREF="sql-commands.html"><LINK
19
HREF="sql-close.html"><LINK
22
HREF="sql-comment.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2011-04-27T21:20:33"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.1beta1 Documentation</A
81
HREF="sql-comment.html"
90
HREF="sql-comment.html"
111
>CLUSTER -- cluster a table according to an index</DIV
113
CLASS="REFSYNOPSISDIV"
121
>CLUSTER [VERBOSE] <TT
132
CLUSTER [VERBOSE]</PRE
149
to cluster the table specified
156
based on the index specified by
163
already have been defined on
172
> When a table is clustered, it is physically reordered
173
based on the index information. Clustering is a one-time operation:
174
when the table is subsequently updated, the changes are
175
not clustered. That is, no attempt is made to store new or
176
updated rows according to their index order. (If one wishes, one can
177
periodically recluster by issuing the command again. Also, setting
181
> storage parameter to less than
182
100% can aid in preserving cluster ordering during updates, since updated
183
rows are kept on the same page if enough space is available there.)
186
> When a table is clustered, <SPAN
190
remembers which index it was clustered by. The form
200
reclusters the table using the same index as before. You can also
206
>SET WITHOUT CLUSTER</TT
209
HREF="sql-altertable.html"
211
> to set the index to be used for
212
future cluster operations, or to clear any previous setting.
218
> without any parameter reclusters all the
219
previously-clustered tables in the current database that the calling user
220
owns, or all such tables if called by a superuser. This
224
> cannot be executed inside a transaction
228
> When a table is being clustered, an <TT
232
> lock is acquired on it. This prevents any other
233
database operations (both reads and writes) from operating on the
261
> The name (possibly schema-qualified) of a table.
273
> The name of an index.
283
> Prints a progress report as each table is clustered.
297
> In cases where you are accessing single rows randomly
298
within a table, the actual order of the data in the
299
table is unimportant. However, if you tend to access some
300
data more than others, and there is an index that groups
301
them together, you will benefit from using <TT
305
If you are requesting a range of indexed values from a table, or a
306
single indexed value that has multiple rows that match,
310
> will help because once the index identifies the
311
table page for the first row that matches, all other rows
312
that match are probably already on the same table page,
313
and so you save disk accesses and speed up the query.
319
> can re-sort the table using either an indexscan
320
on the specified index, or (if the index is a b-tree) a sequential
321
scan followed by sorting. It will attempt to choose the method that
322
will be faster, based on planner cost parameters and available statistical
326
> When an indexscan is used, a temporary copy of the table is created that
327
contains the table data in the index order. Temporary copies of each
328
index on the table are created as well. Therefore, you need free space on
329
disk at least equal to the sum of the table size and the index sizes.
332
> When a sequential scan and sort is used, a temporary sort file is
333
also created, so that the peak temporary space requirement is as much
334
as double the table size, plus the index sizes. This method is often
335
faster than the indexscan method, but if the disk space requirement is
336
intolerable, you can disable this choice by temporarily setting <A
337
HREF="runtime-config-query.html#GUC-ENABLE-SORT"
345
> It is advisable to set <A
346
HREF="runtime-config-resource.html#GUC-MAINTENANCE-WORK-MEM"
347
>maintenance_work_mem</A
349
a reasonably large value (but not more than the amount of RAM you can
353
> operation) before clustering.
356
> Because the planner records statistics about the ordering of
357
tables, it is advisable to run <A
358
HREF="sql-analyze.html"
361
on the newly clustered table.
362
Otherwise, the planner might make poor choices of query plans.
368
> remembers which indexes are clustered,
369
one can cluster the tables one wants clustered manually the first time,
370
then set up a periodic maintenance script that executes
374
> without any parameters, so that the desired tables
375
are periodically reclustered.
386
> Cluster the table <TT
395
CLASS="PROGRAMLISTING"
396
>CLUSTER employees USING employees_ind;</PRE
403
> table using the same
404
index that was used before:
406
CLASS="PROGRAMLISTING"
407
>CLUSTER employees;</PRE
411
> Cluster all tables in the database that have previously been clustered:
413
CLASS="PROGRAMLISTING"
429
> statement in the SQL standard.
447
is also supported for compatibility with pre-8.3 <SPAN
462
HREF="app-clusterdb.html"
473
SUMMARY="Footer navigation table"
484
HREF="sql-close.html"
502
HREF="sql-comment.html"
518
HREF="sql-commands.html"
b'\\ No newline at end of file'