MySQL has provided the optimizer Option Switch option since 5.1. In this way, we can force some things that we think should not be done when the optimizer is confused, or when we want to see why the optimizer wants this
MySQL has provided the optimizer Option Switch option since 5.1. In this way, we can force some things that we think should not be done when the optimizer is confused, or when we want to see why the optimizer wants this
MySQL has provided the optimizer Option Switch option since 5.1. In this way, we can force some things that we think should not be done when the optimizer is confused, or when we want to see why the optimizer is so selective, you can manually disable or enable these options to change the optimization policy.
MySQL adds more switch options starting from 5.5 and 5.6. To optimize the query. Next I will explain the meanings and usage of these optimization switches one by one.
In MySQL 5.1, the following switch is added:
Index_merge
1). index_merge_intersection
If two independent indexes are available, but none of them is optimal, the optimizer will merge the two indexes and create an intersection in their result set, then match the disk data based on the intersection.
2). index_merge_union
For OR, connect all related indexes, find the corresponding ROWID of the record, and then obtain the data on the disk based on the ROWID.
3). index_merge_sort_union
For OR, connect all related indexes, find the corresponding ROWID of the record, and set the order, and then obtain the data on the disk based on the ROWID.
MySQL 5.5 adds the following switch:
Engine_condition_pushdown
Only used for the NDB engine.
Disabled: data on all data nodes is sent to the SQL node for processing.
After enabling: Data filtered Based on the WHERE condition is sent to the SQL node for processing.
In MySQL 5.6, the following switch is added:
1. mrr
Mrr_cost_based
This is a switch added from MySQL 5.6. It means to maximize resource utilization for common indexes, mainly for multi-column indexes, also called composite indexes for basic scanning, and then sort matching records by primary key, in this way, all required records are scanned from the disk in an ordered primary key order. The fundamental function is to convert random scanning of disks into sequential scanning.
The main target is that the data is too large to be stored in the CACHE (such as INNODB or MYISAM ). Currently, full index scanning is of little significance.
2. batched_key_access
(In the join buffer pool) after the inner table is scanned, find the corresponding primary key value for the scanned records and ** give it to the MRR interface at a time. Saves the IO portion that frequently interacts with the disk.
3. block_nested_loop
(In the join buffer pool) when the internal table is scanned, add a match mark for the original record to generate a new record. In this way, if the value of the External table is traversed again, only the unmatched values can be scanned. Saves some CPU resources.
4. index_condition_pushdown
Disabled: For composite index (A, B), if A can use index and B cannot, A can only be found on the index tree, then, use the pointer corresponding to A to traverse the data on the disk.
After enabling: For composite indexes (A, B), if A can use indexes and B cannot, find A on the index tree, then, use the filter condition of B to filter the data on the index tree, and then use the deleted pointer to traverse the data on the disk.
However, the ICP does not change random scanning to sequential scanning, but reduces the I/O of disk interaction.
5. use_index_extensions
It is mainly used for the second index of INNODB, that is, a common index, to take advantage of the primary key values contained in the index. For example, the primary key is (a, B) and the index is (c ). if index c is used, the index is changed to (c, a, B), and a new composite index can be used.
However, this type of scenario is rarely used. It is generally used for retrieval based on the first field in the combination primary key and the common index.
6. semijoin
Table deduplication during connection.
For example, for the following query, a. class_id only needs to scan the record with the same id as B. id once. Because you do not need to worry about the number of identical class_id in Table B, you just need to know whether there is or not.
Therefore, most subqueries are optimized.
Mysql> select B. class_name from class as B, student as a where. class_id = B. id; + ------------ + | class_name | + ------------ + | xinxi | + ------------ + 2 rows in set (0.00 sec)
7. firstmatch
Only the first record matching the External table is selected.
8. loosescan
Based on the index grouping, you can obtain the first data in each group.
9. materialization
Subquery_materialization_cost_based
Remove the internal table and generate a temporary table with the corresponding index (similar to the materialized view in other data). Then, traverse the temporary table through the corresponding foreign key value.
Mainly for retrieval types that cannot catch Huawei semi-connections.
This article is from "god, let's see it !" Blog, please keep this source