[MDEV-10552] equality operation on cast of the value "-0.0" to decimal not working Created: 2016-08-12  Updated: 2016-12-05  Resolved: 2016-12-05

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 5.5.54, 10.0.29, 10.1.20

Type: Bug Priority: Major
Reporter: Scott Feldstein Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: upstream-fixed


 Description   

This is slightly obscure but i recently encountered it, so

> create table test (a varchar(255));
Query OK, 0 rows affected (0.02 sec)
 
> insert into test values ('-0.0');
Query OK, 1 row affected (0.00 sec)
 
> select * from test where cast(a as decimal(5,1)) < 0;
+------+
| a    |
+------+
| -0.0 |
+------+
1 row in set (0.00 sec)
> select * from test where cast(a as decimal(5,1)) > 0;
Empty set (0.00 sec)
> select @@version;
+-----------------+
| @@version       |
+-----------------+
| 10.1.14-MariaDB |
+-----------------+
1 row in set (0.00 sec)



 Comments   
Comment by Elena Stepanova [ 2016-08-26 ]

Thanks for the report. Reproducible with 5.5-10.1 and MySQL-5.6, but fixed in 5.7 and MariaDB 10.2:

MariaDB [test]> create table test (a varchar(255));
Query OK, 0 rows affected (0.83 sec)
 
MariaDB [test]> insert into test values ('-0.0');
Query OK, 1 row affected (0.09 sec)

MariaDB [test]> select * from test where cast(a as decimal(5,1)) < 0;
Empty set (0.01 sec)
 
MariaDB [test]> select * from test where cast(a as decimal(5,1)) > 0;
Empty set (0.00 sec)
 
MariaDB [test]> select * from test where cast(a as decimal(5,1)) = 0;
+------+
| a    |
+------+
| -0.0 |
+------+
 
MariaDB [test]> select @@version;
+----------------------+
| @@version            |
+----------------------+
| 10.2.2-MariaDB-debug |
+----------------------+

The behavior changed with this revision:

commit c87e002bbb946907b4c9504612b3b3c2a0a19e51
Author: Sergei Golubchik <serg@mariadb.org>
Date:   Sun Jun 26 13:37:27 2016 +0200
 
    str2decimal: don't return a negative zero

Assigning to serg to confirm it's the expected result.

Comment by Sergei Golubchik [ 2016-08-26 ]

let's backport c87e002bbb946907b4c9504612b3b3c2a0a19e51 to 5.5

Generated at Thu Feb 08 07:43:06 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.