Sobes.tech
Junior — Middle

Can you explain what a clustered index in a database is?

sobes.tech AI

Answer from AI

A clustered index is a type of index in a database where the data in the table is physically ordered according to the index. That is, the table rows are stored on disk in the order of the clustered index keys. Usually, a table can have only one clustered index, as data can only be ordered in one way.

Advantages of a clustered index:

  • Fast search and sorting by index key.
  • Efficient for range queries.

Disadvantages:

  • When inserting new data, reordering may be required, which slows down insert operations.

Example: if a table has a clustered index on the "id" field, then the records will be stored on disk in ascending order of "id".

Can you explain what a clustered index in a database… - sobes.tech