This post describes best practices for building appropriate secondary indexes on DataStore Objects.
General guidelines for placing secondary indexes on DataStore Objects:
- The presence of secondary indexes on an DataStore Object can greatly improve query performance, but it may slow down load performance.
- If your application does not have routine, frequent reads or reports on a DataStore Object, do not build secondary indexes on it.
Designing Secondary Indexes:
Apply these general guidelines when determining the number and structure of secondary indexes on DataStore Objects:
- Do not design a secondary index that duplicates the primary key of the DSO, or any high order subset thereof. For example, if the primary key consists of Customer Number + Invoice Date + Document Number + Line Item Number, do not create a secondary index consisting of the first key field (Customer Number), or the first two key fields (Customer Number + Invoice Date), or the first three key fields, etc.
- Do not construct any secondary index as a subset of the high order fields in another secondary index.
- Construct a secondary index for the characteristics used most frequently in query restrictions.
- Use a single characteristic in a secondary index if queries frequently restrict on that characteristic independently of others.
- Use a combination of multiple characteristics in the same secondary index if queries frequently restrict on that combination. For example, Fiscal Period + Version.
- After building indexes to support query restrictions, you may also see further performance improvement by building secondary indexes on the characteristics most frequently used on rows in the initial drilldown state of your queries.
- When building a secondary index composed of multiple characteristics, use the following guidelines to determine the sequence of characteristics in the index:
- If one or more of the index characteristics also appears in query filters independently of the other characteristics, place these independent characteristics in the first (high order) positions of the index definition. For example, if you frequently restrict queries on Profit Center and Version, but you also restrict queries on Version only sometimes, then place Version first in the index definition.
- If the guideline above does not apply, then sequence characteristics in your index definition according to their cardinality (the number of unique characteristic values they have. Place the characteristics with the highest cardinality first. For example, suppose you wish to build an index on Employee Number, Customer Number, and Version. Suppose further that you anticipate 100,000 unique values of Customer Number, 8,000 unique values of Employee Number, and 10 unique values of Version. You should therefore compose your secondary index as Customer Number + Employee Number + Version.
Building Secondary Indexes:
You build secondary indexes on DataStore Objects using the DSO editor (the same tool you use to create and change DataStore Objects definitions.) To create a secondary index on an DataStore Object:
- Go in to the DataStore Object editor in the BW Administrator Workbench. (Right click on a DataStore Object in the InfoProvider tree and choose “Change.”)
- Right-click on the “Indexes” folder and choose Create.
- On the popup window that appears, do not check the unique check box unless this index uniquely identifies a single record. Click OK or press Enter.
- Drag and drop characteristics from the Key fields and Data Fields folders onto the folder representing your new secondary index.
- As necessary, drag and drop characteristics within the secondary index folder to sequence them according to the guidelines above.
- Save and activate the DataStore Object.
If the DataStore Object already contains data, activation may take a few minutes while the system builds the new index.
Secondary indexes get transported with the DataStore Object to Test and Production. You should build and test secondary indexes in the Development environment first, then transport them up the landscape.
In practice, you should rarely use this option, since the primary key uniquely identifies a row in the DSO. Circumstances may arise, however, where some combination of characteristics outside the primary key also identifies a unique record. In those instances, you should set this check box on.
As a personal note of caution, I have seen secondary indexes causing lot of issues in the DSO activation step. For Example, a delivery DSO was having secondary indexes on it. This DSO sometimes took very long time to activate a single request. Again this may depend on your local system settings and version and even nature of the data sometimes.
Courtesy: SAP and Project Help Documents