[MDEV-14458] CASE statement precision Created: 2017-11-21 Updated: 2017-12-05 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 10.0, 10.1, 10.2 |
| Fix Version/s: | 10.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Kieran Brahney | Assignee: | Vicențiu Ciorbaru |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Description: How to repeat:
Actual Results: Expected Results: Additional Information:
Seems to also work if you add > 0:
|
| Comments |
| Comment by Elena Stepanova [ 2017-12-02 ] | ||||||||||||||||||||||||||||
|
I agree that the result is counter-intuitive at the first glance. However, given the existing logic with types and conversion, I don't understand why MySQL returns a result set here, it seems highly inconsistent. The first SELECT returns a very small decimal (or rather double) value:
CASE has no magic, it keeps the value:
So, effectively our query in question is
and it returns a result set. The table t1, its structure and fulltext indexes are not important here – where clause evaluates to FALSE for everything under 0.5:
It works the same way in MySQL and MariaDB. While I haven't found an explicit statement in documentation yet, I assume it's because the value is cast to an integer. Thus, it seems only logical that the second query in the description returns an empty result. Still, I'll assign the report to the data type expert bar to confirm whether everything works as expected. | ||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2017-12-05 ] | ||||||||||||||||||||||||||||
|
The problem is that the code responsible for condition calculation is very inconsistent in calling val_int() versus val_bool(). This scripts demonstrates inconsistency:
Should be checked by the optimizer team. |