[MDEV-8026] use index when IN list contains tuples Created: 2015-04-20  Updated: 2015-10-31

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Fix Version/s: None

Type: Task Priority: Major
Reporter: Jiri Kavalik Assignee: Unassigned
Resolution: Unresolved Votes: 3
Labels: upstream-fixed


 Description   

When query contains condition on multiple columns using IN list with multiple tuples, it won't use index. If IN contains only single tuple, then optimizer seems to rewrite it into multiple ANDs (can be seen with EXPLAIN EXTENDED).

Upstream has it tracked in https://bugs.mysql.com/bug.php?id=31188 and said to be fixed in 5.7.3

Would it be possible to implement such optimization?



 Comments   
Comment by Julien Pivotto [ 2015-10-29 ]

We have found the same behavior with delete and the WHERE clause:

MariaDB [foo]> create table mdev_8026 (foo varchar(2), bar varchar(2), constraint foobar primary key (foo, bar));
Query OK, 0 rows affected (0.03 sec)
 
MariaDB [foo]> explain delete from mdev_8026 where foo='ab' and bar='cd';
+------+-------------+-----------+-------+---------------+---------+---------+------+------+-------------+
| id   | select_type | table     | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+------+-------------+-----------+-------+---------------+---------+---------+------+------+-------------+
|    1 | SIMPLE      | mdev_8026 | range | PRIMARY       | PRIMARY | 16      | NULL |    1 | Using where |
+------+-------------+-----------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)
 
MariaDB [foo]> explain delete from mdev_8026 where (foo, bar) = ('ab', 'cd');
+------+-------------+-----------+------+---------------+------+---------+------+------+-------------+
| id   | select_type | table     | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+------+-------------+-----------+------+---------------+------+---------+------+------+-------------+
|    1 | SIMPLE      | mdev_8026 | ALL  | NULL          | NULL | NULL    | NULL |    1 | Using where |
+------+-------------+-----------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

If you use tuples, the delete operation does a full table scan.

Generated at Thu Feb 08 07:24:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.