Description:
From the documentation:
https://dev.mysql.com/doc/refman/5.6/en/switchable-optimizations.html
It's not clear that SET GLOBAL optimizer_switch does not take effect in the current session, but rather all subsequent sessions. This can be confusing the operators setting the variable dynamically and then attempting to check their work.
mysql root@localhost ((none))> select @@version ;
+-----------------+
| @@version |
+-----------------+
| 5.6.27-75.0-log |
+-----------------+
1 row in set (0.00 sec)
How to repeat:
# with GLOBAL
mysql root@localhost ((none))> set global optimizer_switch="use_index_extensions=on"
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql root@localhost ((none))> select @@optimizer_switch ;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| @@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,subquery_materialization_cost_based=on,use_index_extensions=off |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
# without GLOBAL:
mysql root@localhost ((none))> SET optimizer_switch = 'use_index_extensions=on';
Query OK, 0 rows affected (0.00 sec)
mysql root@localhost ((none))> select @@optimizer_switch ;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| @@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,subquery_materialization_cost_based=on,use_index_extensions=on |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Suggested fix:
changes to optimizer_switch using SET GLOBAL should take effect in the current, as well as future sessions.