Every Db2 shop knows it should rebind after REORG and RUNSTATS, and many still avoid it, because a rebind can turn an index access into a tablespace scan overnight and the first sign is an application that has slowed down. TUC makes rebinding safe enough to do after every maintenance cycle: it rebinds when the objects are ready, finds and judges every access path change, switches back or prevents any change for the worse, and corrects the table that caused it.
Key Benefits
Rebind at the Right Moment — Packages are rebound once, after the utility work is complete, and if you choose, only when every object they depend on is in good condition.
Every Change Detected — APCOMPARE is added to the generated REBIND commands, so every statement whose access path changed is found in the same step.
Changes in Plain Terms — The old and new value of each plan step that differs is recorded, such as index access replaced by a tablespace scan, or a sort added for a join.
Better or Worse, Decided by Cost — The estimated cost of the previous and the new access path is compared, and each changed statement is judged improved, neutral or degraded.
Degradations Switched Back or Prevented — A degraded package is switched back to its previous access path automatically, or the change is rejected before it takes effect.
The Responsible Table Named — Each difference is tied to the table it belongs to, so the object behind a degradation is known.
The Cause Corrected — The responsible tables qualify for REORG or RUNSTATS through the policy rules, and the next rebind starts from an object in good condition.
The Case for Rebinding, and the Risk
The risk is not the rebind itself. A package usually references several tables, and the optimizer works from whatever statistics each of them has at the moment of the rebind. One table left out of the maintenance cycle, or with statistics older than the rest, can be enough to replace a good access path with a poor one.
A Package That Is Never Rebound Does Not Stay Optimal
Static SQL keeps the access path chosen when the package was last bound. REORG restores the physical order of the data, RUNSTATS brings the statistics up to date, and a new index or a new Db2 function level may offer a better path, but none of this reaches a static package until it is rebound. Rebinding after maintenance lets the optimizer choose the best access path for the object as it is now.
A Package Rebound Without Checks Can Lose an Index Overnight
A rebind chooses the access path of every statement in the package again, not only the statements that reference the object that was maintained. Most of the time the new path is as good as the old one or better. When it is not, a standard rebind does not say so: the rebind completes, the package runs with the new path, and the application finds the regression.
Db2 provides the controls for doing this safely. Plan management keeps the previous copy of a package, APCOMPARE reports the statements whose access path changed, and APREUSE asks the optimizer to keep the existing path. What Db2 does not provide is the analysis in between. APCOMPARE reports only the name of the PLAN_TABLE column that differs, with no old and new values, no cost and no judgement, and it writes its findings to the PLAN_TABLE of each package owner. Turning that into a decision has been left to the DBA, package by package.
TUC makes rebinding safe enough to do routinely. The optimizer gets every chance to improve access paths, and a degraded access path cannot reach production unnoticed.
Rebinding When the Objects Are Ready
Most access path degradation after maintenance comes from optimizing a package against a mix of fresh and stale statistics. TUC reduces the number of changes before any comparison takes place. It finds the packages that depend on the objects being processed and generates the rebind commands at run time, and three controls decide when those commands run.
Statistics That Reflect the Reorganized Object
The REORG procedures supplied with TUC collect inline statistics, so the statistics of every reorganized object describe it as it is right after the REORG. The optimizer never works from statistics that describe the object as it was before.
Rebind Only When Every Dependent Object Is in Good Condition
If you choose, a package is rebound only when every object it depends on is freshly reorganized or unchanged since its last REORG. A package that references an object still in poor condition is left for a later cycle, after that object has been maintained.
One Rebind, After All the Utility Work
When a job stream runs in parallel, the parallel jobs do not rebind. The rebind is done once, by the job that synchronizes them, after all the utility work has completed, so no package is rebound while an object it depends on is still being processed.
Knowing What Changed
TUC adds APCOMPARE to the generated REBIND commands and uses it as the detector. Db2 compares the newly chosen access path with the access path structures stored in the package itself, so no earlier EXPLAIN is needed to find out whether a statement changed. TUC then completes the analysis in the same REBIND step, with no separate analysis step, no catalog queries and no EXPLAIN to run.
| Question | How TUC Answers It |
| Did the access path change? | APCOMPARE on the generated REBIND flags every statement whose access path changed. |
| What exactly changed? | The explained access paths of the new and the previous package copy are compared plan step by plan step. |
| Is it better or worse? | The estimated cost of the two access paths is compared. |
| Which object is responsible? | Each differing plan step belongs to exactly one table, which names the table responsible. |
| What should be done about it? | The corrective utility, REORG or RUNSTATS, is recorded for the responsible table when the statement degraded. |
One Set of Explain Tables for Every Owner
A rebind writes its explain output to the explain tables of the package owner, and rebinds run under many owners. TUC makes sure the findings of every rebind can be reviewed centrally. There is one place to look, whoever owns the package, and no set of explain tables to maintain for each owner.
A Baseline That Belongs to the Running Copy
The comparison needs the previous access path as well as the new one. TUC makes sure the baseline is the access path of the package copy Db2 is actually running, so a candidate path that was never bound cannot be mistaken for it. When the access path of the running copy is not on record, TUC captures it before the rebind, without binding anything.
Changes Described in Plain Terms
For each flagged statement, TUC compares the plan steps of the two access paths in full, from the join method and the index used to prefetch and sorts. Only what differs is recorded, with its old and new values and the estimated cost of the statement. Each changed field is shown on its own row, with the Db2 codes translated into plain text, for example:
| Db2 Code | Shown As |
| Join method 1 to 2 | Nested-loop to Merge-scan |
| Access type I to R | Index to Table-scan |
| Prefetch blank to S | None to Sequential |
| Composite sort N to Y | No-sort to Composite-orderby-sort |
Better or Worse, and Why
Classifying Each Change
Each plan step that differs is classified by what changed and in which direction: index access lost, fewer matching columns, more sorts, prefetch gained, and so on, each marked improved, neutral or degraded. A neutral impact does not mean that nothing changed. An index switch or a change of prefetch is a real difference whose direction cannot be told from the access path alone, so it is reported rather than passed over.
Judging by Estimated Cost
The verdict comes from the estimated cost of the statement before and after the rebind. A statement is judged improved, degraded or neutral, and a tolerance band keeps routine noise in the estimates out of the report.
Statements are ranked by how much cost is really at stake, not by the percentage. A small statement whose cost doubled does not matter next to a large one whose cost grew by a third, so the statements that matter most are the first ones shown, and they decide the verdict of the package.
Naming the Responsible Table
A statement usually reads several tables, and blaming all of them would be wrong: one table may have lost an index while the others are untouched. Each difference belongs to one plan step, and each plan step to one table, so every changed table is recorded with its own classification, and a table whose plan steps did not change is not recorded at all.
A table whose access got worse inside a statement that became cheaper needs no correction, because the optimizer made a profitable trade. The corrective utility is recorded only when the statement itself was judged degraded.
The analysis turns a list of packages whose access path changed into three answers: what changed, whether it costs more, and which table is responsible. That is what makes an automatic decision possible, and what lets a whole rebind be reviewed without running a single EXPLAIN.
Prevent the Change or Reverse It
- Rebind. Dependent packages are rebound with APCOMPARE and EXPLAIN(YES).
- Describe. Changed statements are compared plan step by plan step.
- Judge. The estimated cost decides improved, neutral or degraded.
- Protect. A degraded package is switched back, or the change is rejected.
There are two ways to work, and both end the same way: no degraded access path stays in production. They differ in whether the change is reversed after the rebind or prevented before it.
| Mode | What Happens |
| APCOMPARE(WARN) with SWITCH | Every package is rebound and every improvement takes effect at once. A package with a degraded statement is switched back to its previous access path with REBIND SWITCH(PREVIOUS), after its findings are recorded. |
| APCOMPARE(ERROR) | The rebind of any package whose access path would change is rejected, and the current copy is left untouched. The rejected path is still explained and costed, so each package can be accepted by a deliberate decision. |
| APREUSE, with either mode | The optimizer is asked to reproduce the previous access path for each statement, which reduces the number of changes to review. Statements where reuse was not possible are analyzed in the same way. |
Choosing the Mode
WARN with SWITCH is the mode for rebinds that must complete, such as after activating a new Db2 function level, when packages have been invalidated, or when the application compatibility level has to be raised. It is also the mode for sites that want the optimizer to keep improving access paths. ERROR is the mode for routine maintenance windows, where stability matters more than optimization and the rebind does not have to complete.
A rejected rebind is analyzed exactly like an accepted one, although Db2 itself keeps no explain output for it. The report then answers the question that follows a rejection: what would have changed, and would it have been worse.
Access path stability relies on Db2 plan management. PLANMGMT(BASIC) or PLANMGMT(EXTENDED) keeps the previous copy of each package, which is what the new access path is compared with and what SWITCH(PREVIOUS) returns to. The switch applies to the whole package: one degraded statement reverts every statement in the package, including the ones that improved.
Reviewing a Rebind
The list of packages in a rebind is where it is reviewed. It shows the verdict, the classification, the outcome and the cost difference of each package, so a whole rebind can be scanned for degradation without opening anything. Selecting a package with a verdict opens the access path comparison. From the same list you can display the objects the package depends on, show the access path from the last EXPLAIN, list the previous and original copies side by side, and generate a REBIND, a switch back to the previous access path, or a FREE. Bind errors, reuse failures and access path changes are listed together, so the rebinds that need attention are easy to find.
| Outcome | What the Package Is Running |
| Accepted | The new access path. If it is neutral or improved and you decide otherwise, it can still be switched back from the list. |
| Switched | The access path it had before the rebind. The comparison shows the path that was rejected and why. |
| Rejected | The access path it had before the rebind, never changed. The comparison shows what the rebind would have done. |
Correcting the Cause
Switching a package back protects the application, but it leaves the cause in place. TUC records the tables responsible for each degradation together with the utility that can correct them, and two policy rules, one for REORG and one for RUNSTATS, qualify those tables in the next maintenance cycle.
The utility follows from the kind of change. Where the change shows that the optimizer gave up on the physical order of the data, a REORG restores it. Where it follows from the estimates the optimizer was given, current statistics correct it. Changes that no maintenance can resolve are reported as such, because they are the ones that may need an SQL or index change.
Two Stages Before Any Utility Runs
A degraded access path is a good signal, but not proof that a utility will help. That is decided by the condition of the object itself, such as its cluster ratio, indirect references and number of extents, which the normal TUC thresholds evaluate. The corrective rules are combined with the normal REORG and RUNSTATS rules rather than replacing them, so the object is processed with the priority its condition earns, within the same windows and quotas as the rest of the maintenance.
Once the utility has run, the object stops qualifying by itself, and nothing has to be deleted or reset. If the degradation is seen again after the utility has run, the object qualifies again.
That the optimizer changed its access path is not by itself a reason to reorganize a table. That the table lost its index and its cluster ratio has fallen is. TUC requires both before it acts.
A Cycle That Corrects Itself
- Qualify. The policy selects the objects.
- Maintain. REORG or RUNSTATS runs, with inline statistics.
- Rebind. Dependent packages are rebound with APCOMPARE.
- Protect. Degradations are switched back or rejected.
- Record. The responsible tables and the corrective utility are recorded.
- Correct. The utility runs and clears the trigger.
Once the options are set, each cycle runs without intervention, and each one starts the next rebind from objects in better condition. A package that could not keep its access path in one cycle is normally able to keep or improve it in the next, once the object behind the degradation has been reorganized or has had its statistics refreshed. Where a package is switched back cycle after cycle, the cause is usually an object that never reaches good condition, and its thresholds and exclusions are the place to look, not the package.
What the Analysis Can and Cannot Tell You
The cost is an estimate, not a measurement. A degraded verdict means that the optimizer expects the new path to cost more. Only runtime measurement, from SMF accounting, from IFCID 316 and 318, or from the performance data TUC collects, proves an actual regression. Where Db2 marks an estimate with cost category B, usually because host variables or parameter markers forced it to use default values, the classification of the change is the more reliable signal.
When the baseline comes from an earlier rebind, the two estimates were made under different statistics, so the cost difference reflects the change in the data as well as the change of path. And because the cost is one number for the whole statement, a degraded step on a large table can be hidden by a larger improvement elsewhere in the same statement. That is why TUC records the classification of each table alongside the verdict of the statement.
Without and With TUC
| Task | Without TUC | With TUC |
| When to rebind | Never, for fear of regressions, or right after each utility, against stale statistics. | Once, after all the utility work, and only when the dependent objects are in good condition. |
| Finding changes | APCOMPARE names a column, per owner, with no values. | Every changed plan step, with old and new values in plain text, in one place. |
| Better or worse | EXPLAIN run and compared statement by statement. | Judged by estimated cost, with routine noise filtered out. |
| A degraded path | Found by the application in production. | Switched back automatically, or never takes effect. |
| The cause | Guessed, if looked for at all. | The responsible table named and corrected in the next cycle. |
In short — The choice has usually been between two risks: never rebinding, and running on access paths chosen for data that has since changed, or rebinding, and finding a regression in production. TUC removes the choice. Packages are rebound when their objects are ready, every change is described and judged, degradations are switched back or prevented, and the objects behind them are corrected in the next cycle, so the benefit of every REORG and RUNSTATS reaches the applications.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article