[MDEV-19600] The optimizer should be able to produce rows=1 estimate for unique index with NULLable columns Created: 2019-05-26 Updated: 2020-01-15 Resolved: 2019-06-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3 |
| Fix Version/s: | 10.3.16, 10.4.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
When the optimizer considers a ref access for a full PRIMARY key, it will use an estimate of rows=1. The same will happen for a UNIQUE key, but only if the columns are not NULL-able. If any of the columns are NULLable, the estimate from index statistics is used. The reason is possible NULL values. A unique index with NULL-able columns may have multiple rows with NULL values. However, the most common type of join uses null-rejecting predicates, "keypart = ...". For those, NULLable UNIQUE index is the same as non-NULLable, and the optimizer should be able to figure out that it should use an estimate of rows=1. Testcase:
note, t1.rows=45 here. Index statistics:
(If you want to suggest to fiddle with innodb_stats_method, check out MDEV-19574 - persistent innodb stats will always use nulls_equal) |
| Comments |
| Comment by Sergei Petrunia [ 2019-05-27 ] |
|
Patch: http://lists.askmonty.org/pipermail/commits/2019-May/013803.html |
| Comment by Sergei Petrunia [ 2019-05-27 ] |
|
Igor, please review. |
| Comment by Igor Babaev [ 2019-05-30 ] |
|
OK to push this patch into 5.5 (Here I'm confused: the description says that it affects 5.5 and |
| Comment by Varun Gupta (Inactive) [ 2020-01-15 ] |
|
According to psergey the reason for pushing into 10.3 was that in the older versions the users are already fine with whatever plans they have. |