[MDEV-410] EXPLAIN shows type=range, while SHOW EXPLAIN and userstat show full table scan is used Created: 2012-07-24 Updated: 2012-07-25 Resolved: 2012-07-25 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 10.0.0 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
For the following query
usual EXPLAIN produces
while SHOW EXPLAIN says
As always, SLEEP in the query is not essential, it just makes the query a bit longer and allows to catch it by SHOW EXPLAIN. bzr version-info (5.5-show-explain-test1)
Test case:
|
| Comments |
| Comment by Sergei Petrunia [ 2012-07-25 ] | ||||||||||||||||||||||||||||
|
It seems, SHOW EXPLAIN's output is correct, and EXPLAIN is wrong. Let's create a copy of t2 so that accesses to t2-outside-the-subquery and t2-inside-the-subquery are counted separately: create table t2a like t2; Then I run: and then I see: MariaDB [j12]> show index_statistics;
-------------
------------- MariaDB [j12]> show table_statistics;
-------------
------------- As one can see, there were 2 rows read from table t2, and they were not read through an index. | ||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2012-07-25 ] | ||||||||||||||||||||||||||||
|
Debugged SELECT and its EXPLAIN concurrently. The difference is in make_join_statistics(), here: /* if (!tab->table->is_filled_at_execution() && | ||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2012-07-25 ] | ||||||||||||||||||||||||||||
|
The difference comes from different value of tab->const_keys(), which comes from update_ref_and_keys() , from add_key_fields() call for this part of the WHERE condtion: (`j14`.`t2`.`b` = (select min(`j14`.`t2`.`b`) from `j14`.`t2`)) Here, the right part is an Item_singlerow_subselect, and it has item->const_item() == FALSE for the EXPLAIN and TRUE for the SELECT. | ||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2012-07-25 ] | ||||||||||||||||||||||||||||
|
Verified that the problem with EXPLAIN being inconsistent with userstat profiling exists on the current mariadb-5.5 ( sanja@montyprogram.com-20120724145006-17q5hre8fwp1toql ) | ||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2012-07-25 ] | ||||||||||||||||||||||||||||
|
Figured out this is a problem in EXPLAIN, not in SHOW EXPLAIN. |