• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • The DB2 DBA: Identifying Indexes with Shared Access Paths

    July 13, 2011 Hey, Mike

    The SysIndexStat catalog view has the column Owning_Index_Owner (plus schema, system names, etc.). However, that catalog view does not include constraint-created indexes, nor does it include keyed logical and physical files that share the access path owned by an SQL index. The DSPFD command does show the SQL index that owns the access path for such logical files, but I have not been able to generate this information in an outfile format from that command.

    The information must exist somewhere (since it shows on screen) and I would think it would be in one of the file description APIs, but I haven’t found it yet. Do you know where I can access it programmatically? I want to build a function that would supply that information for logical files that are not in the SysIndexStat catalog.

    With this information sorted by key column names, we could do a better job of cleaning up duplicate indexes and also make better decisions about new indexes.

    –Nelson

    This is a great question, Nelson.

    For those who may not know, I’d like to explain a bit about index ownership. When an index is built that shares one or more initial key columns of another existing index, DB2 for i is smart enough to build the new index by re-using the “shared columns” from the pre-existing index.

    To illustrate, say an index called INDEX1 on the ORDER_HEADER table consists of columns COMPANY, CUSTOMER, and SHIP_DATE. Then an index called INDEX2 is built on the same table with columns COMPANY, CUSTOMER, and ORDER_NUMBER. Because the first two columns (COMPANY, CUSTOMER) are shared in common with the same sort order (ascending), DB2 recognizes it is a waste to build another completely new index with these same two primary columns again (because it would have to store the same information again and it would have to take the time to do the sorting again).

    When building INDEX2, DB2 leverages the sort order for the first two columns in INDEX1 so that the only remaining work to do when building the access path for INDEX2 is to sort by ORDER_NUMBER within the pre-existing COMPANY and CUSTOMER access path from INDEX1. Because of this sharing, INDEX1 is known as the “owner” of INDEX2.

    In DB2 for i, this ownership mechanism encompasses more than just SQL indexes, it also includes constraints such as primary keys and unique keys, keyed physical files and keyed logical files.

    I asked IBM‘s Dan Cruikshank about how to programmatically retrieve index ownership information and he responded with three surprisingly simple approaches:

    1. The QUSRMBRD API. You can write an external User-Defined Table Function based on this API and join it back to the system catalogs. Be careful if at 5.4 or earlier as UDTFs are not supported by SQE until 6.1.
    2. The DSPFD TYPE(*MBR) command to an outfile contains the owning access path. You could join to the system catalogs using the owner name. This may be better performing for i 5.4 or earlier if the outfile is used as a driver.
    3. The traditional QSYS catalog views (objects starting with QADB%) also contain the access path ownership. You will probably need a high level of authority and you also want to be careful if you are on 6.1 or earlier as these are DDS LFs and they are not supported by SQE until 7.1.

    All of us who have some kind of management responsibility over our DB2 databases should follow in Nelson’s footsteps to identify the shared indexes on our systems. Indexes help a database system by improving query performance. However, maintaining too many indexes during database modifications imposes a performance tax on the database. It’s the database administrator’s job to determine the optimal balance between improved query performance with indexes and minimal index overhead.

    Identifying shared indexes helps with decision making as follows:

    1. Knowing which indexes share duplicate initial key columns can allow an administrator or developer to delete unnecessary indexes. Sometimes when similar indexes exist, one or more secondary or tertiary indexes may be deleted without drastically affecting query performance.
    2. Knowing which potentially shared indexes already exist can help prevent the unnecessary creation of new indexes that are very similar to existing indexes.

    Maintaining a balanced index strategy is key to an optimally running database.

    –Michael Sansoterra

    RELATED STORY

    Eliminate Unnecessary Access Paths



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Rocket Software

    Two Steps Forward, No Steps Back

    For over 35 years, Rocket Software’s solutions have empowered businesses to modernize their infrastructure, unlock data value, and drive transformation – all while ensuring modernization without disruption.

    LEARN MORE

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Cosyn:  Add audit trails to your master files in minutes with Audit Trail/400
    PowerTech:  FREE White Paper: PCI Compliance for Power Systems running IBM i
    Bytware:  Viruses? You'll Never Know Unless You Scan. FREE Webinar. July 20

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    PostgreSQL, Progress DB Now Supported on mrc’s m-Power Still Wanted: A Power-i System of Systems

    Leave a Reply Cancel reply

Volume 11, Number 20 -- July 13, 2011
THIS ISSUE SPONSORED BY:

SEQUEL Software
ProData Computer Services
CNX

Table of Contents

  • Running Totals in an SQL Query, Take 2
  • The DB2 DBA: Identifying Indexes with Shared Access Paths
  • How Do I Email a PC5250 Screen Shot?

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle