[MDEV-30015] full join vs left join results in a table scan vs. 1 row access Created: 2022-11-15 Updated: 2022-11-21 Resolved: 2022-11-21 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | N/A |
| Affects Version/s: | None |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Critical |
| Reporter: | Marc | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Description |
|
In version 10.5.17 The reordering algorithm looks very strange and the results are not the best.
The query plan is as follows:
if you change the last LEFT JOIN as intended to a FULL JOIN, the result is:
For me (looking at the tables), it is not obvious, how mariadb manages to move "sli" to the front and reorder the query - and has the result of "0 rows" - which should be filtered=100.00 not 0 - and as a result, this query should be faster than the left join - but the oposite is the case. I had to manually kill this query; the left join query runs in 0.084s. I assume the probleme here is the result of 0 rows in the first place. The total result is 0 rows. |
| Comments |
| Comment by Marc [ 2022-11-15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
reanalyzing all tables for the whole database seems to somehow "fix" the problem, as the full join is appended:
this is still weired. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ralf Gebhardt [ 2022-11-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Changed to bug to get the bug report verified | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2022-11-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
mokraemer, there is no FULL JOIN in MariaDb, could you please show the query in a question? maybe FULL was interpreted as an alias? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marc [ 2022-11-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I think the problem occured, when table stats are inaccurate, e.g. a table is just created and still empty and then gets filled. If no analyze table is issued, the optimizer makes very strange decissions. In that particular case "rdShopLieferantItems sli" was [inner] joined and does not have any results (0 items), but was stated as filtered "0.00%" instead of "100%" (as no results were found). But after issueing an analyze table, I'm not able to reproduce this issue, even with a new table - just close it - sorry for bothering you. |