MySQL provides the ldquo; eq_range_index_dive_limitrdquo parameter to indicate which method MySQL uses in this case.
MySQL provides the ldquo; eq_range_index_pe_limitrdquo parameter to indicate which method MySQL uses in this case.
One guide
In the MySQL official manual, there is one sentence:
The optimizer can estimate the row count for each range using pes into the index or index statistics.
This is to say: the optimizer for each range segment (for example, "a IN (10, 20, 30)" is equivalent comparison, and the three range segments are actually simplified to three single values, 10, 20, 30, respectively. It is estimated that each range segment (expressed by range segments) is because most of MySQL's "range" scanning methods do range scanning, here, a single value can be considered as a special case of a range segment) includes the number of elements, and there are two estimation methods. One is to use the index to estimate the number of elements from pe to index, index pe for short; second, use the index statistical value for estimation.
Compared with the two methods, the effect is as follows:
1 index pe: the speed is slow, but the exact value can be obtained (MySQL implements the number of index items corresponding to the number index, so it is accurate)
2 index statistics: fast, but the obtained value may not be accurate.
2. In-depth
Why do we need to differentiate these two methods?
Simply put:
1. the query optimizer uses the cost estimation model to calculate the cost of each plan.
2. The cost is calculated for a single table scan. Therefore, the cost is also calculated for an index scan for a single table.
3. The calculation formula for a single table is usually: cost = number of elements * I/O average.
4. Therefore, no matter which scan method is used, the number of groups must be calculated.
5. When an expression like "a IN (10, 20, 30)" is encountered, it is found that column a has an index ,, you need to check the number of groups that can be scanned by this index and calculate the index scan cost, so we use the "index pe" and "index statistics" methods mentioned in this article.
Tri-Optimization
MySQL provides the "eq_range_index_pe_limit" parameter to indicate which method MySQL uses in this case. The usage is as follows:
This variable indicates the number of parameter ity ranges in an Inter ity comparison condition when the optimizer shold switch from using index pes to index statistics in estimating the number of qualifying rows. it applies to evaluation of expressions that have either of these equivalent forms, where the optimizer uses a nonunique index to look up col_name values:
Col_name IN (val1,..., valN)
Col_name = val1 OR... OR col_name = valN
-------------------------------------- Split line --------------------------------------
Install MySQL in Ubuntu 14.04
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Build a MySQL Master/Slave server in Ubuntu 14.04
Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS
Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04
MySQL-5.5.38 universal binary Installation
-------------------------------------- Split line --------------------------------------