next up previous contents index
Next: VACUUM Up: Performance Previous: Unique Indexes

   
CLUSTER

The CLUSTER command reorders the table file to match the ordering of an index. This specialized command is valuable when performance is critical and the indexed column has many duplicate values.

For example, suppose the column customer.age has many duplicate values, and the query SELECT * FROM customer WHERE age = 98 is executed. An index on age allows rapid retrieval of the row locations from the index. If thousands of matching rows exist, however, they may be scattered in the table file, requiring many disk accesses to retrieve them. CLUSTER reorders the table, placing duplicate values next to each other. This speeds access for large queries accessing many duplicate values.

CLUSTER even helps with range queries like col >= 3 AND col <= 5. The command places these rows next to each other on disk, speeding indexed lookups.

In addition, CLUSTER can also speed ORDER BY  processing. See the CLUSTER manual page for more information.  


Bruce Momjian
2001-05-09