Conceptual
Login

Physical Row Order and Correlation: Why CLUSTER Can Make an Index Scan Cheaper

If rows that are next to each other in an index also sit near each other in the table, then following the index reads a handful of heap pages instead of one page per row, and the engine tracks this relationship as a statistic called correlation. Tables that grow by appending are naturally well correlated on their creation date, and badly correlated on almost everything else. The CLUSTER command physically rewrites a table in one index's order to restore that alignment, which helps range queries on that column a lot, helps nothing else, and drifts back out of order as the table is updated.

Questions this Concept answers

  • Why does high correlation make an index range scan cheaper?