[MDEV-21445] Strange/inconsistent behavior of IN condition when mixing numbers and strings Created: 2020-01-08 Updated: 2022-08-18 Resolved: 2022-07-06 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 5.5, 10.1, 10.2.16, 10.3.21, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.3.36, 10.4.26, 10.5.17, 10.6.9, 10.7.5, 10.8.4, 10.9.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Ján Regeš | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | in, upstream, where | ||
| Environment: |
Tested on Debian with 10.3.21 and Gentoo with 10.2.16. |
||
| Attachments: |
|
||||||||||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Description |
|
Hi, today we encountered one strange behavior in an older project. Below are simple SQL statements that quickly show where the problem is. When combining a number and a number as a string in an IN WHERE condition, it sometimes returns extra unwanted records. As you can see, condition id = 1234 OR id = "97716021308405775" returns expected 2 records, but equivalent id IN(1234,"97716021308405775") returns 4 records. This unexpected behavior is independent on storage engine - it works the same with InnoDB, MYISAM or TokuDB. We'll fix our ORM layer to use the IN condition correctly (with either numbers or strings only), but maybe it's a bug in MariaDB that should be fixed. Maybe it's just old, familiar, unexpected behavior that can't be corrected?
|
| Comments |
| Comment by Elena Stepanova [ 2020-01-13 ] | |||||||||||||||||||||||||||||
|
Thanks for the report. Reproducible as described on 5.5-10.5 and MySQL 5.6, 8.0. | |||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-01-14 ] | |||||||||||||||||||||||||||||
|
The problem happens because convert_const_to_int() is applied inconsistently:
| |||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-06-18 ] | |||||||||||||||||||||||||||||
|
The same problem happen with a simple CASE:
| |||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-06-18 ] | |||||||||||||||||||||||||||||
|
BETWEEN works fine:
Searched CASE works fine:
| |||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-08-10 ] | |||||||||||||||||||||||||||||
|
A possible solution would be to compare pairs (int,string) as DECIMAL rather than DOUBLE. @serg suggests trying this starting from 10.2. We should suppress warnings when decimal2string() runs outside of the DECIMAL range, e.g. :
as the comparison to INT will work correctly anyway. | |||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-08-10 ] | |||||||||||||||||||||||||||||
|
The problem is also repeatable with engines MyISAM and HEAP.
| |||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-08-25 ] | |||||||||||||||||||||||||||||
|
serg, please review a patch for 10.3: https://github.com/MariaDB/server/commit/d19f380d62c3145258c229d102b829c2f1c77223 Thanks. | |||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-09-21 ] | |||||||||||||||||||||||||||||
|
Probably this is the review: https://lists.launchpad.net/maria-developers/msg12411.html |