[MDEV-27472] ANALYZE: r_filtered=100 may look confusing when r_rows=0 Created: 2022-01-11 Updated: 2023-12-05 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2, 10.3, 10.4, 10.5, 10.6, 10.7 |
| Fix Version/s: | 10.4, 10.5, 10.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
So, neither the WHERE condition as a whole nor any part of it can keep any rows, and yet r_filtered is 100%. Also, it's unclear how the plan comes up with rows==2000 while the table has 1000 rows. Initially the issue popped up in the course of
|
| Comments |
| Comment by Sergei Petrunia [ 2022-01-12 ] | |||||||||||||||||||||||||||
Note that r_rows=0. This means that the access method has not returned any rows. Hence the condition was never checked, and in this case, we assume filtered=100%. (In case we want to discuss this: the logic is in class Table_access_tracker:
we could print e.g. null instead. | |||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-12 ] | |||||||||||||||||||||||||||
Looking at the trace
Ok so far...
We get the value of 2000 when we estimate #rows for ref_or_null. ref_or_null normally reuses the #rows estimate from the range optimizer. Indeed, as we saw, the range optimizer has generated one range:
This is because the WHERE was (I've added the brackets):
range optimizer was able to infer that the second line is always false. ref optimizer was not able to do that (as it doesn't analyze the "a>100" (also, the range optimizer actually has removed the second OR-part but ref optimizer wasn't able to take advantage of this as it runs before that is done)). Anyway, so ref optimizer is there and it only has index statistics to look at. index statistics says 1000 rows per key. then, this code is run which doubles the number due to NULL causing another value:
This is sensible in general case, but in this case (table has rec_per_key > half_of_table), it doesn't. | |||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-01-12 ] | |||||||||||||||||||||||||||
|
We should probably fix this, but I don't see this as urgent case. | |||||||||||||||||||||||||||
| Comment by Julien Fritsch [ 2023-12-05 ] | |||||||||||||||||||||||||||
|
Automated message: | |||||||||||||||||||||||||||
| Comment by JiraAutomate [ 2023-12-05 ] | |||||||||||||||||||||||||||
|
Automated message: |