[MDEV-7220] Materialization strategy is not used for REPLACE ... SELECT Created: 2014-11-26 Updated: 2015-02-20 Resolved: 2015-02-20 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0.15 |
| Fix Version/s: | 10.0.17 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Materialization strategy is not used for REPLACE ... SELECT. Filing this based on CSC#8345.
Let's make a query with a subquery that is better executed with Materialization:
Ok.
3 min looks like it is too long for the above EXPLAIN plan. Indeed, SHOW EXPLAIN shows:
It is using IN->EXISTS conversion, not materialization. CREATE TABLE ... SELECT is not affected:
|
| Comments |
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
Debugging... REPLACE ... SELECT calls convert_join_subqueries_to_semijoins but then it exits here:
| ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
Here in is_materialization_applicable () we have:
while we have:
| ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
is_materialization_applicable() check is also used for non-semi-join materialization. | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
Tracking where this check of thd->lex->sql_command comes from...
| ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
Thinking of the reasons that Materialization won't work with non-select commands. Not finding any, so far. | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
Btw, there is a non intrusive fix possible: just change
to
This is certainly safe | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
http://lists.askmonty.org/pipermail/commits/2014-November/007074.html | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-11-26 ] | ||||||||||||||||||||||||||
|
elenst, could you run tests with the above commit (it is for current 10.0). The interesting test mixes would be those that use subquery materialization (need uncorrelated IN subqueries), and non-SELECT statements. | ||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-12-23 ] | ||||||||||||||||||||||||||
|
With the same test case as in the description, but instead of REPLACE, I do
Isn't it supposed to use materialization now, too? It doesn't:
and
| ||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2015-01-10 ] | ||||||||||||||||||||||||||
|
We discussed earlier that it's supposed to be looked at; re-assigning back so that it doesn't get lost. I ran a number of test rounds, didn't get wrong results or crashes. I didn't run performance tests since when DML is involved, it's too volatile to be run in an environment not specifically tuned for benchmarking. The issue above is what I got from manual testing. | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-02-20 ] | ||||||||||||||||||||||||||
|
elenst, the difference between the statements is quite big under the hood. REPLACE ... SELECT has a SELECT part (which has a JOIN structure, which allows for semi-join optimizations and so forth). The UPDATE you've found belongs to a class of single-table UPDATE/DELETE statements. We have a task for enabling semi-join optimization for those, | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2015-02-20 ] | ||||||||||||||||||||||||||
|
Ok I will push this fix |