O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

optimizer_switch

 The optimizer_switch system variable is a set of flags. You can set each of those flags to ON or OFF to enable or disable the corresponding optimizer behavior. You can set it at the session level or global level dynamically. If you adjust the optimizer switch at the session level, all the queries in that session are affected, and if it is at the global level, all queries are affected.

For example, you have noticed that the preceding query, SELECT emp_no FROM employees WHERE first_name='Adam' OR last_name='Adam', is using sort_union(first_name,last_name_2). If you think that optimization is not correct for that query, you can adjust optimizer_switch to switch to another optimization:

mysql> SHOW VARIABLES LIKE 'optimizer_switch'\G ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required