Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65371

Use of DB2 Indices with several columns

We are trying to locate a performance problem and wondering if an index is being used.

We have a table with a composite key, "ID" and "Version", both integers.

We have a select that tries to find the max of "ID". (This is done via Entity framework if it makes a difference).

Will this use the index or will it do a table scan?

Upvotes: 0

Views: 126

Answers (1)

bhamby
bhamby

Reputation: 15450

If the ID column is defined as the first part of a multi-column index, then DB2 will use that index to determine the MAX(). It will still probably try to use the index if you did a MAX(VERSION), but if you have a very large table, this may take quite a bit of processing.

You can confirm this using the explain facilities (link is for Linux/Unix/Windows 9.7).

Upvotes: 1

Related Questions