While index advice from the DB2 query optimizer is not new, the advice itself is much easier to capture and analyze with the new V5R4 tooling. A recent set of V5R4 PTFs simplifies the process even further.
With V5R4, capturing and collecting DB2 index advice is so simple that you don't even have to do anything. In past releases, you could find feedback on suggested indexes in optimizer debug messages within a job log or a database monitor collection. However, this feedback was available only if someone manually started a database monitor or turned on debug messages. Even once the advice was collected, an analyst had to deal with the complexities of extracting the advised index details of various job logs and database monitor files.
The DB2 query optimizer in V5R4 automatically logs all index advice for all queries to a system-wide repository. Just right-click the Database object in the iSeries Navigator tree and select the Index Advisor task to show the display in Figure 1. From this Advisor output screen, you can also directly create the advised index.
Figure 1: Right-click the Database object in the iSeries Navigator tree and select the Index Advisor for output. (Click images to enlarge.)
So that you are not overwhelmed with index advice, you can look at subsets of the DB2 index advice. Filtering the Index Advisor output is accomplished by launching the Advisor with a right-click on a table or schema (library) object. When the Index Advisor is launched from the table or schema level, the advisor will contain only those indexes advised for the selected table or the tables in the specified schema. This filtered index advice makes life much easier for the person who has to analyze and take action on the output provided by the DB2 for i5/OS Index Advisor.
Further simplifying the DB2 index advice is the capability delivered with recent V5R4 PTFs. The PTFs listed below deliver a new advisor feature known as the Index Advice Condenser:
- i5/OS 5722-SS1: SI25391, SI25469, SI25470
- iSeries Access for Windows: SI25949
This new Condenser simplifies use of the DB2 Index Advisor by analyzing the suggested indexes and trying to combine overlapping index advice into a single index recommendation. Overlapping index advice can occur when the query optimizer recommends indexes with the key columns in a different order or recommends indexes for different SQL requests that share some of the key columns. For example, a series of queries and SQL reports run against an inventory table results in the DB2 Index Advisor recommending two different indexes with the following keys:
- Index #1—Key columns: item_color
- Index #2—Key columns: item_color, item_size
In this case, creating a single index with key columns of item_color and item_size would cover both index recommendations. You don't have to manually correlate and combine advice for similar indexes because the Index Advice Condenser automates this process.
Not only will the Advice Condenser save you the time it takes to analyze the DB2 Index Advisor recommendations, but this new DB2 feature can also help you more efficiently utilize your server resources over the long term. Creating a single index that helps multiple queries and SQL statements is going to be better from a server resource point of view because a single index requires less storage and maintenance overhead than multiple indexes do. The Index Advice Condenser makes it much easier to create a single index that can potentially help multiple SQL requests.
Figure 2 shows the output of the Index Advice Condenser based on the raw index advice displayed in Figure 1 for the Customers table. Notice that the five indexes advised over the Customers table are reduced to four advised indexes by the Index Advice Condenser.
Figure 2: This is the output of the Index Advice Condenser based on the raw index advice displayed in Figure 1 for the Customers table.
You may be wondering why the recommended index over the custkey column was not merged into the last advised index in Figure 2, which contains key columns of Customer and Custkey. This behavior is due to the fact the Index Advice Condenser is limited by the "Leading Keys Order Independent" column returned in the DB2 Index Advisor output. This column contains those key column names that the DB2 Index Advisor is recommending to be at the beginning of the key definition for the index. The key columns in this "Leading Keys Order Independent" column can go in any order as long as they occupy the leading columns in the index key definition. The rest of the advised key columns can go in any order after the leading key columns. In this example, the Condenser is able to consolidate the first two rows of index advice into a single index with keys of Customer and Custkey since the "Leading Keys Order Independent" is the same for each advised index. In contrast, the advised index over just the Custkey column could not be merged into this same index because the leading key column for this index is Custkey, while the leading key for the consolidated index is Customers.
The Index Advice Condenser can be accessed programmatically or via a graphical interface. The graphical interface obviously is provided by iSeries Navigator. As you can see in Figure 3, the Condenser can be launched from the Index Advisor task menu.
Figure 3: The Condenser can be launched from the Index Advisor task menu.
To access the condensed index advice without iSeries Navigator, you can simply query a new view in the QSYS2 schema named CondensedIndexAdvice. This view will not be created in QSYS2 until the referenced i5/OS PTFs are applied on your server.
Here's an example of using this new view to retrieve the condensed index advice for a specific table:
WHERE table_name='CUSTOMERS' AND table_schema='DBITSODATA'
Using the new Index Advice Condenser in conjunction with the system-wide Index Advisor will make it much faster for you to determine the right indexes to add to your database in order to maximize DB2 performance on your system.