Explain the concept of index clustering. What are its advantages and disadvantages?

Instruction: Describe what index clustering is and discuss its benefits and potential drawbacks.

Context: This question tests the candidate's knowledge of index clustering in databases, including when and why it might be used and the impact it can have on database performance.

Updated

Official answer

Name the database and index type first. In a SQL Server rowstore clustered index, the leaf level holds the data rows in logical key order. A table can have one clustered index; separate nonclustered indexes contain keys and row locators. On a clustered table that locator uses the clustered key.

This can suit range access, but it does not promise physically contiguous pages or ordered SELECT results without ORDER BY. A wide or frequently changing clustered key can increase maintenance and nonclustered-index costs. Inserts, page splits, lookups and the actual workload matter when choosing a key; clustering every table by an arbitrary field is not a performance strategy.

PostgreSQL CLUSTER instead performs a one-time table reorder using an index. Subsequent changes do not preserve that physical ordering automatically, and reclustering has locking and space costs. The term also has different meanings in other products.

Neither clustered indexing nor CLUSTER means distributing a database across a cluster of machines. Explain the engine-specific structure, then validate the candidate with representative reads, writes and execution plans.

Related Questions