[MDEV-326] EXPLAIN+ORDER BY: Different plans produced by SHOW EXPLAIN and EXPLAIN Created: 2012-06-08 Updated: 2016-04-18 Resolved: 2016-04-18 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0.10 |
| Fix Version/s: | 10.2.0 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
For the following query
the plan produced by SHOW EXPLAIN contains 'Using where; Using index' in the Extra field, while normal EXPLAIN only says 'Using index'. bzr version-info
Reproducible with Aria and InnoDB, with the default optimizer_switch. SHOW EXPLAIN:
EXPLAIN:
Test case:
|
| Comments |
| Comment by Sergei Petrunia [ 2012-06-19 ] | |||||||||||||
|
With latest 5.5-show-explain, I was able to replicate with these sync commands: set @show_explain_probe_select_id=1; EXPLAIN:
SHOW EXPLAIN:
| |||||||||||||
| Comment by Sergei Petrunia [ 2012-06-19 ] | |||||||||||||
|
As one can see, I don't get the "Using where" vs "Using where; Using index" difference. However, I get these differences:
| |||||||||||||
| Comment by Sergei Petrunia [ 2012-06-19 ] | |||||||||||||
|
The original testcase also has rows=8 vs rows=98 difference. Table al1 is accessed with type='index', there is no LIMIT clause. This means, we will scan the whole index. There are 98 rows in the table, so SHOW EXPLAIN shows the correct value, while EXPLAIN shows the wrong one. | |||||||||||||
| Comment by Sergei Petrunia [ 2012-06-19 ] | |||||||||||||
|
The query hits these lines in test_if_skip_sort_order(): if (tab->join->select_options & SELECT_DESCRIBE) { tab->ref.key= -1; tab->ref.key_parts= 0; if (select_limit < table->file->stats.records) tab->limit= select_limit; }At this point, select_limit==8. The value of 8 was obtained in This could make some sense if we did a GROUP BY operation, but the query has The query has HAVING (which doesn't seem to make much sense). If I remove the | |||||||||||||
| Comment by Sergei Petrunia [ 2012-07-25 ] | |||||||||||||
|
Regarding the "Using where" part:
Item* sort_table_cond= make_cond_for_table(... which will take the HAVING and attach it to the first JOIN_TAB, effectively putting it into the WHERE. For this particular example, it is correct that SHOW EXPLAIN shows "Using where", if you catch it during the query execution. | |||||||||||||
| Comment by Elena Stepanova [ 2014-04-13 ] | |||||||||||||
|
On the current 10.0 tree (10.0.10+) I'm not getting 8 vs 98 difference; but on the other hand, there is no 'Using where' in SHOW EXPLAIN, so, if what the previous comment suggests it's true and it should be there, there's still a bug: EXPLAIN:
SHOW EXPLAIN:
(If it's not a bug, please close). | |||||||||||||
| Comment by Sergei Petrunia [ 2016-04-18 ] | |||||||||||||
|
The issue is not repeatable after |