[MDEV-6235] EXPLAIN UPDATE shows range when it should be eq_ref Created: 2014-05-13 Updated: 2014-05-16 Resolved: 2014-05-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.10 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Arjen Lentz | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | upstream | ||
| Environment: |
All,Linux |
||
| Description |
|
EXPLAIN UPDATE shows access method 'range' for a scenario where both parts of the primary key are referenced, with single constants. In fact, the query execution uses Handler_read_key and thus accesses only a single row. My conclusion: EXPLAIN UPDATE shows the wrong access method, while the actual query execution does the right thing. Schema below (from Drupal)
|
| Comments |
| Comment by Elena Stepanova [ 2014-05-13 ] | |||||||||||||||||||||||||
|
Same is true for MySQL 5.6:
| |||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-05-15 ] | |||||||||||||||||||||||||
|
The difference between "range" and "const" is relevant when optimizing joins. "const" tables are read before the join optimization is done, and then the optimizer takes advantage of knowing the values of const_table.column. | |||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-05-15 ] | |||||||||||||||||||||||||
|
"range" access can also increment Handler_read_key counter. try SELECT * FROM tbl WHERE pk IN (const1, const2, const3) | |||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-05-15 ] | |||||||||||||||||||||||||
|
Execution of SELECT FROM tbl WHERE pk=const will use join_read_const_table(). EXPLAIN correctly reflects that. UPDATE tbl SET ... WHERE pk=const will use QUICK_RANGE_SELECT. EXPLAIN correctly reflects that. So, this is not an EXPLAIN bug. | |||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-05-15 ] | |||||||||||||||||||||||||
|
One could argue that single-table SELECT and UPDATE should use the same execution paths. There are some differences between UPDATE and SELECT execution, but there are way more common things than different things. I was re-writing MariaDB from scratch today, I would have made UPDATE and SELECT use the same execution path. But in the current state, I don't think it is worth to rewrite UPDATE/DELETE to use SELECT's execution path. | |||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-05-15 ] | |||||||||||||||||||||||||
|
Closing. Feel free to reopen if the points in the comments do not address the issue. | |||||||||||||||||||||||||
| Comment by Arjen Lentz [ 2014-05-16 ] | |||||||||||||||||||||||||
|
No that's fine Sergei - of course I'm aware of how const works. |