Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

Create attribute indexes

The Library Server and the Resource Manager databases are installed with the appropriate indexes to optimize create, retrieve, update, and delete operations. When you define a new item type, the appropriate indexes are created automatically. Indexes on user-defined item attributes are not generated automatically. For the attributes that are frequently used for regular searches, creating indexes on these attributes often improves response time and reduces resource usage for queries using these attributes. Indexes can negatively affect response times for create, update, and delete operations for that item type as well as increase the database size and buffer pool usage. You should monitor overall system performance and response time before and after adding an index to evaluate its overall value. A part of this process should be running your SQL through the DB2 Explain function to verify that the new indexes are being used.

How to create an index


You can use the Content Manager system administration client or the DB2 Control Center to add an index for a single attribute. If you want to create an index over multiple attributes, then you must create it manually. In order to be effective, manually created indexes must include certain key system-defined attributes. For example, for a simple (no child components) item type myitemtype, with user-defined attributes myattr1 and myattr2, perform the following steps to create indexes on the attributes: 1. Query to get numeric values AAAA for myattr1 and BBBB for myattr2:
db2 select keywordcode, keywordname from icmstnlskeywords where keywordclass=1 and keywordname in ('myattr1','myattr2')

2.

Query to get numeric value CCCC for myitemtype:


db2 select c.componenttypeid from icmstnlskeywords k, icmstcompdefs c where k.keywordname='myitemtype' and k.keywordclass=2 and k.keywordcode=c.itemtypeid and c.comptypeclass=0

3.

Create the index using the obtained numeric values:


db2 create unique index mynewindex1 on icmut0<CCCC> ( ATTR000000<AAAA> asc, ATTR000000<BBBB> asc, versioned asc, componentid asc ) include (itemid, compkey)

(This index is unique, even if myattr1 and myattr2 are not.) 4. If you want the myattr1 and myattr2 combination to be unique within myitemtype, create this index as well:
db2 create unique index mynewindex2 on icmut0<CCCC>001 ( ATTR000000<AAAA> asc, ATTR000000<BBBB> asc)

After creating a new index, either manually or through the DB2 Control Center, run the runstats and rebind commands to make sure that the DB2 UDB optimizer can effectively use the new index.

You might also like