Your system already knows which indexes you need

Your system has been quietly writing down which indexes it wishes you had. You just have to go read the note.

Every time the SQL Query Engine runs a query and decides an index would have helped, it records that. It has been doing it this whole time. The list lives here:

SELECT TABLE_NAME, KEY_COLUMNS_ADVISED,
      TIMES_ADVISED, MTI_USED, LAST_ADVISED
 FROM QSYS2.SYSIXADV
 ORDER BY TIMES_ADVISED DESC;

That is the information that the Index Advisor from Navigator displays. Sort it by TIMES_ADVISED, and the top of the list is the system telling you, in order, exactly which indexes would do your users the most good. It had to build that one the most.

A few things to understand before you go build all of them, because that is the rookie System Administrator mistake:

TIMES_ADVISED is how many times the engine wished for that index. A row near the top is a query that runs the most, over and over. That is your highest-value fix. But you also need to look at the estimated time. If you find the highest times advised and estimated time, these will be the best bang for your buck. Also, make sure the last advised is not a few years ago.

KEY_COLUMNS_ADVISED is the index it wants. Usually you build it close to that.

But do not just build the whole list. Indexes cost you on every insert, update, and delete, and they take up disk space. The art is building the handful that fix your worst queries without burying your write performance. Start at the top, build the obvious ones, measure, repeat.

This is the single highest-return hour an admin or developer can spend on a database that feels slow, and it costs nothing but attention.

Go look at your top five. How many are queries you already knew were painful?
#IBMi #SQL #Db2

Originally posted on LinkedIn. Join the conversation there.

Get new posts by email

Practical IBM i tips on SQL services, security and backup, sent when I publish. No spam, unsubscribe anytime.

Leave a Reply