Use the following steps to cluster a table:
- Before using the CLUSTER statement, check the time at which the query used in the previous recipe was executed by executing the following commands:
SELECT schoolid FROM caschools sc JOIN sfpoly sf
ON ST_Intersects(sf.geom, ST_Transform(sc.geom, 3310));
- We get the following performance numbers for three query runs:
Time: 80.746 ms
Time: 80.172 ms
Time: 80.004 ms
- Cluster the caschools table using the caschools_geom_3310_idx index as follows:
CLUSTER caschools USING caschools_geom_3310_idx;
- Rerun the query from the first step three times for the following performance timings:
Time: 57.880 ms
Time: 55.939 ms
Time: 53.107 ms
The performance improvements were not significant.