[MDEV-28001] greatest/least with bigint unsigned maxium has unexpected results compared to 0 Created: 2022-03-04  Updated: 2023-04-27

Status: Confirmed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.2.43, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: upstream-fixed


 Description   

From https://mariadb.com/kb/en/bigint-unsigned-with-least-or-greatest-unexpected-result/

MariaDB [test]> create table i (a bigint unsigned, b bigint unsigned);
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> insert into i values (18446744073709551615,0);
Query OK, 1 row affected (0.00 sec)
 
MariaDB [test]> select * from i;
Field   1:  `a`
Catalog:    `def`
Database:   `test`
Table:      `i`
Org_table:  `i`
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 20
Decimals:   0
Flags:      UNSIGNED NUM 
 
Field   2:  `b`
Catalog:    `def`
Database:   `test`
Table:      `i`
Org_table:  `i`
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 1
Decimals:   0
Flags:      UNSIGNED NUM 
 
 
+----------------------+------+
| a                    | b    |
+----------------------+------+
| 18446744073709551615 |    0 |
+----------------------+------+
1 row in set (0.02 sec)
 
MariaDB [test]>   SELECT LEAST(a,b), GREATEST(a,b), LEAST(a,cast(0 as unsigned integer)),  GREATEST(a,cast(0 as unsigned integer)) from i;
Field   1:  `LEAST(a,b)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 20
Decimals:   0
Flags:      UNSIGNED BINARY NUM 
 
Field   2:  `GREATEST(a,b)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 1
Decimals:   0
Flags:      UNSIGNED BINARY NUM 
 
Field   3:  `LEAST(a,cast(0 as unsigned integer))`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 20
Decimals:   0
Flags:      UNSIGNED BINARY NUM 
 
Field   4:  `GREATEST(a,cast(0 as unsigned integer))`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       LONGLONG
Collation:  binary (63)
Length:     20
Max_length: 1
Decimals:   0
Flags:      UNSIGNED BINARY NUM 
 
 
+----------------------+---------------+--------------------------------------+-----------------------------------------+
| LEAST(a,b)           | GREATEST(a,b) | LEAST(a,cast(0 as unsigned integer)) | GREATEST(a,cast(0 as unsigned integer)) |
+----------------------+---------------+--------------------------------------+-----------------------------------------+
| 18446744073709551615 |             0 |                 18446744073709551615 |                                       0 |
+----------------------+---------------+--------------------------------------+-----------------------------------------+
1 row in set (0.00 sec)


Generated at Thu Feb 08 09:57:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.