Details
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?
DROP TABLE IF EXISTS test;
CREATE TABLE `test` (
`id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;INSERT IGNORE INTO `test` VALUES(1234),(97716021308405775),(97716021308405770),(97716021308405780);
– OK
SELECT * FROM `test` WHERE `id` IN(97716021308405775);
SELECT * FROM `test` WHERE `id` IN("97716021308405775");
SELECT * FROM `test` WHERE `id` IN("1234",97716021308405775);
SELECT * FROM `test` WHERE `id` IN("1234","97716021308405775");
SELECT * FROM `test` WHERE `id` = 1234 OR id = "97716021308405775";– NOT OK (returns 4 records instead of 2)
SELECT * FROM `test` WHERE `id` IN(1234,"97716021308405775");
SELECT * FROM `test` WHERE `id` IN("97716021308405775",1234);
Attachments
Issue Links
- is blocked by
-
MDEV-22976 CAST(JSON_EXTRACT() AS DECIMAL) does not handle boolean values
-
- Closed
-
-
MDEV-29041 Redundant truncation warning on CAST(string_column AS DECIMAL)
-
- Closed
-
- is duplicated by
-
MDEV-25492 BETWEEN clause returns incorrect results on quoted 64-bit ints
-
- Closed
-
- relates to
-
MDEV-25871 compare error bigint to varchar
-
- Closed
-
-
MDEV-29259 Comparison semantic of int = string changes with creation of an index
-
- Confirmed
-
Activity
Field | Original Value | New Value |
---|---|---|
Component/s | Data types [ 13906 ] | |
Component/s | N/A [ 14411 ] | |
Fix Version/s | 10.1 [ 16100 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | 10.3 [ 22126 ] | |
Fix Version/s | 10.4 [ 22408 ] | |
Affects Version/s | 5.5 [ 15800 ] | |
Affects Version/s | 10.1 [ 16100 ] | |
Affects Version/s | 10.2 [ 14601 ] | |
Affects Version/s | 10.3 [ 22126 ] | |
Affects Version/s | 10.4 [ 22408 ] | |
Assignee | Alexander Barkov [ bar ] | |
Labels | in where | in upstream where |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Affects Version/s | 10.5 [ 23123 ] |
Fix Version/s | 10.5 [ 23123 ] |
Link |
This issue is blocked by |
Status | Confirmed [ 10101 ] | In Progress [ 3 ] |
Assignee | Alexander Barkov [ bar ] | Sergei Golubchik [ serg ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Assignee | Sergei Golubchik [ serg ] | Alexander Barkov [ bar ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Fix Version/s | 10.1 [ 16100 ] |
Attachment | MDEV-21445.diff [ 57500 ] | |
Attachment | MDEV-21445-REVIEW.txt [ 57501 ] |
Attachment |
|
Attachment | MDEV-21445-REVIEW.txt [ 57502 ] |
Link |
This issue relates to |
Link |
This issue relates to |
Link |
This issue relates to |
Assignee | Alexander Barkov [ bar ] | Oleksandr Byelkin [ sanja ] |
Link |
This issue relates to |
Labels | in upstream where | in need_feedback upstream where |
Labels | in need_feedback upstream where | in upstream where |
Assignee | Oleksandr Byelkin [ sanja ] | Alexander Barkov [ bar ] |
Workflow | MariaDB v3 [ 102851 ] | MariaDB v4 [ 143623 ] |
Link |
This issue is blocked by |
Fix Version/s | 10.3.36 [ 27513 ] | |
Fix Version/s | 10.4.26 [ 27511 ] | |
Fix Version/s | 10.5.17 [ 27509 ] | |
Fix Version/s | 10.6.9 [ 27507 ] | |
Fix Version/s | 10.7.5 [ 27505 ] | |
Fix Version/s | 10.8.4 [ 27503 ] | |
Fix Version/s | 10.9.2 [ 27115 ] | |
Fix Version/s | 10.2 [ 14601 ] | |
Fix Version/s | 10.3 [ 22126 ] | |
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.5 [ 23123 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Link |
This issue is duplicated by |
Link |
This issue relates to |
Link | This issue relates to MDEV-29259 [ MDEV-29259 ] |
Thanks for the report. Reproducible as described on 5.5-10.5 and MySQL 5.6, 8.0.