[MDEV-287] CHEAP SQ: A query with subquery in SELECT list, EXISTS, inner joins takes hundreds times longer Created: 2012-05-21 Updated: 2014-05-12 Resolved: 2012-06-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.5.25 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Timour Katchaounov (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Description |
|
The following query
on my machine takes 80 sec and more on the work tree vs 0.5 sec and less on the main 5.5 tree (tried revno 3413 and revno 3402). bzr version-info
Reproducible with the default optimizer_switch as well as with all OFF values (except for in_to_exists which is required to execute the query). EXPLAIN on the work tree (with the default optimizer_switch):
EXPLAIN on the main tree (with the default optimizer_switch):
Test case:
|
| Comments |
| Comment by Timour Katchaounov (Inactive) [ 2012-05-28 ] |
|
Analysis: The much slower execution in the case when constant subqueries are evaluated is a result of the subquery cache not working in this case. This is what happens in more detail. The subquery in the SELECT list contains a subquery. This subquery in turn contains a constant subquery.
The ultimate result is that once the subquery becomes non-correlated, it is not cached any more, and is executed for each result row combination (40K times in the example). I consider the above behavior a deficiency of the subquery cache. This is being investigated ATM. |
| Comment by Timour Katchaounov (Inactive) [ 2012-06-08 ] |
|
This problem is fixed by the following patch waiting for review: revno: 3406 Analysis: The fix for lp:944706 introduces early subquery optimization. The subquery cache is designed to work only for correlated subqueries. However, when the constant subquery was optimized away, it was neither Solution: The solution is to update the correlated status of the subquery after it has
Notice that his patch is an improvement over MySQL 5.6 and older, where |
| Comment by Timour Katchaounov (Inactive) [ 2012-06-19 ] |
|
Merged, tested, pushed. |