Feedback Reoptimization

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. FR proactively detects suboptimal plans and triggers reoptimization, while also providing a precise, auditable way for users to explicitly mark a plan for reoptimization.

Traditional query optimization suffers from plan misestimation, especially as data grows and evolves. These misestimations can result in consistently poor query performance. FR automates detection and reoptimization of suboptimal plans, ensures safety under concurrency, provides concrete means for user control, and surfaces comprehensive runtime and historical feedback for observability.

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_auto_profile must be set to ON and auto_profile_type must be set to SMART. Use the command below to verify the values of these variables.

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

enable_automatic_feedback_reoptimization

Enables and disables FR.

Values: OFF, ON

optimizer_feedback_reoptimization_auto_marking

Enables and disables automatic FR marking.

Values: OFF, ON, AUTO

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. Plans can be automatically marked for FR or manually marked.

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. Qualified plans are marked 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. Ongoing or new queries use the currently valid plan instance, and are unaffected by in-process FR.

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_NOTES 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_NOTES 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_NOTES.

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_id.

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. For automatic FR, the flow is as follows.

  1. The user executes a complex query. 

  2. The system automatically profiles and detects a significant mismatch between the estimates used to create the plan and the actual runtime statistics.

  3. The plan is marked for FR.

  4. 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.

  5. 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:

  1. Run SHOW PLANCACHE to identify target plan_id.

  2. Run REOPTIMIZE MARK <plan_id> to mark the plan for FR.

  3. 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.

  4. Run SHOW FEEDBACK REOPTIMIZATION STATUS or use EXPLAIN to obtain diagnostic detail.

Last modified: June 13, 2025

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK