The use of indexes can improve significantly the performance of
your applications.
This is because the Optimizer uses
them for performance optimization. Indexes are created in five different ways:
- CREATE INDEX (in SQL)
- CRTPF, with key
- CRTLF, with key
- CRTLF, as join logical file
- CRTLF, with select/omit specifications, without a key, and without dynamic
selection (DYNSLT).
Indexes are used to enable row selection by means of index-versus-table
scanning, which is usually slower. Table scanning sequentially processes all
rows in a table. If a permanent index is available, building a temporary index
can be avoided. Indexes are required for:
- Join tables
- ORDER BY
- GROUP BY
Indexes will be created, if no permanent index exists.
Manage the number of indexes to minimize the extra server cost
of maintaining the indexes during update operations. Below are general rules
for particular types of tables:
- Primarily read-only tables:
- Create indexes over columns as needed. Consider creating an index only
if a table is greater than approximately 1,000 rows or is going to be used
with ORDER BY, GROUP BY, or join processing. Index maintenance could be costlier
than occasionally scanning the entire table.
- Primarily read-only table, with low update rate:
- Create indexes over columns as needed. Avoid building indexes over columns
that are updated frequently. INSERT, UPDATE, and DELETE will cause maintenance
to all indexes related to the table.
- High update-rate tables:
- Avoid creating many indexes. An example of a table that has a high update
rate is a logging or a history table.