An index is a database structure that provides quick lookup of data in a column or columns of a table.
For example, a Flights table in a travelDB database has three indexes:
This means there are three separate structures that provide shortcuts into the Flights table. Let's look at one of those structures, OrigIndex.
OrigIndex stores every value in the orig_airport column, plus information on how to retrieve the entire corresponding row for each value.
When an index includes more than one column, the first column is the main
one by which the entries are ordered. For example, the index on (flight_id, segment_number) is ordered first by flight_id. If there is more than one flight_id of the same value, those entries are then ordered by segment_number. An excerpt from the entries in the index might look like
this:
Indexes are helpful only sometimes. This particular index is useful when a statement's WHERE clause is looking for rows for which the value of orig_airport is some specific value or range of values. SELECTs, UPDATEs, and DELETEs can all have WHERE clauses.
For example, OrigIndex is helpful for statements
such as the following:
DestIndex is helpful for statements such as the
following:
The primary key index (on flight_id and segment_number) is helpful for statements such as the following:
The next section discusses why the indexes are helpful for these statements but not for others.