MySQL Variables optimizer_switch 数据库 参数变量解释及正确配置使用

本站中文解释

MySQL的optimizer_switch参数变量用于配置优化器的行为,即控制MySQL的优化器的不同功能,影响MySQL查询的性能。通常有四类参数:on/off开关设置,后面附加+/-号,表明一次性设置所有。

下面详细介绍如何设置MySQL参数变量 optimizer_switch:

(1)首先,登录MySQL服务器,并在MySQL提示符下输入以下命令设置参数 optimizer_switch:

SET GLOBAL optimizer_switch=’option’;

这里option可以是on/off,或是on/off+/-,以控制MySQL优化器的不同功能。

(2)如果只需要设置optimizer_switch中的某些部分,可以采用如下命令:

SET GLOBAL optimizer_switch=’option1, option2, …’;

注意:这里的option1和option2,都是on/off+/-的组合,用逗号隔开,例如下面的例子:

SET GLOBAL optimizer_switch=’mrr=on,mrr_cost_based=off,block_nested_loop=off’;

(3)最后,使用 SHOW VARIABLES LIKE ‘optimizer_switch’ 命令检查设置是否成功。

官方英文解释

optimizer_switch

Command-Line Format --optimizer-switch=value
System Variable optimizer_switch
Scope Global, Session
Dynamic Yes
Type Set
Valid Values (≥ 5.7.33)

batched_key_access={on|off}

block_nested_loop={on|off}

condition_fanout_filter={on|off}

derived_merge={on|off}

duplicateweedout={on|off}

engine_condition_pushdown={on|off}

firstmatch={on|off}

index_condition_pushdown={on|off}

index_merge={on|off}

index_merge_intersection={on|off}

index_merge_sort_union={on|off}

index_merge_union={on|off}

loosescan={on|off}

materialization={on|off}

mrr={on|off}

mrr_cost_based={on|off}

prefer_ordering_index={on|off}

semijoin={on|off}

subquery_materialization_cost_based={on|off}

use_index_extensions={on|off}

Valid Values (≤ 5.7.32)

batched_key_access={on|off}

block_nested_loop={on|off}

condition_fanout_filter={on|off}

derived_merge={on|off}

duplicateweedout={on|off}

engine_condition_pushdown={on|off}

firstmatch={on|off}

index_condition_pushdown={on|off}

index_merge={on|off}

index_merge_intersection={on|off}

index_merge_sort_union={on|off}

index_merge_union={on|off}

loosescan={on|off}

materialization={on|off}

mrr={on|off}

mrr_cost_based={on|off}

semijoin={on|off}

subquery_materialization_cost_based={on|off}

use_index_extensions={on|off}

The optimizer_switch system
variable enables control over optimizer behavior. The value of
this variable is a set of flags, each of which has a value of
on or off to indicate
whether the corresponding optimizer behavior is enabled or
disabled. This variable has global and session values and can
be changed at runtime. The global default can be set at server
startup.

To see the current set of optimizer flags, select the variable
value:

mysql> SELECT @@optimizer_switch\G
*************************** 1. row ***************************
@@optimizer_switch: index_merge=on,index_merge_union=on,
                    index_merge_sort_union=on,
                    index_merge_intersection=on,
                    engine_condition_pushdown=on,
                    index_condition_pushdown=on,
                    mrr=on,mrr_cost_based=on,
                    block_nested_loop=on,batched_key_access=off,
                    materialization=on,semijoin=on,loosescan=on,
                    firstmatch=on,duplicateweedout=on,
                    subquery_materialization_cost_based=on,
                    use_index_extensions=on,
                    condition_fanout_filter=on,derived_merge=on,
                    prefer_ordering_index=on

For more information about the syntax of this variable and the
optimizer behaviors that it controls, see
Section 8.9.2, “Switchable Optimizations”.


数据运维技术 » MySQL Variables optimizer_switch 数据库 参数变量解释及正确配置使用