Measuring the usefulness of Indexes
Administration Tips
Are my indexes are useful? I suppose this question is really asking whether it is possible to tell if an index is regularly used to access data in a table, or is it just sitting there slowing down DML on that table, and providing no real benefit. The unfortunate answer ot this is that it is simply not possible to tell easily in any version of Oracle prior to 9i, and even then it's not easy. In 9i, it's possible to switch on a monitoring function for an existing index by using the following sort of syntax: ALTER INDEX BLAH_IDX MONITORING USAGE;
After a suitable passage of time (the length of which is up to you to decide), you can switch monitoring off by issuing the command: ALTER INDEX BLAH_IDX NOMONITORING USAGE;
(Incidentally, switching on monitoring incurs some performance overhead, so don't just leave your indexes in the monitoring state... remember to switch them off after a suitable period). For the period during which the index is in the "monitoring" state, any time that index is used to satisfy a query or a piece of DML (and has thus, presumably, proved itself to be "useful"), the V$OBJECT_USAGE view will record a "YES" in the USAGE column. If the index is never used, that column will display a "NO". Notice that this is a binary state -either the index has been used, or it hasn't been. There's no indication given as to how often an index may have been used. That "YES" in V$OBJECT_USAGE might indicate it was used 600 times a day, or once. There's no way of telling. However, all is not lost. Every time a index flips between "monitoring" and "nomonitoring", the V$OBJECT_USAGE view is reset for that index. It would thus be conceivable that you might switch monitoring on and off ever, say, half hour -if you always get a "YES" in the OBJECT_USAGE view after flipping the monitoring state, it would indicate regular (at least once every half-hour) usage of the index. If you only got a "YES" once or twice, it might indicate an index that is only of use some of the time. It still doesn't tell you how many times an index was used within each half-hour time period, though, so be careful -even if an index is only used in one half-hour period a day, if 300,000 users used it at that one time, it might be considered a fairly useful index!
Copyright Š Howard Rogers 2001
10/18/2001
Page 1 of 2
Measuring the usefulness of Indexes
Administration Tips
One final word of warning: flipping between monitoring states for an index invalidates all shared SQL areas in the Library Cache which referenced that index. That means you'll be incurring additional parses, and thus hitting performance, potentially to a significant degree. If you've got anything other than 9i, none of the above applies to you! I can think of only one way to determine whether an index is being used in a 7, 8.0 or 8i environment -and that's to produce trace files for the various queries passed to the database by Users, and check whether the execution plans they are generating show that index access is being performed. That's not a trivial task, and working your way through the trace files afterwards is not going to be easy, either.
Copyright Š Howard Rogers 2001
10/18/2001
Page 2 of 2