Bug #81876 neg op returns diff results
Submitted: 16 Jun 2016 7:30 Modified: 20 Jun 2016 11:06
Reporter: 帅 Bang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.5.50, 5.6.31, 5.7.13 OS:Linux
Assigned to: CPU Architecture:Any

[16 Jun 2016 7:30] 帅 Bang
Description:
mysql> create table sb(a bigint unsigned);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into sb values(~1);
Query OK, 1 row affected (0.00 sec)

mysql> select -a from sb;
ERROR 1690 (22003): BIGINT value is out of range in '-(`test`.`sb`.`a`)'

mysql> drop table sb;
Query OK, 1 row affected (0.00 sec)

mysql> create table sb(a int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into sb values(1);
Query OK, 1 row affected (0.00 sec)

mysql> select -(~a) from sb;
ERROR 1690 (22003): BIGINT value is out of range in '-(~(`test`.`sb`.`a`))'

but, when we type this 

mysql> select -~1;

we get :

+-----------------------+
| -~1                   |
+-----------------------+
| -18446744073709551614 |
+-----------------------+
1 row in set (0.00 sec)

How to repeat:
drop table if exists sb;
create table sb(a bigint unsigned);
insert into sb values(~1);
select -a from sb;

drop table if exists sb;
create table sb(a int);
insert into sb values(1);
select -(~a) from sb;

select -(~1);

Suggested fix:
select -(~1) failed with ERROR 1690 

or

select -(~a) from sb; successed
[20 Jun 2016 11:06] MySQL Verification Team
Hello Bang,

Thank you for the report and test case.
Observed this with 5.5.50, 5.6.31 and 5.7.13 builds.

Thanks,
Umesh