[MDEV-26663] MariaDB 10.5.11: Need for chars within brackets in query DELETE FROM ... WHERE x IN (...) Created: 2021-09-22  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.5.11
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Alan Stolc Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Debian Buster



 Description   

Hello people of MariaDB,

we have observed a minor but annoying bug, hopefully not a feature. Please see below.

mysql> SELECT VERSION();
+--------------------------------------------+
| VERSION()                                  |
+--------------------------------------------+
| 10.5.11-MariaDB-1:10.5.11+maria~buster-log |
+--------------------------------------------+
 
mysql> desc rating;
+------------------------------+-----------------------+------+-----+---------------------+-------------------------------+
| Field                        | Type                  | Null | Key | Default             | Extra                         |
+------------------------------+-----------------------+------+-----+---------------------+-------------------------------+
| user_id                      | bigint(20) unsigned   | NO   | PRI | 0                   |                               |
.
.
.
+------------------------------+-----------------------+------+-----+---------------------+-------------------------------+
 
 
mysql> explain select user_id from rating where user_id in (3322217720125498802, 17417331430921724792, 4812081455371997970);
+------+-------------+--------+-------+---------------+------------------------+---------+------+----------+--------------------------+
| id   | select_type | table  | type  | possible_keys | key                    | key_len | ref  | rows     | Extra                    |
+------+-------------+--------+-------+---------------+------------------------+---------+------+----------+--------------------------+
|    1 | SIMPLE      | rating | index | *PRIMARY*       | last_record_update_idx | 4       | NULL | 10882993 | Using where; Using index |
+------+-------------+--------+-------+---------------+------------------------+---------+------+----------+--------------------------+
 
mysql> explain delete from rating where user_id in (3322217720125498802, 17417331430921724792, 4812081455371997970);
+------+-------------+--------+------+---------------+------+---------+------+----------+-------------+
| id   | select_type | table  | type | possible_keys | key  | key_len | ref  | rows     | Extra       |
+------+-------------+--------+------+---------------+------+---------+------+----------+-------------+
|    1 | SIMPLE      | rating | ALL  | *NULL*          | NULL | NULL    | NULL | 10882740 | Using where |
+------+-------------+--------+------+---------------+------+---------+------+----------+-------------+
 
mysql> explain delete from rating where user_id in ('3322217720125498802', '17417331430921724792', '4812081455371997970');
+------+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| id   | select_type | table  | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+------+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
|    1 | SIMPLE      | rating | range | *PRIMARY*       | PRIMARY | 8       | NULL | 3    | Using where |
+------+-------------+--------+-------+---------------+---------+---------+------+------+-------------+

So as you can see, if user_ids in brackets aren't chars, primary key is not used when deleting. This is weird, because ids are not chars but bigints, therefore this should work even with numbers only.
Can you please check, if this is a bug or a feature? This used to work for us in 10.2.

Thanks and regards,
Alan



 Comments   
Comment by Sergei Golubchik [ 2021-12-25 ]

Caused by 74891ed.

Test:

create table t1 (a serial);
explain select * from t1 where a in (3322217720125498802, 17417331430921724792, 4812081455371997970);
explain delete from t1 where a in (3322217720125498802, 17417331430921724792, 4812081455371997970);
explain delete from t1 where a in ('3322217720125498802', '17417331430921724792', '4812081455371997970');
drop table t1;

Generated at Thu Feb 08 09:47:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.