Bug #25052 Function "mod" error for bigints
Submitted: 13 Dec 2006 22:00 Modified: 29 Feb 2008 8:48
Reporter: Sergey Zhuravlev Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 OS:Linux (Linux)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[13 Dec 2006 22:00] Sergey Zhuravlev
Description:
Manual says, that it is safe to use mod with bigint numbers, but
in 4.1
15410543273277416494 % 4 => 18446744073709551614
and in 5.0
15410543273277416494 % 4 => -2

How to repeat:
select 15410543273277416494 % 4;
[22 Dec 2006 13:54] Valeriy Kravchuk
Thank you for a bug report. Verified just as described with 5.0.27 and 4.1.23-BK. Works correct in 5.0.34-BK, though:

openxs@suse:~/dbs/5.0> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.34-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select 15410543273277416494 % 4;
+--------------------------+
| 15410543273277416494 % 4 |
+--------------------------+
|                        2 |
+--------------------------+
1 row in set (0.25 sec)

mysql> select 15410543273277416494 / 4;
+--------------------------+
| 15410543273277416494 / 4 |
+--------------------------+
| 3852635818319354123.5000 |
+--------------------------+
1 row in set (0.00 sec)

mysql> select 15410543273277416492 / 4;
+--------------------------+
| 15410543273277416492 / 4 |
+--------------------------+
| 3852635818319354123.0000 |
+--------------------------+
1 row in set (0.00 sec)

mysql> exit
Bye

So, it works correctly.

openxs@suse:~/dbs/5.0> bin/mysqladmin -uroot shutdown
STOPPING server from pid file /home/openxs/dbs/5.0/var/suse.pid
061222 13:03:32  mysqld ended

[1]+  Done                    bin/mysqld_safe
openxs@suse:~/dbs/5.0> cd ../4.1
openxs@suse:~/dbs/4.1> bin/mysqld_safe &
[1] 17487
openxs@suse:~/dbs/4.1> Starting mysqld daemon with databases from /home/openxs/d
bs/4.1/var

openxs@suse:~/dbs/4.1> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.23

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select 15410543273277416494 % 4;
+--------------------------+
| 15410543273277416494 % 4 |
+--------------------------+
|     18446744073709551614 |
+--------------------------+
1 row in set (0.01 sec)

mysql> select 15410543273277416494 / 4;
+--------------------------+
| 15410543273277416494 / 4 |
+--------------------------+
|   3852635818319354368.00 |
+--------------------------+
1 row in set (0.78 sec)

In 4.1-BK we have a bug.
[29 Feb 2008 8:48] Ramil Kalimullin
"4.1 is EOL; this should not be fixed.
The problem does not exist in 5.0".