[MDEV-16374] filtered shows 0 for materilization scan for a semi join, which makes optimizer always pick materialization scan over materialization lookup Created: 2018-06-02 Updated: 2018-06-09 Resolved: 2018-06-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.0.36, 10.1.34, 10.2.16, 10.3.8, 10.4.0 |
| Type: | Bug | Priority: | Major |
| Reporter: | Varun Gupta (Inactive) | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The dataset:
If you look closely filtered=0 for the <subquery2> which means the optimizer predicted that no rows would be read. Due to this , the cost for such a plan would always be less than any other plan. |
| Comments |
| Comment by Varun Gupta (Inactive) [ 2018-06-02 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Introduced by this commit
| ||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-06-02 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Running the same query by using a derived table, we get the correct plan
| ||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-06-04 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Patch: | ||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-06-05 ] | ||||||||||||||||||||||||||||||||||||||||||
|
There is this code in make_join_statistics() which fetches the number of rows in the materialized table:
But then, the code in matching_candidates_in_table() uses table->stat_records():
Maybe it should it use s->records or s->found_records instead? | ||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-06-05 ] | ||||||||||||||||||||||||||||||||||||||||||
|
cond_selectivity is selectivity of condition w.r.t. the total number of rows in the table (that is, if the table has a range access, the cond_selectivity "includes" the selectivity of the range access). That is, the code in matching_candidates_in_table needs the number of rows in the table. Looking at members in JOIN_TAB:
(Also one can see that the code in best_access_path and elsewhere assumes s->records is the total number of rows in the table) | ||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-06-07 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Yesterday on the optimizer call agreed that
| ||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-06-09 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Pushed to 10.0 |