DB2advanced

DB2 Performance Tuning Principles

Bring together indexing, statistics, isolation levels, and SQL-writing discipline into a coherent approach to diagnosing and fixing slow DB2 queries.

Performance tuning interview questions rarely ask for a single fact — they ask you to walk through an investigative process, and this topic is really about demonstrating that process end to end rather than reciting isolated tips. A strong candidate treats 'this query is slow' as a diagnosis problem with a repeatable sequence of checks, not a grab-bag of unrelated tricks.

Tuning a slow DB2 query is like diagnosing why a delivery route suddenly takes twice as long — you check the map app's chosen route first (EXPLAIN), then whether the map data is current (RUNSTATS/REORG), then whether a shortcut even exists (indexing), then whether the delivery instructions themselves are oddly worded and confusing the app (SQL rewrite), before finally considering whether it's just rush hour traffic everywhere (environmental/concurrency factors).

Key Concepts

1
The starting point is almost always EXPLAIN: confirm what access path the optimizer actually chose before guessing at a fix. From there, common culprits include missing or unusable indexes (a predicate written in a way that defeats index matching, like applying a function to an indexed column), stale statistics (fixed by RUNSTATS followed by REBIND), poor clustering after heavy update activity (fixed by REORG), and SQL written in a way that forces the optimizer into an inefficient plan (unnecessary DISTINCT, functions in WHERE clauses, or overly broad SELECT * pulling far more data than needed).
2
Beyond query-level fixes, broader tuning considerations include isolation level choice (an overly conservative isolation level can serialize concurrent access unnecessarily), buffer pool tuning (ensuring frequently accessed table spaces and indexes have adequate buffer pool allocation to avoid excessive physical I/O), and application-level batching (avoiding row-by-row processing where set-based SQL or bulk utilities would be dramatically more efficient).
3
A well-rounded answer to 'how would you tune a slow DB2 query' walks the interviewer through this exact sequence — EXPLAIN first, then statistics freshness, then indexing, then SQL rewrite, then broader environmental factors — rather than jumping straight to a single favorite fix, because that sequencing itself demonstrates real diagnostic maturity.