[MDEV-6127] Incorrect Right Join execution Created: 2014-04-17 Updated: 2017-11-02 Resolved: 2017-11-02 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.1.67, 5.2.14, 5.3.12, 5.5.36, 5.5.37, 10.0.10 |
| Fix Version/s: | 5.5.56, 10.0.34, 10.1.29 |
| Type: | Bug | Priority: | Major |
| Reporter: | Konstantin | Assignee: | Oleksandr Byelkin |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | upstream | ||
| Environment: |
Does not matter |
||
| Sprint: | 5.5.44, 5.5.58, 10.1.29 |
| Description |
|
Hello all.
Now let's try the query:
What do I get:
What do I expect:
Now look at this query:
What do I expect (without 2 last columns):
I think that "test1.id" and "coalesce(test1.id)" are similar, yes? This means that both of queries must return a similar resultset. But the second query returns exactly what I expect. I think the reason is in query optimizer. It converts outer join to inner join because of using "test1.id" in ON clause. In this case it is not a correct behavior. It does not assume that the function used in this expression may work with nulls well. |
| Comments |
| Comment by Elena Stepanova [ 2014-04-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Konstantin, Reproducible on all of MySQL 5.1 - MySQL 5.7, MariaDB 5.1 - MariaDB 10.0 that I tried. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Expanding the function to an expression also returns correct resunt. EXPLAIN of both queries looks identical. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-04-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
test1.id+0 does not work so it is not "protection of transformation by the function. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-04-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
it looks like ability to be NULL fix the result:
works | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-04-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Difference between correct and incorrect execution for sure is inside SP, fere how result of execution of function differ (first is incorrect, second is correct):
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-04-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Probably the fact that test1.id can be NULL due to outer join is not taken into account | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-04-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
To avoid recreating test suite every time trees changed and cleaned:
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-06-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
in SP select list turned some how to this was: probably equality this equality worked in such strange way somehow: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-06-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
This looks suspicious taking into account that t4 is not constant: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-06-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
"correct" execution somehow avoid make_join_statistics() where one table referenced by a key become "const table" (it looks like quite correct, incorrect is the variable (key) value). | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-06-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
opt_sum_query() is for blame | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-06-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
In first statement (3rd call in it) we somehow do not have NULL values for the key lookup | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem was fixed by one of this commits: |