Bug #59266 | EXPLAIN output does not show full length of clustered indexes | ||
---|---|---|---|
Submitted: | 4 Jan 2011 1:28 | Modified: | 5 Jan 2011 13:25 |
Reporter: | Andrew Dalgleish | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S4 (Feature request) |
Version: | OS: | Any | |
Assigned to: | CPU Architecture: | Any |
[4 Jan 2011 1:28]
Andrew Dalgleish
[4 Jan 2011 7:47]
Valeriy Kravchuk
If index on col3 is used it is a bug by itself... Now, what additional information this full length will give us, taking into account that access path is "index", that is, entire index is scanned anyway (see http://dev.mysql.com/doc/refman/5.1/en/explain-output.html#jointype_index)? Just check index definition to see columns it is defined on.
[4 Jan 2011 11:32]
MySQL Verification Team
The use of the index on col3 is not a bug; using the secondary index on col3 (which also includes col1 and col2) uses fewer disk IOs than using either the primary index on (col1, col2) or a full table scan. This is mentioned in the manual: ----- It is possible that key will name an index that is not present in the possible_keys value. This can happen if none of the possible_keys indexes are suitable for looking up rows, but all the columns selected by the query are columns of some other index. That is, the named index covers the selected columns, so although it is not used to determine which rows to retrieve, an index scan is more efficient than a data row scan. ----- The only issue is that the EXPLAIN output doesn't make it clear when the primary columns of a secondary index are used in this way, and doesn't show the full length of the index used.
[4 Jan 2011 11:44]
Valeriy Kravchuk
OK, you are right. For InnoDB table with that many long columns in the table scan of entire primary key means scan of entire big table. Scan of index on col3, where only col3 + two columns from primary key are used, is, indeed, faster. Anyway, as "index" access path means that entire index is scanned, what is the point to add exact size of index record for this specific case of InnoDB table?
[5 Jan 2011 5:17]
MySQL Verification Team
The only point is that the length displayed is not the length actually used. It is not critical as you can infer it once you understand what is happening, but it would be nice to have it spelled out though.