[MDEV-11279] There are difference explain in SELECT query and UPDATE query. Created: 2016-11-14 Updated: 2017-02-08 Resolved: 2017-02-08 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0.20 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | sungwon.han | Assignee: | Sergei Petrunia |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
CentOS 6.7 |
||
| Attachments: |
|
| Description |
|
There are different query in update and select query. 1) UPDATE QUERY
2) SELECT QUERY
Then, I change the original query to multi-update join query. This query belows.
I attached create table ddl script. Why did make the difference? |
| Comments |
| Comment by Sergei Petrunia [ 2017-02-08 ] | ||||||||||||||||||||
|
Looking at the query plans:
vs
| ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-02-08 ] | ||||||||||||||||||||
|
These are essentially the same plans. They will read the same sets of rows. Note the same key, key_len, rows, and Extra columns. The difference comes from how MariaDB (or MySQL) optimizer works internally. Single-table update always reads a single table. It may scan a range on an index, which it does in this case. On the other hand, any SELECT (including the {{( SELECT CORP_TYPE ... ) A }} in the second query is considered as a potential join, even if the said select has just one table.
so that one can do lookups in table tbl2 on tbl2.key = tbl1.column. However, as a special case, ref access works for tbl2.key =constant as well. This is what your example has: type=ref, ref=const,const,const,const. But it will still use the same restrictions and read the same rows. | ||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-02-08 ] | ||||||||||||||||||||
|
gks3117, hope the above makes sense. Feel free to re-open if you still think something is wrong. |