[MDEV-6818] Possibly wrong result with a query comparing a date field to a char constant. Created: 2014-10-01 Updated: 2022-12-11 Resolved: 2022-12-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1.1 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Cannot Reproduce | Votes: | 1 |
| Labels: | datatype, optimizer | ||
| Description |
|
After the commit on 10.1 tree, the provided test case started producing a different result.
I'm not quite sure which result is correct, but I want to make sure that the change was intentional.
|
| Comments |
| Comment by Sergei Petrunia [ 2014-10-01 ] | ||||||||||||||
|
So, the missing row is:
d ids defined as DATE, and then invalid date is compared with string literal 'c'. | ||||||||||||||
| Comment by Sergei Petrunia [ 2014-10-01 ] | ||||||||||||||
|
Let's check how they compare without indexes:
So, '0000-00-00' = 'c'. | ||||||||||||||
| Comment by Sergei Petrunia [ 2014-10-01 ] | ||||||||||||||
|
However, range optimizer has a different idea. Even in the old code (before the 8bd4716272ef16a4bcd3196ba62f249aa3878998 commit), it thinkd that d='c' can never be true:
and this does cause result mismatch:
| ||||||||||||||
| Comment by Sergei Petrunia [ 2014-10-01 ] | ||||||||||||||
|
The query
used to return the row with 0000-00-00, because "OR b>=a" prevented use of range optimizer. But then, we've got " The solution is to reconcile range optimizer logic with item evaluation logic. | ||||||||||||||
| Comment by Sergei Petrunia [ 2014-10-01 ] | ||||||||||||||
|
Test result from mysql-5.6.20 and mysql-5.6.21:
It's the same as the new one that we've got. It seems, they have fixed the comparison to not return true:
Debugging the range optimizer, I can see that it produces SEL_TREE(NULL), unlike MariaDB which produces IMPOSSIBLE. This is actually weird - if item comparison was changed to evaluate to FALSE, why change range optimizer to not return IMPOSSIBLE? | ||||||||||||||
| Comment by Alice Sherepa [ 2022-12-09 ] | ||||||||||||||
|
current 10.3-10.10 return the correct result:
|