Deep Dive: Oracle Optimizer Internals – Dynamic Sampling & Optimizer Feature Enable (OFE)
When tuning Oracle Database performance at an advanced level, two often underutilized yet highly impactful parameters come into play:
Understanding how these influence the Cost-Based Optimizer (CBO) can significantly improve execution plan stability and query performance.
1. OPTIMIZER_DYNAMIC_SAMPLING – Smarter Cardinality Estimates
Dynamic Sampling allows the optimizer to collect runtime statistics when existing object statistics are missing, stale, or insufficient.
Why it matters: The optimizer’s decisions depend heavily on cardinality estimates. Poor estimates = poor plans.
Levels (0–11):
Advanced Insight:
Trade-off: Higher levels increase parse time due to sampling overhead. Use selectively (session-level or SQL hint).
Example:
ALTER SESSION SET OPTIMIZER_DYNAMIC_SAMPLING = 6;
2. OPTIMIZER_FEATURES_ENABLE (OFE) – Version-Control for the Optimizer
OFE acts as a compatibility switch that controls optimizer behavior based on a specific Oracle release.
Why it matters: Each Oracle version introduces optimizer enhancements—but sometimes these changes can regress performance for legacy workloads.
Key Use Cases:
Example:
ALTER SESSION SET OPTIMIZER_FEATURES_ENABLE = '19.1.0';
What it affects:
Dynamic Sampling vs OFE – How They Interact
Even with a modern OFE, poor statistics can lead to suboptimal plans—this is where dynamic sampling complements the optimizer.
Pro Tips from the Field
Final Thought
Oracle’s optimizer is incredibly powerful—but not infallible. Mastering parameters like Dynamic Sampling and OFE allows you to guide it with precision rather than guesswork.
Performance tuning isn’t just about fixing slow queries—it's about engineering predictable, scalable execution plans.
Note: This content is shared strictly for informational and educational purposes only. The concepts discussed are based on general Oracle Database behavior and real-world experience, but may not apply universally to every environment.