[MDEV-8694] Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a' Created: 2015-08-28  Updated: 2015-09-02  Resolved: 2015-08-28

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

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

Issue Links:
Blocks
blocks MDEV-8728 Fix a number of problems in equal fie... Closed

 Description   

This script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
INSERT INTO t1 VALUES ('a'),('a ');
SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ';

returns one row:

+------+-----------+
| a    | LENGTH(a) |
+------+-----------+
| a    |         1 |
+------+-----------+

Now if I make the condition even stronger:

SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a';

it erroneously returns 2 rows:

+------+-----------+
| a    | LENGTH(a) |
+------+-----------+
| a    |         1 |
| a    |         2 |
+------+-----------+

The problem happens in equal fields propagation.

WHERE a NOT LIKE 'a ' AND a='a'

gets rewritten to

WHERE 'a' NOT LIKE 'a ' AND a='a'

then LIKE gets removed from the condition.


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