Favoring index access
You can increase the likelihood that Db2 chooses matching index access when other access methods might result in suboptimal performance.
Before you begin
Index access might sometimes be more costly than a table space scan or non-matching index access. Use these methods only when you are certain that index access is preferable.
About this task
Db2 often scans a table space or
nonmatching index when statistics indicate that a table is small, even though matching index access
is possible. This choice might become a problem in certain cases. For example, a table might be
small or empty when statistics are collected.
Later, after data is
inserted in the table, statistics such as the value of the NPAGES column in the SYSIBM.SYSTABLES
catalog table might no longer represent the actual volume of data in the table. The result might be
that Db2 chooses an inefficient access path
because of the inaccurate cost estimate.
Another reason to favor index access might be a database design in which tables contain groups of rows that logically belong together. The rows within each group are accessed in the same sequence every time. The access sequence is based on the primary key. Lock contention can occur when Db2 chooses different access paths for other applications that operate on tables that use this design. Index access can reduce contention and preserve the access sequence that the primary key provides.
Procedure
To favor the use of index access over other access methods, use any of the following approaches:
Results
At access path selection for bind or prepare, Db2 uses real-time statistics values and favors index access for tables defined as VOLATILE or that qualify for the value of the NPGTHRSH subsystem parameter. Db2 uses the index that has the most matching columns.