Indexes

suggest change

Introduction

An index is a data structure that points to rows of a table in a specific order, to help the database optimize queries. It is similar to the index of a book.

Several types of indexes exist, and can be created on a table. When an index exists on the columns used in a query’s WHERE clause, JOIN clause, or ORDER BY clause, it can substantially improve query performance.

Remarks

Indexes speed up some read queries. A nonclustered index is a separate structure sorted on the indexed columns. Only a clustered index stores the table rows themselves in index order.

The effect of an index is not noticeable for small databases like the example, but if there are a large number of rows, it can greatly improve performance. Instead of checking every row of the table, the server can do a binary search on the index.

The tradeoff for creating an index is write speed and database size. Storing the index takes space. Also, every time an INSERT is done or the column is updated, the index must be updated. This is not as expensive an operation as scanning the entire table on a SELECT query, but it is still something to keep in mind.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents