[MDEV-31303] Key not used when IN clause has both signed and unsigned values Created: 2023-05-18 Updated: 2023-08-29 Resolved: 2023-08-29 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.3.38, 10.4.28, 10.6.13 |
| Fix Version/s: | 10.5.23, 10.6.16, 10.10.7, 10.11.6, 11.0.4, 11.1.3, 11.2.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Iliya Polihronov | Assignee: | Vicențiu Ciorbaru |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Debian |
||
| Description |
|
When using IN() operator, if the provided values are both within the 1st half and the 2nd half of the column size ( < 9223372036854775808 and >= 9223372036854775808 for unsigned bigint), the index is not used. This behavior has changed from the 10.1.* versions where the index was correctly used. SQL to reproduce:
|
| Comments |
| Comment by Vicențiu Ciorbaru [ 2023-06-06 ] | ||||||
|
Preliminary investigation in this: This is related to the type system. The fix will require a bit more analysis, however I have a workaround: Cast all values in the IN clause as UNSIGNED.
This will make the optimizer know that the types are compatible. I'll work on a proper fix for this. | ||||||
| Comment by Vicențiu Ciorbaru [ 2023-08-28 ] | ||||||
|
Hi bar! Please review this patch that fixes a "regression" introduced by Ideally, I'd like to push this to 10.4, so it fixes the user's problem, but please review this in the context of 11.3 for now and if you think that it is safe enough, we can push this to older versions. I have tried various approaches to make this work and this is the cleanest I could come up with, without taking apart the multiple-inheritance that Item_func_in has. I've explained the bugfix in the commit message, as well as code comments. Let me know if it is clear enough. | ||||||
| Comment by Alexander Barkov [ 2023-08-29 ] | ||||||
|
Hi cvicentiu, Please review a modified version of the patch implementing (as discussed on slack) it in a slightly different way:
https://github.com/MariaDB/server/commit/3096cdb57b3c5b3c0c38e4538186f5c6f5fc4d03 The patch is good starting from 10.5. For 10.4 it would need some additional changes, let's skip 10.4. Thanks. | ||||||
| Comment by Vicențiu Ciorbaru [ 2023-08-29 ] | ||||||
|
Hi bar. Patch looks good to me. Buildbot should clear it first of course, but if no other tests fail, this fixes the issue. |