REOPTIMIZE
On this page
Reoptimize the most recently profiled query based on previous executions of it.
Syntax
REOPTIMIZE [[EXPLAIN] | [COMMIT]] [<reoptimize_level>]Remarks
-
The
REOPTIMIZEcommand is used with thePROFILEcommand to look for improved query plans. -
REOPTIMIZEworks on the most recently profiled query in the current connection. -
The keyword
EXPLAINshows the explain output for the reoptimized plan. -
Subsequent
REOPTIMIZEstatements will generate differing plans (<reoptimize_).level> Refer to specific subsequent plans with the corresponding number of the order in which the REOPTIMIZEwas executed.For example, if you run REOPTIMIZEthree times consecutively on the same query profile, you can rerun the second of the optimizations by referring to its place in the order of execution, like so:REOPTIMIZE 2; -
To save a reoptimize plan to apply to a query, use the
COMMITkeyword:REOPTIMIZE COMMIT 2;After running the above statement, the query will use the plan generated the second time
REOPTIMIZEwas executed. -
Refer to the Permission Matrix for the required permissions.
-
Refer to REOPTIMIZE MARK for automatic feedback reoptimization.
Example
PROFILE <query text>;REOPTIMIZE EXPLAIN; -- prints the explain of the reoptimized planREOPTIMIZE; -- runs the reoptimized plan as a profile;SHOW PROFILE; -- shows the reoptimized profileREOPTIMIZE; -- Runs reoptimize with the previous two executions statsREOPTIMIZE; -- Runs reoptimize with the previous three executions statsREOPTIMIZE 2; -- Runs the reoptimize plan from the second reoptimizeREOPTIMIZE COMMIT 2; -- Runs and saves the second reoptimize plan to <query text><query text>; -- Uses the committed reoptimize plan
Last modified: October 1, 2025