[MDEV-8189] field<>const and const<>field are not symmetric Created: 2015-05-20  Updated: 2015-06-30  Resolved: 2015-06-30

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 10.1.6

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Sprint: 10.1.6-1

 Description   

This script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10),(20),(30),(40),(50);
EXPLAIN SELECT * FROM t1 WHERE a<>10;
EXPLAIN SELECT * FROM t1 WHERE 10<>a;

returns:

+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                    |
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
|    1 | SIMPLE      | t1    | index | a             | a    | 5       | NULL |    5 | Using where; Using index |
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
...
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                    |
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
|    1 | SIMPLE      | t1    | index | NULL          | a    | 5       | NULL |    5 | Using where; Using index |
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+

Notice, "possible_keys" is different in the two EXPLAINs.

"Not equal" operations is symmetric, so the expected results should the the same for the two EXPLAINs.

Another SQL script demonstrating the same problem:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT, b INT, KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 (a) VALUES (10),(10),(10),(10),(10),(10),(10),(10),(10),(10),(70);
EXPLAIN SELECT * FROM t1 WHERE a<>10;
EXPLAIN SELECT * FROM t1 WHERE 10<>a;

The first explain returns:

+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                 |
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
|    1 | SIMPLE      | t1    | range | a             | a    | 5       | NULL |    3 | Using index condition |
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+

The second returns:

+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |   11 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
{code}
 


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