Optimizer Modes   «Prev  Next»

Lesson 5

Oracle Optimizer Modes: Module Review and Practical Checklist

This module introduced a practical way to reason about Oracle SQL optimization: identify what the application needs, understand the information available to the optimizer, choose an appropriate scope for any change, and verify the result. In modern Oracle, the central choice is between performance goals within cost-based optimization. It is not a choice between a current cost-based optimizer and an equally current rule-based alternative.

The four lessons build on one another. The introduction to optimizer modes explains the application goals. The overview of optimizer modes distinguishes those goals from statistics and historical approaches. Viewing and changing the default mode explains effective settings and persistence. Overriding the optimizer goal applies that knowledge to individual queries. This conclusion connects those decisions into a repeatable review.

Keep the optimizer, its goal, and its plan distinct

The optimizer evaluates alternative ways of executing SQL. An access path describes how rows are obtained from an object. A complete execution plan combines access paths with joins, sorting, grouping, and any other operations required by the statement. An optimizer goal guides the tradeoffs used when selecting among candidate plans.

These distinctions prevent a common tuning error: treating a goal as a specific access-path instruction. A throughput goal does not mean that Oracle must scan every table. An initial-response goal does not guarantee index access. Either goal can lead to different operations as predicates, data volumes, statistics, and available indexes change.

Estimated cost is also different from observed time. It is an internal comparison measure used in planning, not a duration in milliseconds. A smaller cost can help explain an optimizer decision, but it does not establish that an application completed faster. Plan inspection and runtime measurement answer related but separate questions.

Review the supported optimizer-mode choices

For Oracle AI Database 26ai, the parameter reference documents the following choices. Treat the table as a vocabulary guide, then evaluate a setting against the workload rather than choosing solely from an application label such as reporting or online processing.

Optimizer goals and their practical meaning
Parameter valueGoal or roleWhat to verify
ALL_ROWSThe documented default, emphasizing efficient completion of the entire statement.Complete fetching and the work needed to finish the operation.
FIRST_ROWS_1, FIRST_ROWS_10, FIRST_ROWS_100, FIRST_ROWS_1000Cost-based goals emphasizing delivery of an initial number of rows.Initial-batch response and the consequences of continued fetching.
FIRST_ROWSAn older combination of costs and heuristics, retained for compatibility. Oracle recommends numbered alternatives.Existing application assumptions before replacing the setting.

The notation FIRST_ROWS_n names a family; it is not a literal parameter value. The unnumbered FIRST_ROWS is not equivalent to FIRST_ROWS_1. These distinctions are easy to overlook in old configuration notes, so record the exact value rather than shortening it to “first rows.” See the Oracle OPTIMIZER_MODE reference for the supported values.

Let fetching behavior define the performance question

Consider an export that must consume every qualifying transaction. Producing the first ten rows promptly does not finish the export. The meaningful comparison includes total processing time and resource use for the complete result. Initial responsiveness can still be measured, but it is not the main acceptance criterion.

Now consider an order-search screen that fetches an initial batch and waits for the user to continue. Early delivery may matter more than complete fetching if users usually stop after that first batch. A first-row goal is a candidate to evaluate, provided that this is how the application actually works.

A screen's visible page size does not prove its database fetching behavior. A framework might fetch all qualifying rows before displaying ten, or spend most of its time formatting data after retrieval. Measure the relevant application boundary. A database change that improves an initial fetch may have little effect on the delay the user experiences.

Neither a numbered parameter value nor a FIRST_ROWS hint limits the result. If an application needs ten rows in a particular order, the SQL must express its row-limiting and ordering requirements separately. An optimizer goal cannot remove work required for correct results, including necessary blocking operations.

Statistics and goals solve different problems

Statistics help the optimizer estimate row counts, selectivity, and the work of candidate operations. A goal expresses the desired performance emphasis. Changing the goal does not repair missing knowledge about a skewed distribution or a misleading estimate. Equally, collecting statistics does not decide whether a caller wants an initial batch or a complete export.

For example, most customer identifiers might match a few orders while a small number match very large histories. Testing one ordinary customer provides incomplete evidence. Include important high-volume cases and examine how estimates relate to the work actually performed. The same SQL text can represent very different amounts of work across representative values.

Modern statistics maintenance uses DBMS_STATS and Oracle's automatic collection facilities. Older ANALYZE-based optimizer-statistics instructions should not be copied into a current maintenance procedure. This does not mean every use of ANALYZE has disappeared; its other supported purposes are distinct from gathering optimizer statistics.

Missing statistics do not switch modern Oracle to the historical RBO. Other estimation mechanisms may apply. Investigate estimate quality within cost-based optimization instead of treating statistics as an on/off switch between optimizers. Detailed maintenance decisions belong to a statistics-management procedure, not an automatic “gather everything” response to one slow query.

Inspect the environment before changing it

The documented default, the effective session value, the system setting, and persisted startup configuration can differ. An application can establish a session override. A stored change may be intended for a later startup. An administrator connected to another container or instance may be inspecting a different context from the application.

In SQL*Plus or SQLcl, the following client command provides a convenient starting point:

SHOW PARAMETER optimizer_mode

SHOW PARAMETER is a client command, not SQL syntax accepted by every application interface. A session-level SQL inspection, subject to the necessary view access, is:

SELECT name, value
FROM v$parameter
WHERE name = 'optimizer_mode';

V$SYSTEM_PARAMETER and V$SPPARAMETER answer different questions about system and stored values. Use the detailed procedures in Lesson 3 when examining persistence, instance associations, and containers. Record enough context to reproduce the observation, including which session issued the query.

Configuration evidence is not plan evidence. Seeing a new value does not establish that every previously parsed or running statement now uses a different plan. Identify the actual execution being investigated before attributing its behavior to a recent setting change.

Choose the narrowest appropriate control

A query-goal hint expresses a request for its applicable statement block. A session setting establishes a broader default for work in that session. A system-level change is an administrative decision with wider implications. Choose the scope that matches the requirement and the comparison being performed.

For a controlled session experiment, record the previous value before issuing a statement such as:

ALTER SESSION SET OPTIMIZER_MODE = FIRST_ROWS_10;

Restore the recorded value afterward when the change was temporary. Assigning ALL_ROWS is not a universal rollback: a session might originally have used another setting. Connection pools make restoration particularly important because one physical database session can serve multiple application requests.

Persistence needs its own review. An SPFILE is server-managed and should not be edited as text. A PFILE is text, but changing it does not directly change a running instance. For system changes, MEMORY, SPFILE, and BOTH distinguish current and stored effects where applicable. Container inheritance and instance-specific settings require attention in multitenant and RAC environments.

A conclusion cannot supply one universally safe administrative reset command. Restoring an explicit value and removing an override to resume inheritance are different actions. Use the original configuration and the intended scope to decide what restoration means, then verify both effective and persisted settings.

Use goal hints with the correct syntax

The query-level spelling differs from the numbered parameter value. The following illustrative SELECT requests a goal for delivery of the first ten rows:

SELECT /*+ FIRST_ROWS(10) */
       employee_id, first_name, last_name
FROM employees
WHERE department_id = 10;

A throughput-oriented form uses /*+ ALL_ROWS */ in the same position after SELECT. Use these hint names directly; OPTIMIZER_MODE is not a wrapper around them. The parameter uses FIRST_ROWS_10, while the hint uses FIRST_ROWS(10). The parameter's numbered choices should not be assumed to define every valid integer argument of the hint.

This example assumes a suitable employees table and access to its columns. It has not been executed here and does not imply any particular plan or measured improvement. The presence of a hint comment also does not prove that Oracle used it. A misspelled, conflicting, or inapplicable hint can leave the statement executable without achieving the intended influence.

Review the hint usage report and the correct plan. For an application execution, identify the relevant SQL_ID and child cursor before examining DISPLAY_CURSOR output. A report about another cursor can make a technically valid investigation answer the wrong question. Lesson 4 develops this verification process in more detail.

Separate estimated plans from measured execution

EXPLAIN PLAN describes an estimated plan without running the target SQL to measure its performance. It is useful for learning and investigation, but an application's executed plan can differ. Do not report an explained cost as an observed runtime or assume that an estimated plan proves a hint improved response time.

Where runtime row-source statistics have been collected, comparing estimated and actual rows can help locate unexpected work. The collection and access requirements matter: requesting an ALLSTATS LAST display does not itself guarantee that all desired measurements exist.

A useful experiment records the original SQL, representative values, session settings, fetching pattern, and baseline measurements. Change one relevant factor, repeat under comparable conditions, and relate any plan differences to observed behavior. Cache state, concurrent activity, and client processing can otherwise obscure the effect being tested.

Decide what counts as success before reviewing the result. A first batch arriving sooner with more expensive complete fetching may be acceptable for a search interaction and unsuitable for an export. Both observations can be correct. Document the tradeoff rather than declaring one optimizer mode universally faster.

Keep historical material in its proper role

Historical RBO used predefined access-path rules and data dictionary information. CHOOSE belongs to the older period in which statistics influenced the choice of optimization approach. These concepts explain old manuals and application assumptions; they are not additional modern optimizer-mode choices.

Oracle documented RBO desupport beginning with Oracle Database 10g Release 1. The useful modernization question is how to validate supported cost-based behavior for the application, not how to revive an obsolete RULE-based tuning procedure.

Later optimizer and plan-management developments do not change the basic distinction between a goal, an estimate, and an observed outcome. Adaptive behavior, SQL profiles, and plan baselines deserve their own explanations. They should not be reduced to a version-by-version promise that automatic features always produce the fastest possible SQL.

Historical reference remains useful when investigating inherited code. Record why an old directive exists, compare supported alternatives on representative data, and retain evidence for any decision. Removing a legacy assumption is a change to validate, not a guarantee that every execution plan will remain identical.

Apply the module as a short tuning review

  1. Define the outcome. Identify correct results, initial-batch response, complete fetching, and resource use that matter to the caller.
  2. Record the environment. Capture effective settings, statement identity, representative values, and actual client fetching behavior.
  3. Examine the plan and estimates. Investigate unexpected work before assuming the optimizer goal is the cause.
  4. Test a focused change. Use documented syntax and an appropriate scope, preserving the original configuration.
  5. Verify and compare. Check hint handling or settings separately from measured application performance.
  6. Restore or document. Restore temporary changes and explain any retained setting, its evidence, and when to reassess it.

This sequence also helps explain a decision to keep the original setting. An experiment can show that the existing goal already meets the requirement or that another bottleneck dominates. A useful tuning result is an evidence-based decision, not necessarily a changed parameter or a newly added hint.

Work through a mixed application example

Suppose the same application offers an order-search screen and a monthly export. Both read orders, but their success criteria differ. Begin by tracing each caller's behavior: how many rows it requests, whether it continues fetching, and when it presents a usable result. Sharing a table does not mean the two operations need identical tuning decisions.

For the screen, establish a baseline for the first useful batch and for the less common interaction that requests many more rows. Include customers with small and large histories. If a focused goal hint is evaluated, confirm its handling and compare the resulting measurements. Keep the original SQL available so the comparison remains reproducible.

For the export, measure completion of the complete result under realistic conditions. A quick first batch followed by expensive remaining work is not an improvement merely because the initial screen test looked good. Also separate database fetching from file writing, network transfer, and application formatting so that the investigation targets the component responsible for the delay.

Afterward, the evidence might support different statement-level goals, the existing default for both operations, or further investigation of estimates and access paths. None of those outcomes requires declaring a universal winner. Record the workload assumptions with the result. If the search screen later gains an export button or begins fetching all rows eagerly, revisit the earlier decision because its original justification may no longer apply.

Terms to carry forward

Cost-based optimizer
The optimizer approach that estimates the work of candidate plans using available information.
Optimizer statistics
Information describing data and objects that helps inform planning estimates.
Optimization goal
The performance emphasis used when evaluating plan alternatives.
Access path
A method of obtaining rows from an object, forming part of a complete plan.
Execution plan
The operations selected to carry out a SQL statement.
Hint
An instruction embedded in a specially formatted SQL comment, subject to syntax, scope, and applicability rules.
Throughput and initial response
Different performance concerns: efficient complete processing and timely delivery of an initial portion of the result.

You should now be able to distinguish modern optimizer goals, inspect the relevant defaults, explain session and statement controls, and evaluate their effects using execution evidence. Use the preceding lessons for detailed examples. Treat the following rule-based material as historical reference; practical tuning work should continue within supported cost-based optimization.

Oracle reference material

SQL Optimizer Mode Defaults Quiz

The module quiz remains available for review. Apply the current distinctions above when considering optimizer terminology and historical settings.

SQL Optimizer Mode Defaults Quiz

SEMrush Software 5 SEMrush Banner 5