[MDEV-22583] Selectivity for BIT columns in filtered column for EXPLAIN is incorrect Created: 2020-05-15 Updated: 2021-06-10 Resolved: 2021-02-01 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.2.38, 10.3.28, 10.4.19, 10.5.10 |
| Type: | Bug | Priority: | Major |
| Reporter: | Varun Gupta (Inactive) | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | eits | ||
| Issue Links: |
|
||||||||
| Description |
|
So filtered here shows 99.61 % which is incorrect, selectivity should be ~66% Lets try with INT instead of BIT(32)
Filtered here is ~66%, so this looks correct. |
| Comments |
| Comment by Varun Gupta (Inactive) [ 2020-05-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The value for BIT fields in the statistical fields are stored as strings. To get the value from the statistical field we enter the function
So the statistical field has value 80, stored in string representation In the function Field_bit::store we have:
So the value 80 is stored as 2 bytes in the byte field which is not correct, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-05-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Patch | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2021-01-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have created a new patch where Varun's idea us used, but done with virtual functions instead of 'if (field_type == Field_bit). If Varun accepts this, it's ok to push. However, please fix commit message so that the first row is not split into two rows. Better to have the full MDEV message on the first row | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2021-01-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The reason bit fields are different is that they are basically a string type but used by statistics as a numerical type. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2021-02-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Have pushed my patch to 10.2. Will use monty patch for 10.5 as there will be conflicts when this code is merged upwards. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2021-02-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Diff for that is:
|