[MDEV-32889] Unexpected Results when Comparing Boolean with Floating-point Created: 2023-11-27  Updated: 2023-12-18  Resolved: 2023-12-18

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 11.2.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Suyang Zhong Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Latest docker image on Ubuntu 22.04



 Description   

Considering the test case below:

The third `SELECT` returns an empty result, which is surprising: If the result of second query is -0.4 (`TRUE`), the value of the `true - c1/10` in `WHERE` condition should also be true, and thus the third query should return the row in `t0`.

CREATE TABLE t0(c1 INT);
INSERT INTO t0(c1) VALUES (14);
 
SELECT * FROM t0; -- 14
SELECT true-c1/10 FROM t0; -- -0.4000
SELECT * FROM t0 WHERE true-c1/10; 
-- Expected: 14
-- Actual: empty

I originally find this in the latest docker image.



 Comments   
Comment by Sergei Golubchik [ 2023-12-18 ]

you evaluate a decimal in the integer context, it gets rounded, -0.4 becomes 0, that is FALSE.

Generated at Thu Feb 08 10:34:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.