We can search a table for
data records that satisfy certain search criteria faster using an index.
An index can be considered
a copy of a database table that has been reduced to certain fields. This copy
is always in sorted form. Sorting provides faster access to the data records of
the table, for example using a binary search. The index also contains a pointer
to the corresponding record of the actual table so that the fields not
contained in the index can also be read.
The primary index is
distinguished from the secondary indexes of a table. The primary index
contains the key fields of the table and a pointer to the non-key fields of the
table. The primary index is created automatically when the table is created in
the database.
Table
SCOUNTER in the flight model contains the assignment of the
carrier counters to airports. The primary index on this table therefore
consists of the key fields of the table and a pointer to the original data
records.
We can also create further
indexes on a table in the ABAP Dictionary. These are called secondary
indexes. This is necessary if the table is frequently accessed in a way
that does not take advantage of the sorting of the primary index for the
access. Different indexes on the same table are distinguished with a
three-place index identifier.
All
the counters of carriers at a certain airport are often searched for flight
bookings. The airport ID is used to search for counters for such an access.
Sorting the primary index is of no use in speeding up this access. Since table
SCOUNTER has a large number of entries, a secondary index on the field AIRPORT
(ID of the airport) must be created to support access using the airport ID.
The optimizer of the
database system decides whether an index should be used for a concrete table
access (see How to Check if an Index is Used?). This means that an index might
only result in a gain in performance for certain database systems. You can
therefore define the database systems on which an index should be created when
you define the index in the ABAP Dictionary (see Creating Secondary Indexes.)
All the indexes existing in
the ABAP Dictionary for a table are normally created in the database when the
table is created if this was not excluded in the index definition for this
database system.
If the index fields have
key function, that is if they already uniquely identify each record of the
table, an index can be defined as a unique index.
See also:
No comments:
Post a Comment