[MDEV-8369] Unexpected impossible WHERE for a condition on a ZEROFILL field Created: 2015-06-24 Updated: 2015-09-14 Resolved: 2015-09-11 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1 |
| Fix Version/s: | 10.1.8 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
This script:
correctly returns one row for both SELECT queries. if I join the two conditions using AND:
it unexpectedly returns Empty set. EXPLAIN for the above query tells "Impossible WHERE":
|
| Comments |
| Comment by Jiri Kavalik [ 2015-06-24 ] | |||||||||||||
|
and without zerofil
| |||||||||||||
| Comment by Alexander Barkov [ 2015-08-20 ] | |||||||||||||
|
The problem happens because optimize_cond() when propagating equalities replaces the condition to: WHERE a=128 AND hex('0000000128')='80' which later evaluates to FALSE because HEX() returns hex representations of the string rather than hex representation of the original number 128. convert_zerofill_number_to_string() is the function which actually replaces Item_field to Item_string is . | |||||||||||||
| Comment by Alexander Barkov [ 2015-08-21 ] | |||||||||||||
|
This script demonstrates a similar problem:
The first and the second SELECT return one row. The third SELECT returns empty set.
returns
| |||||||||||||
| Comment by Alexander Barkov [ 2015-08-21 ] | |||||||||||||
|
A similar example with WEIGHT_STRING:
| |||||||||||||
| Comment by Alexander Barkov [ 2015-08-21 ] | |||||||||||||
|
A similar example using FORMAT():
|