[MDEV-8661] Wrong result for SELECT..WHERE a='a' AND a='a' COLLATE latin1_bin Created: 2015-08-21 Updated: 2015-09-12 Resolved: 2015-08-26 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1 |
| Fix Version/s: | 10.1.5 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | propagation, upstream | ||
| Issue Links: |
|
||||||||
| Description |
|
This bug is similar to http://bugs.mysql.com/bug.php?id=5134 This script:
correctly returns one row:
Now if I add an extra part into the condition:
it returns two rows:
The expected result is to return one row in both cases. The problem happens because "AND a='a' COLLATE latin1_bin" gets erroneously replaced to "AND 'a'='a' COLLATE latin1_bin" which is further evaluates to TRUE and gets removed from the WHERE condition. So, the query gets rewritten to:
The method which actually replaces the field to the constant is Item_field::equal_fields_propagator() in item.cc. This condition is not strict enough:
It should also take into account the collations of the two operations that the field "a" appears in. |
| Comments |
| Comment by Alexander Barkov [ 2015-08-25 ] | |||||||||||||||||||||
|
Another example:
The above script returns one row in the first SELECT and two rows in the second SELECT:
Now if I join the above two condition using AND:
I get empty set. This is wrong. The expected result is to return one row, the same result as in the first SELECT. | |||||||||||||||||||||
| Comment by Alexander Barkov [ 2015-09-12 ] | |||||||||||||||||||||
|
The problem is repeatable in MySQL-5.7.8 |