[MDEV-12838] Wrong results with materialization=on (with subquery and joins) Created: 2017-05-18 Updated: 2020-08-25 Resolved: 2017-06-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.0.30, 10.1.23, 10.2.5, 10.2 |
| Fix Version/s: | 10.1.25, 5.5.57, 10.0.32, 10.2.7 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Chris Calender (Inactive) | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Description |
|
With optimizer_switch materialization=on, the following test case fails with wrong results in MariaDB (tested 10.0.30, 10.1.23, and 10.2.5). This works with MySQL 5.6 and 5.7, and also with MariaDB if you set materialization=off. Here is sample output from the sql file (attached) when piped into MariaDB 10.2.5:
|
| Comments |
| Comment by Igor Babaev [ 2017-05-22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
First of all it makes sense to simplify the offending query:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-05-22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here's the explanation how it happens.
The subquery has the equality condition:
As a result we have these two possible keys to access the table sm_m2m_group_dependency0 from the tables sys_user_grmember0 and sys_user_group1_i.:
When the optimizer evaluates the partial join order: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-05-23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here' s an explanation why using a field not from the materialized table as a key to access an outer table does not cause a crash. The fact is that with the current implementation fields from the materialized table are always copied into the buffers for the tables of the materialized subquery. When the access keys are formed they are constructed over the values from these buffers. If a field does not belong to the result of materialization it's not copied, and some old value is read for this field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-05-31 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The patch with a fix of the problem was sent to Sergey Petrunia for a review. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-06-07 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The fix for this bug was pushed into the 5.5 tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Chris Calender (Inactive) [ 2017-06-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Why was this only fixed for 5.5.57, an old version most of our users are not using, and marked as closed. Shouldn't this be fixed for 10.0, 10.1, and 10.2? Or am I missing something? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-06-14 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It will be certainly merged up to all versions. I've updated the 'Fix version/s' field. |