Production engineering · Advanced

Performance & SQL tuning

Measure elapsed time, query plans, I/O, and contention before choosing a fix.

Learn this topic first: Production engineering: debug, secure, integrate and tune →

6 explained questions · 5 practice MCQs

Questions and answers

1. How do you begin a performance investigation? (Intermediate)

Define the slow operation, expected service level, input size, time window, and baseline. Separate queue delay, application execution, database work, and external waits. Capture comparable successful and slow runs.

Use evidence from job state, CPU, I/O, locks, and SQL activity. A single high CPU percentage or one slow user report is insufficient to choose a fix. Measure the outcome the business cares about, such as completed orders per minute or response-time percentiles.

2. What can the SQL plan cache and Visual Explain reveal? (Intermediate)

The SQL plan cache records query-plan and execution information useful for identifying expensive statements. ACS tooling can inspect statements and Visual Explain can show the chosen access strategy. The cache is finite and changes over time.

Capture relevant statements or snapshots while the evidence exists. Compare parameters, row counts, selectivity, and access paths for slow and fast cases. A plan diagram is a hypothesis about cost; validate its practical impact with measured execution.

3. Why can an index be useful and still not be chosen? (Intermediate)

The optimizer estimates whether an access path is cheaper for the query and data distribution. A table scan can be reasonable for a large fraction of rows; an index may not match useful leading keys or may require expensive lookups.

Inspect predicates, conversions, selectivity, statistics, and required ordering. Do not force an index solely because it exists. Additional indexes impose write and storage costs, so evaluate both read improvement and overall workload impact.

4. What makes a predicate less index friendly? (Advanced)

Applying transformations to indexed columns or comparing incompatible types can prevent or weaken efficient keyed access, depending on optimizer support. Broad wildcard patterns and low-selectivity conditions can also limit benefit.

Express a range directly when possible and keep types aligned. For a timestamp day filter, compare against start and next-day boundaries rather than assuming a formatting function is free. Confirm the actual plan; some expressions can be optimized or supported by suitable indexes.

5. How would you tune a native RPG read loop? (Advanced)

Measure record count, reads per result, key access, repeated opens, and work inside the loop. Eliminate unnecessary full scans and repeated lookups where a correct keyed path or set-based query helps.

Keep correctness first: selective reads must still include every qualifying record, and changing locking can change behavior. Compare representative volumes and concurrency. Do not assume CHAIN is universally faster than SQL or that changing opcodes is the main bottleneck.

6. How do you prove a tuning change improved the system? (Advanced)

Compare before and after on representative data and load, measuring throughput, elapsed distribution, resource usage, lock waits, and error rates. Verify output equivalence and transaction behavior.

Account for warm caches, concurrent workloads, and different parameters. A faster isolated query can slow writers or consume excessive memory under load. Document the measurement conditions and keep a rollback path for plan or workload regressions.

Practice checkpoint

  1. 1. High elapsed time with little CPU suggests investigating:
    1. Only multiplication speed
    2. Only the source filename
    3. Wait time, I/O, locks, and dependencies
    4. Only screen refresh
  2. 2. Why preserve a plan-cache snapshot promptly?
    1. The cache is permanent source control
    2. Every query is stored forever
    3. It replaces all backups
    4. Relevant entries can be evicted or replaced
  3. 3. Is every table scan a performance bug?
    1. No, it can be appropriate for many rows
    2. Yes, always
    3. Only on Db2 for i
    4. Only with a primary key
  4. 4. What is a cost of adding indexes?
    1. Automatic loss of all rows
    2. Additional write maintenance and storage
    3. Removal of all locks
    4. Disabling SQL
  5. 5. What should accompany a faster timing result?
    1. Only a smaller code file
    2. Only fewer comments
    3. Correctness and representative-load validation
    4. Only a new job name
Show answer key and explanations

1. C — Wait time, I/O, locks, and dependencies The bottleneck may be outside active instruction execution.

2. D — Relevant entries can be evicted or replaced Plan-cache evidence is finite and changes over time.

3. A — No, it can be appropriate for many rows The optimizer compares access costs for the query and data.

4. B — Additional write maintenance and storage Evaluate the whole workload, not only one read query.

5. C — Correctness and representative-load validation Performance gains must preserve results and remain useful under actual workload conditions.

IBM documentation and further reading