DB2 RUNSTATS and a Slower Batch Query: Prove an Access-Path Change Before Recommending an Index
A batch step that becomes slow after DB2 statistics maintenance is not automatically a DB2 defect, and it is not automatic evidence that a new index is needed. This incident guide shows how to collect the right comparison evidence, read a small EXPLAIN result, and choose a safe next action without changing production objects on a guess.
A batch step that becomes slow after DB2 statistics maintenance is not automatically a DB2 defect, and it is not automatic evidence that a new index is needed. This incident guide shows how to collect the right comparison evidence, read a small EXPLAIN result, and choose a safe next action without changing production objects on a guess.
The order table, SQL, object names, and numbers below are fictional. DB2 release, catalog layout, statistics procedures, optimizer options, and change controls vary by site.
Symptom: the job still completes, but the elapsed time changed
A nightly order-summary job normally finishes its read/update step in 12 minutes. After the weekend maintenance window, the same step runs for 58 minutes and approaches its batch window. Operations notices that a RUNSTATS utility completed before the first slow run.
That timing is worth investigating, but it is not a conclusion. The slower run may have more input rows, a different predicate value, concurrent workload, a lock wait, changed table organization, a package rebind, or an access-path choice based on more accurate statistics. A successful RUNSTATS return code only says that the utility finished according to its rules; it does not certify that every SQL statement will retain its former path.
The immediate objective is to answer a narrower question: did the costly statement’s workload or access path change, and is the observed path reasonable for the current data distribution?
Do not cancel a business-critical job, rerun it, rebind a package, update catalog statistics, or create an index solely because the elapsed time is high. First preserve the evidence from the slow execution and compare like with like.
Evidence to capture while the comparison is still possible
Collect identifiers and measurements that tie the investigation to one exact execution. Follow local controls for SQL text, bind information, and performance data.
| Evidence | Why it matters |
| --- | --- |
| Job ID, step, program, DBRM/package and plan or collection | Establishes which executable SQL actually ran |
| Business date, input count, qualifying-row count, and commit frequency | Separates a larger workload from a less efficient path |
| Start/end time, CPU time if available, and DB2 wait indicators | Shows whether elapsed time is CPU, I/O, lock, or external-wait driven |
| Statement identifier and predicate values or representative selectivity class | A different date range can legitimately need a different path |
| Package bind/rebind timestamp and relevant bind options | A package change can explain a changed access path independently of RUNSTATS |
| RUNSTATS scope, completion time, and object/index statistics updated | Establishes which optimizer inputs changed |
| EXPLAIN output for the statement before and after, when retained or reproducible | Converts a suspicion into an inspectable access-path comparison |
Avoid copying a full production input record or unrestricted statement trace into a ticket. A statement number, masked business key, row counts, and approved performance evidence are usually enough to begin. Also check whether the job overlapped an unusual online workload, utility, or storage event; a scan can be innocent while I/O service time is not.
Diagnosis path: compare the question before comparing the plan
Start with the SQL predicate and the population it selected. In the fictional example, the summary program processes orders for one cycle date and a small list of regions:
SELECT ORDER_ID, REGION_CD, ORDER_STATUS, NET_AMOUNT
FROM APP.ORDER_HDR
WHERE CYCLE_DATE = :HV-CYCLE-DATE
AND REGION_CD = :HV-REGION
AND ORDER_STATUS IN ('READY', 'HOLD');
An index on (CYCLE_DATE, REGION_CD, ORDER_STATUS) may be useful when those predicates are selective. It may be less useful on a peak cycle date where most rows have ORDER_STATUS = 'READY', or when the table is small enough that a tablespace scan is cheaper. The optimizer estimates cost from statistics; it does not know that a human expected the same index every night.
Next, make the run comparison fair:
1. Compare the slow execution with a prior run using the same or similar cycle type, not merely the prior calendar day.
2. Check qualifying rows and rows examined, if the local monitoring tooling exposes them. A fivefold increase in qualifying rows can explain a longer run even with the same path.
3. Confirm that the package and bind state are comparable. RUNSTATS alone generally does not change a static SQL package’s stored access path; a rebind or another event that changes the executable plan may be relevant. Dynamic SQL has different preparation behavior.
4. Use the approved EXPLAIN process in a non-production or controlled analysis context. Do not force a production rebind just to see a plan.
This distinction prevents a common bad diagnosis: blaming RUNSTATS when the real change was a package deployment, a changed host-variable value, or a concurrent resource constraint.
Reading a compact EXPLAIN comparison
The exact EXPLAIN tables and columns differ by DB2 version and local tooling. A simplified comparison might be recorded like this after an approved EXPLAIN:
Earlier comparable run
Access: matching index APP.IX_ORDER_CYCLE_REGION
Estimated qualifying rows: 18,000
Join/order operation: no extra sort observed
Slow execution analysis
Access: tablespace scan of APP.ORDER_HDR
Estimated qualifying rows: 1,140,000
Predicate stage: CYCLE_DATE applied, remaining filtering later
Additional operation: sort for downstream grouping
```
This does not by itself prove that the scan is wrong. Ask why the estimate changed. If the current cycle actually contains 1.1 million qualifying rows, a scan may be rational. If monitoring shows only 18,000 rows qualified but EXPLAIN estimates 1.1 million, investigate the statistics, data skew, correlated columns, predicate form, and any implicit conversions before proposing an index.
For example, a character host variable with unexpected padding or a function applied to an indexed column can change indexability. Rewriting SQL may help, but only after confirming semantic equivalence and testing the result. Do not change a predicate merely to make an EXPLAIN display look attractive.
Decision points: choose the smallest justified correction
| Finding | Safer next action |
| --- | --- |
| More qualifying rows and similar access path | Treat it as a workload/capacity question; review schedule, commit design, and batch-window impact |
| Access path changed after a verified bind/rebind | Compare approved EXPLAIN results and bind history; involve the DB2/application owner before any further bind action |
| Estimates are implausible for actual distribution | Have the DB2 team review RUNSTATS scope, histogram/frequency needs, and object statistics under the local procedure |
| SQL makes an indexed column non-indexable | Test a semantics-preserving SQL or host-variable correction in lower environments |
| Predicate pattern has a genuine unserved access need | Prepare an index proposal with write-cost, storage, maintenance, concurrency, and rollback considerations |
| High elapsed time is mainly lock or I/O wait | Investigate the blocking workload or infrastructure path; an index may not address the dominant wait |
An index is a permanent cost, not a free performance switch. It adds space, insert/update/delete maintenance, possible utility time, and design responsibility. A test that improves one statement with an artificial data sample can still harm other batch or online workloads.
What to verify before a rebind, index, or rerun
- Confirm the slow step’s package/plan identity, execution timestamp, and comparable input and qualifying-row volumes.
- Preserve approved EXPLAIN and monitoring evidence for both the baseline and slow case; record statement identifiers rather than exposing sensitive values.
- Verify whether static or dynamic SQL is involved and whether a bind, rebind, deployment, or optimizer-setting change occurred.
- Check the actual versus estimated row behavior where the site’s tools allow it, especially for skewed status, date, or region columns.
- Review RUNSTATS scope and recency with the DB2 owner; do not manually alter catalog statistics to force a preferred plan.
- Test any SQL, statistics, bind, or index proposal with representative data and concurrent-workload considerations in an approved environment.
- Obtain change approval and a rollback plan. Do not blindly rerun a partially completed update job; establish its commit and restart boundary first.
Practical takeaway
A slower batch query after RUNSTATS is an evidence problem before it is a tuning problem. Compare equivalent workloads, prove the package and access path in use, and reconcile estimated with actual row behavior. Only then can a team decide whether the responsible action is statistics review, SQL correction, capacity work, a controlled bind decision, or a carefully justified index.