Bug #55365 MySQL does not evaluate TRUNCATE/ROUND + XOR consistently
Submitted: 19 Jul 2010 14:17 Modified: 19 Jul 2010 14:46
Reporter: Philip Stoev Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.48, 5.5.6-m3-debug OS:Any
Assigned to: CPU Architecture:Any
Triage: Triaged: D2 (Serious)

[19 Jul 2010 14:17] Philip Stoev
Description:
Expressions containing XOR and TRUNCATE/ROUND are not evaluated consistently.

How to repeat:
CREATE TABLE `X` (
  `f1` double DEFAULT NULL,
  `f2` double DEFAULT NULL,
  `f3` double NOT NULL DEFAULT '0',
  `f4` double NOT NULL
);

INSERT INTO `X` VALUES (NULL,NULL,0,0),(NULL,NULL,0,0),(7,0,0,0),(NULL,NULL,0,0),(NULL,NULL,0,0),(NULL,NULL,0,0),(NULL,0,0,0);

# This query returns all NULLs
select ( ( f1 % ( ( ( TRUNCATE( f3 , f1 ) ) ) XOR ( f1 ) ) )) from X;

# This query returns one zero
select ( ( f1 % ( ( ( TRUNCATE( f3 , f1 ) ) ) XOR ( f1 ) ) )) from X WHERE f1;
[19 Jul 2010 14:20] Philip Stoev
TRUNCATE + OR is also affected
[19 Jul 2010 14:46] Valeriy Kravchuk
Thank you for the bug report. Verified with 5.1.48 also:

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot -proot -P3310 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.48-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE TABLE `X` (
    ->   `f1` double DEFAULT NULL,
    ->   `f2` double DEFAULT NULL,
    ->   `f3` double NOT NULL DEFAULT '0',
    ->   `f4` double NOT NULL
    -> );
Query OK, 0 rows affected (0.30 sec)

mysql>
mysql> INSERT INTO `X` VALUES
    -> (NULL,NULL,0,0),(NULL,NULL,0,0),(7,0,0,0),(NULL,NULL,0,0),(NULL,NULL,0,0)
,(NULL,NULL,0,0),(NULL,0,0,0);
Query OK, 7 rows affected (0.08 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql> select ( ( f1 % ( ( ( TRUNCATE( f3 , f1 ) ) ) XOR ( f1 ) ) )) from X;
+--------------------------------------------------------+
| ( ( f1 % ( ( ( TRUNCATE( f3 , f1 ) ) ) XOR ( f1 ) ) )) |
+--------------------------------------------------------+
|                                                   NULL |
|                                                   NULL |
|                                                   NULL |
|                                                   NULL |
|                                                   NULL |
|                                                   NULL |
|                                                   NULL |
+--------------------------------------------------------+
7 rows in set (0.13 sec)

mysql> select ( ( f1 % ( ( ( TRUNCATE( f3 , f1 ) ) ) XOR ( f1 ) ) )) from X WHER
E f1;
+--------------------------------------------------------+
| ( ( f1 % ( ( ( TRUNCATE( f3 , f1 ) ) ) XOR ( f1 ) ) )) |
+--------------------------------------------------------+
|                                                      0 |
+--------------------------------------------------------+
1 row in set (0.03 sec)
[19 Jul 2013 8:19] Hartmut Holzgraefe
Still reproducible with 5.6.12