Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I noticed mysql starts to SUM incorrectly at row 62184. Summing my ID column up to 62183 reports both the same SUM'd number in Excel and MySQL. Yet as soon as go up one more row I get this, its off by 3.
Excel =SUM(A1:A62184): 5231630907980670
MySQL:
mysql> select format(sum(ID), '000000000000000') as auto_id_total from Table where row_num <= 62184;
+-----------------------+
| auto_id_total |
+-----------------------+
| 5,231,630,907,980,673 |
+-----------------------+
1 row in set (0.00 sec)
I think you have discovered the limitations of precision, significant figures, round off, truncation, and binary storage. Excel is limited to 15 significant digits and those numbers displayed greater then 15 are truncated. It isn't mysql that is wrong.
What is you ID column type?
As you definitely has a very huge SUM (because your IDs are very very big), I'm not sure it's a good idea to get rid of the scientific notation (i.e. exponential value)
What is you ID column type?
As you definitely has a very huge SUM (because your IDs are very very big), I'm not sure it's a good idea to get rid of the scientific notation (i.e. exponential value)
mysql> SELECT SUM(CAST(ID AS UNSIGNED)) from Table;
+---------------------------+
| SUM(CAST(ID AS UNSIGNED)) |
+---------------------------+
| 61050470996456889 |
+---------------------------+
1 row in set (8.99 sec)
Its even different again. Before I got 61050470996395050. Which is different then excel as was my concern above.
mysql> SELECT ID from Table LIMIT 62183,3;
+--------------+
| ID |
+--------------+
| 170318068013 |
| 170318068014 |
| 170318068021 |
+--------------+
3 rows in set (2.58 sec)
The numbers are exact and correct when compared to the excel columns. I guess I have found a limit of some sort.
In addition to the excel precision problem, you may indeed be hitting the limit of 64-bit integers which is the UNSIGNED type in MySQL. That is something over 18 followed by 18 zeros, a twenty digit number at most.
In the above selection you show 3 twelve digit numbers beginning with 17, so adding six of those values in that range will carry to the next power of 10 - a thirteen digit number... do that ten times (~60 IDs in that range) and you have a fourteen digit number, ten times that (~600 in that range) and you have a 15 digit number, 6000 to get to 16 digits, 60000 to 17 digits... and that is a tiny slice of that very specific number range!
Taken together with the fact that your SUM query took 8.99 seconds, even assuming reasonably recent hardware, indicates likely very many times that number of values... you may very likely be in danger of exceeding the 64 bit integer limit. I do not know if MySQL rolls over zero, returns an error or simply preduces meaningless results in that case.
Plus, you are not actually storing the data as integer types, so they must be cast to integers which might impose yet another limiting factor.
Again, I am curious to know what is the meaning of those IDs that would make their sum useful?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.