Feedback Reoptimization
On this page
Note
This feature is an opt-in preview.
Opt-in previews allow you to evaluate and provide feedback on new and upcoming features prior to their general availability.
Feedback Reoptimization (FR) is an automatic mechanism that optimizes query plans based on execution statistics rather than on optimizer estimates.
Traditional query optimization suffers from plan misestimation, especially as data grows and evolves.
Functionality
Concepts
-
Feedback Reoptimization (FR): An automatic mechanism that optimizes query plans based on execution statistics rather than on optimizer estimates.
-
Automatic FR Marking: A sub-feature of FR.
The engine automatically detects suboptimal plans and marks such plans for FR. -
Manual FR Marking: Manually mark a plan for FR using the REOPTIMIZE MARK command.
-
Explicit Reoptimization: Manually reoptimize a plan by executing the REOPTIMIZE command.
Configure Feedback Reoptimization
To use FR, enable_
must be set to ON
and auto_
must be set to SMART
.
SELECT @@enable_auto_profile, @@auto_profile_type;
+-----------------------+---------------------+
| @@enable_auto_profile | @@auto_profile_type |
+-----------------------+---------------------+
| 1 | SMART |
+-----------------------+---------------------+
The following engine variables are used to configure FR.
Name |
Description |
---|---|
|
Enables and disables FR. Values: |
|
Enables and disables automatic FR marking. Values: |
Enable FR with the following command.
SET SESSION enable_automatic_feedback_reoptimization = ON;
Enable automatic FR marking with the following command.
SET SESSION optimizer_feedback_reoptimization_auto_marking = AUTO;
Disable FR and automatic FR marking with the following commands.
SET SESSION enable_automatic_feedback_reoptimization = OFF;SET SESSION optimizer_feedback_reoptimization_auto_marking = OFF;
Feedback Reoptimization Process
When FR and automatic FR marking are enabled, FR occurs automatically without user intervention.
The FR process begins with a plan being marked for FR.
When automatic FR marking is enabled, after each query execution, FR analyzes runtime statistics and compares estimated versus actual statistics including for row counts, CPU usage, memory, and network usage.
FR uses metrics including: amount of misestimation, query execution time, existence of a compiled plan, and performance of previous FR plans to determine if a plan qualifies for FR.
Alternatively a plan can be manually marked for FR.
Once plan is marked for FR, plan replacement works as follows:
-
FR generates a new plan, collects metrics for the new plan (CPU time, memory, network usage), and then compares the metrics for the new plan with the metrics for the original plan.
-
If the following conditions are met, the new plan is adopted, if not, the new plan is dropped and the original plan remains.
-
At least one metric must improve significantly.
-
No metrics must worsen significantly.
-
To avoid infinite cycling, total FR attempts per plan are capped.
Remarks
-
Parameter Sensitivity: Automatic FR does not address parameter sensitivity issues.
For such scenarios, FR may need to be temporarily disabled. -
Compilation Consistency: FR is only triggered on fully compiled runs to ensure stats are comparable; async compilation may yield misleading stats.
-
Short/Low-Latency Queries: Very fast queries are excluded from FR to avoid unnecessary overhead and system churn.
-
Concurrency and Failures: Concurrency controls completely isolate plan swaps and drops, ensuring zero disruption to ongoing queries.
Cleanup is handled by garbage collection.
Monitor Feedback Reoptimization
FR can be monitored systemwide using the SHOW FEEDBACK REOPTIMIZATION STATUS command or per-query by viewing OPTIMIZER_
from the PLANCACHE.
Systemwide Monitoring
The following command displays system-wide FR information.
SHOW FEEDBACK REOPTIMIZATION STATUS;
The output displays up-to-date atomic counters, including:
-
The number of feedback-reoptimized queries currently running.
-
The number of plans marked for FR.
-
The total number of plans in the plancache.
-
Configured threshold values.
-
System-level stats from startup including total automatic and explicit feedback reoptimizations and number of skips of FR.
Per-Query Monitoring
The OPTIMIZER_
in the PLANCACHE view provide information about FR including:
-
If, when, and how many times a plan was feedback reoptimized.
-
If a plan was feedback reoptimized, which metrics improved with that reoptimization.
-
Historical observed improvement and variance per feedback-reoptimization step.
-
Largest estimation mismatches to support diagnosis and audit.
Run this command to see the OPTIMIZER_
.
SELECT OPTIMIZER_NOTES FROM information_schema.PLANCACHE WHERE ...;
Manually Mark a Plan for Feedback Reoptimization
You can manually mark a plan that has been profiled for reoptimization using the plans plan_
.
Run the following series of commands to manually mark a plan for FR:
-
Run SHOW PLANCACHE to list plans and obtain the
ID
of the plan to be reoptimized.SHOW PLANCACHE; -
Run REOPTIMIZE MARK to mark the plan for FR.
REOPTIMIZE MARK <plan_id>;
After a plan has been marked, the next execution of the query will trigger FR.
Examples
Example 1: Automatic Feedback Reoptimization Flow
FR happens automatically without user intervention.
-
The user executes a complex query.
-
The system automatically profiles and detects a significant mismatch between the estimates used to create the plan and the actual runtime statistics.
-
The plan is marked for FR.
-
On the next execution of the plan, FR runs automatically; the statistics are compared, and the FR plan is swapped in if significant improvement is detected in at least one metric, and other metrics do not worsen significantly.
-
Run SHOW FEEDBACK REOPTIMIZATION STATUS or use EXPLAIN to obtain diagnostic detail.
Example 2: Manual Marking Flow
You can manually trigger FR using following these steps:
-
Run SHOW PLANCACHE to identify target
plan_
.id -
Run REOPTIMIZE MARK <plan_
id> to mark the plan for FR. -
On the next execution of the plan, FR runs automatically; the statistics are compared, and the FR plan is swapped in if significant improvement is detected in at least one metric, and other metrics do not worsen significantly.
-
Run SHOW FEEDBACK REOPTIMIZATION STATUS or use EXPLAIN to obtain diagnostic detail.
Last modified: June 13, 2025