Mysql parameter optimizer_switch

Source: Internet
Author: User

Optimizer_switch is introduced in mysql 5.1 to control the behavior of the mysql optimizer_switch. He has some result sets that enable and disable optimizer behavior through on and off control. The global validity period and session are used. The optional results of optimizer_swtich in mysql 5.5 are as follows. The results of optimizer_swtich vary with mysql versions. 5.1 and 5.6 refer to the official documentation. Mysql> select @ optimizer_switch; + centers + | @ optimizer_switch | + centers + | index_merge = on, index_merge_union = on, index_merge_sort_union = on, index_merge_intersection = on, engine_co Ndition_pushdown = on | + optimize + you can set optimizer_switch to control the optimization behavior during mysql optimization statements. In our production environment, one day the pressure on the mysql server was particularly high, and the load reached 100. The query found that the database had a large number of SQL statements in the state result sorting, result sorting consumes cpu and memory resources. Extract an SQL statement to view the execution plan. mysql> explain selectproduct_id, main_product_id, is_main_product, external_product_id from product where shop_id = '20170' AND status in ('0 ') AND main_product_id in ('0') AND product_type in ('0', '1') order by operator_datedesc limit 800,100; + ---- + ------------- + ---------------- + ------------- + ----------------------------------------------- + ------------------------------ + --------- + --- --- + ------ + Keys + | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | + ---- + ------------- + -------------- + ------------- + keys + --------- + ------ + ----------------------------------------------------------------------- ------- + | 1 | SIMPLE | product_common | index_merge | main_product_id, shop_id, status, product_type | shop_id, main_product_id, status | 5, 5 | NULL | 810 | Usingintersect (shop_id, main_product_id, status); Using where; Using filesort type is index_merge (index merging and sorting ). If the business requires or requires no index, many indexes will be created on the data table. For this query, you can modify optimizer_switch to optimize the optimizer_switch behavior: set global optimizer_seitch = "index_merge = off". This method also has certain risks and affects other SQL statements, exercise caution when operating on the server side. If the index you create is unreasonable, you can create a composite index and delete these Single Column indexes, which improves the SQL efficiency.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.