Description:
When comparing unsigned smallint filed with smallint filed, it result wrong
results.
1. prepare data
CREATE DATABASE test;
USE test;
CREATE TABLE `t2` (
`c0` smallint(5) unsigned zerofill DEFAULT NULL,
`c1` double DEFAULT NULL,
KEY `i0` (`c0`,`c1` DESC)
) ;
CREATE TABLE `t3` (
`c0` decimal(10,0) DEFAULT NULL,
`c1` smallint(209) DEFAULT NULL,
UNIQUE KEY `c1` (`c1`)
) ;
insert into t2(c0) values(32768);
insert into t3(c1) values (6);
insert into t3(c1) values (NULL);
2. exec select statment
mysql> select t2.c0 from t2,t3 where (not ((t2.c0) <= (t3.c1)));
Empty set (0.00 sec)
mysql> select t2.c0, t3.c1, (not ((t2.c0) <= (t3.c1))) from t2,t3;
+-------+------+----------------------------+
| c0 | c1 | (not ((t2.c0) <= (t3.c1))) |
+-------+------+----------------------------+
| 32768 | NULL | NULL |
| 32768 | 6 | 1 |
+-------+------+----------------------------+
2 rows in set (0.00 sec)
The first select statment result empty, it different with the second select statment's result.
How to repeat:
CREATE DATABASE test;
USE test;
CREATE TABLE `t2` (
`c0` smallint(5) unsigned zerofill DEFAULT NULL,
`c1` double DEFAULT NULL,
KEY `i0` (`c0`,`c1` DESC)
) ;
CREATE TABLE `t3` (
`c0` decimal(10,0) DEFAULT NULL,
`c1` smallint(209) DEFAULT NULL,
UNIQUE KEY `c1` (`c1`)
) ;
insert into t2(c0) values(32768);
insert into t3(c1) values (6);
insert into t3(c1) values (NULL);
select t2.c0 from t2,t3 where (not ((t2.c0) <= (t3.c1)));
Empty set (0.00 sec)
select t2.c0, t3.c1, (not ((t2.c0) <= (t3.c1))) from t2,t3;
+-------+------+----------------------------+
| c0 | c1 | (not ((t2.c0) <= (t3.c1))) |
+-------+------+----------------------------+
| 32768 | NULL | NULL |
| 32768 | 6 | 1 |
+-------+------+----------------------------+
2 rows in set (0.00 sec)