Managing Plancache Memory and Disk Usage
On this page
Compiled query plan images, sometimes referred to as 'modules' or 'code modules', are stored in a plancache for later use.
Compiled query plan images may be removed from the in-memory plancache through expiration or eviction.
A plan expires from the in-memory plancache (called expiration) after the time interval specified by the plan_
engine variable has elapsed.
Plans are evicted from the in-memory plan cache (called eviction) when the plancache memory usage goes over the thresholds specified by compiled_
and compiled_
, as described below.
Whether a plan expires or is evicted from the in-memory plancache, that plan remains in the on-disk plancache and is loaded back into memory the next time the query is run.
Query plans expire from the on-disk plancache as described in Set Plan Expiration Limits.
Query plans can be manually removed from the in-memory plancache as described in Drop Plans from the Plancache.
Set Plan Expiration Limits
Plancache expiration policy can be set through the plan_
and disk_
engine variables.
Expiration for the in-memory and on-disk plancaches is always enabled.
Plans will expire from the on-disk plancache if the following three conditions are met:
-
The time limit specified by
disk_
is reached (assuming the plan has not been read from disk during that time), andplan_ expiration_ minutes -
The plan is not in the in-memory plancache.
This process also applies to temporary (temp) tables.
The following example shows how to set these variables to change the in-memory expiration limit to eight hours and set the on-disk expiration to one week.
SHOW VARIABLES LIKE '%plan_expiration%';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| disk_plan_expiration_minutes | 20160 |
| enable_disk_plan_expiration | ON |
| plan_expiration_minutes | 720 |
+------------------------------+-------+
3 rows in set (0.08 sec)
SET GLOBAL plan_expiration_minutes = 480;
Query OK, 0 rows affected (0.07 sec)
SET GLOBAL disk_plan_expiration_minutes = 10080;
Query OK, 0 rows affected (0.09 sec)
SHOW VARIABLES LIKE '%plan_expiration%';
+------------------------------+-------+
| Variable_name | Value |
+------------------------------+-------+
| disk_plan_expiration_minutes | 10080 |
| enable_disk_plan_expiration | ON |
| plan_expiration_minutes | 480 |
+------------------------------+-------+
3 rows in set (0.07 sec)
Manage Eviction of Compiled Query Plans
Note
Plan eviction and the information in this section is applicable when interpreter_
is set to interpret_
or compile
.
Compiled query plan images (sometimes referred to as 'modules' or 'code modules') are evicted using LRU (least-recently used) when the in-memory plancache reaches a set memory limit.compiled_
and compiled_
variables are used to specify the memory limit available for caching query plan images.enable_
engine variable is set to ON
, which is the default setting.
If the compiled_
and compiled_
variables are not set or are set to 0
, compiled_
will be set as a percentage of maximum_
as shown in the following table.
|
|
In-memory Plancache Memory Limit |
---|---|---|
0-1 |
Prohibited ( |
|
1-64 |
|
10% of |
64+ |
|
5% of |
If the compiled_
or compiled_
variables are set, the memory limit for the in-memory plancache is derived at runtime as shown in the following table.
The notation _
denotes compiled_
and _
denotes compiled_
.
_ |
_ |
In-memory Plancache Memory Limit |
---|---|---|
0. |
0 |
The value is derived in accordance with the default allocation rule specified in the table above. |
0. |
> 0 |
If |
> 0. |
Any value |
The value of |
If the compiled_
variable is set to a value other than 0.compiled_
is ignored.
Note
Changes to maximum_
may result in changes in the module cache limit, in accordance with the rules specified above.
Drop Plans from the Plancache
In addition to setting a retention policy for in-memory and on-disk plans, you may also choose to drop plans from the plancache to either compile a new query plan or reduce memory usage.
Successful completion of a new ALTER TABLE
will invalidate the plancache for all queries that operate on the affected table, requiring their recompilation.
ANALYZE
invalidates stale plans from both the in-memory and the on-disk plancache, including plans which are on-disk but not in-memory.
Note
The ANALYZE
command invalidates plans by marking them as invalid so they won’t be used in the future, but it does not actually delete all the files in the on-disk plancache.
Drop All Plans from the Plancache
To remove all plans from the in-memory and on-disk plancaches, SingleStore recommends the practice of temporarily setting plan_
and disk_
to 0
.0
will cause the plans in the plancaches to be marked as invalid and subsequently deleted by the garbage collector.
To forcibly drop all plans in the in-memory and on-disk plancaches:
Run SHOW VARIABLES
and save the current values for the plan expiration minutes engine variables.
SHOW VARIABLES LIKE '%plan_expiration_minutes'; /* be sure to save these values */
Set the plan expiration minutes engine variables to 0
and invoke SLEEP
to give the garbage collector time to delete the plans.SLEEP
may be needed depending on the size of the plancache and the speed of your disks.
SET GLOBAL plan_expiration_minutes=0;SET GLOBAL disk_plan_expiration_minutes=0;SELECT SLEEP(300);
Reset the plan expiration minutes engine variables to their previous values.
SET GLOBAL plan_expiration_minutes=<oldvalue>;SET GLOBAL disk_plan_expiration_minutes=<oldvalue>;
Related Topics
Last modified: April 7, 2025