LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-20-2018, 03:18 AM   #16
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290

Let's sum up the situation:
  1. MySQL sum(ID): 6.105047099639505e16
  2. MySQL format(sum(ID), '000000000000000'): 61,050,470,996,395,050
  3. MySQL SUM(CAST(ID AS UNSIGNED)): 61050470996456889
  4. Excel: 61050470996395000
I don't think you've been hitting MySQL precision limit (maximum BIGINT UNSIGNED value is 18446744073709551615).
1 and 2 are equal.
3 is unique. For me, it's the only mystery currently... Are all your IDs>=0, unsigned and without any decimals?
4 is unique. It has already been explained why (Excel limits its precision to 15 digits only).
 
1 members found this post helpful.
Old 12-20-2018, 01:13 PM   #17
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
Ok, I guess its a limit of hardware. I'm just trying to sum ID to confirm an import matches the source. Thanks for your help.
 
Old 12-20-2018, 03:34 PM   #18
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by l0f4r0 View Post
Let's sum up the situation:
  1. MySQL sum(ID): 6.105047099639505e16
  2. MySQL format(sum(ID), '000000000000000'): 61,050,470,996,395,050
  3. MySQL SUM(CAST(ID AS UNSIGNED)): 61050470996456889
  4. Excel: 61050470996395000
I don't think you've been hitting MySQL precision limit (maximum BIGINT UNSIGNED value is 18446744073709551615).
1 and 2 are equal.
3 is unique. For me, it's the only mystery currently... Are all your IDs>=0, unsigned and without any decimals?
4 is unique. It has already been explained why (Excel limits its precision to 15 digits only).
yes, all ID's are > 0, exist, unsigned, and no decimals.
 
Old 12-20-2018, 05:59 PM   #19
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Quote:
Ok, I guess its a limit of hardware. I'm just trying to sum ID to confirm an import matches the source. Thanks for your help.
In that case, given you really do care about this, I'd also write a short prog (Perl for pref) to SELECT all the IDs and sum them.
Be interesting to see what answer you get ...
 
Old 12-20-2018, 06:20 PM   #20
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
Code:
   while ($sqlDataRow = $sqlDataGetResult -> fetch())
   {
       $iTest= $iTest + $sqlDataRow[ID];
   }
   echo $iTest;
A PHP loop gives iTest = 61050470996456889.
 
Old 12-20-2018, 06:35 PM   #21
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by kenw232 View Post
Ok, I guess its a limit of hardware. I'm just trying to sum ID to confirm an import matches the source. Thanks for your help.
OK, thanks.

If the source is an excel sheet then you will need to figure out some intermediate way to get a reference result without the excel precision limit.

You could generate a checksum with bit mask operations in MySQL, but I have no exposure to excel so do not know if it could generate a reference checksum.

Your question has prompted me to think about the basic math, and one question that came to mind was if we sum the series 1 + 2 + 3... +N, what would be the largest N for which the sum would be less than the unsigned 64 bit integer limit. This works out to be 6074000999. That is,

Code:
The sum of all positive integers 1+2+3...6074000999 == 18446744070963499500
18446744070963499500 < 18446744073709551615 (Diff == 2746052115)
That may not help with your ultimate solution, but it helps to visualize the relative scale of the numbers you are working with and the various limits involved.


The scale of the limit N from above: 6074000999
The scale of IDs from your example: 170318068021

Think of it as an indicator of how fast your sum is moving toward the limit.

We know nothing about the distribution of your data, the sequence obviously has gaps, but the scale of the values you are adding exceed the limit N by two digits or a scale of 100. I don't know if that is helpful to you, but I thought I'd post it here while I had the thought in view.

Good luck!

Last edited by astrogeek; 12-20-2018 at 06:42 PM. Reason: formatting
 
1 members found this post helpful.
Old 12-20-2018, 08:08 PM   #22
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
Thanks for your help. I'm not too worried because when I do a text file compare of the giant list of ID's from excel and mysql they match. no text differences. So it the numbers are the same the result has to be the same. I was just curious why the calc was always off. Its good enough.
 
Old 12-21-2018, 03:31 AM   #23
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by l0f4r0 View Post
Let's sum up the situation:
  1. MySQL sum(ID): 6.105047099639505e16
  2. MySQL format(sum(ID), '000000000000000'): 61,050,470,996,395,050
  3. MySQL SUM(CAST(ID AS UNSIGNED)): 61050470996456889
  4. Excel: 61050470996395000
I don't think you've been hitting MySQL precision limit (maximum BIGINT UNSIGNED value is 18446744073709551615).
1 and 2 are equal.
3 is unique. For me, it's the only mystery currently... Are all your IDs>=0, unsigned and without any decimals?
4 is unique. It has already been explained why (Excel limits its precision to 15 digits only).
Commands #1/#2 give a different result than #3 and, frankly, I would rather rely on #3.
It seems that there is an implicit conversion VARCHAR->INT by MySQL during #1/#2 but I don't really know how it is done exactly so you'd better force the conversion yourself...
More, your PHP script confirms #3

Quote:
Originally Posted by kenw232 View Post
Thanks for your help. I'm not too worried because when I do a text file compare of the giant list of ID's from excel and mysql they match. no text differences. So it the numbers are the same the result has to be the same. I was just curious why the calc was always off. Its good enough.
Did you get an error after importing your data into MySQL? If number of affected rows matched your number of Excel rows, it should mean that everything went fine (except if some data were already present in Table).

Finally, please note that same ID sum result between Excel and MySQL doesn't necessarily mean that your IDs are all the same (there can be some further balance).
However I think this bias cannot happen if number of rows is the same. Did you compare COUNT(ID) FROM Table; with your number of Excel rows?

Last edited by l0f4r0; 12-21-2018 at 03:33 AM.
 
Old 12-21-2018, 11:15 AM   #24
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
Yes, COUNT(ID) matched. both excel and the table have the same number of rows. I'm sure its correct now.
 
Old 12-21-2018, 12:38 PM   #25
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
just a trick: it is enough to sum up the last 4 or 5 digits, no need to handle bigints or similar.
Also you may try to sum up only 1000 (or 10000) lines in one.
 
1 members found this post helpful.
Old 01-07-2019, 08:14 PM   #26
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by pan64 View Post
just a trick: it is enough to sum up the last 4 or 5 digits, no need to handle bigints or similar.
Indeed, last digits of the sum result don't depend on the previous ones. Well done

Quote:
Originally Posted by pan64 View Post
Also you may try to sum up only 1000 (or 10000) lines in one.
What do you mean and what is the purpose?

Quote:
Originally Posted by kenw232 View Post
Yes, COUNT(ID) matched. both excel and the table have the same number of rows. I'm sure its correct now.
Can you mark this thread as [SOLVED] if you think it is please (see HOWTO in my sig)?
 
Old 01-08-2019, 01:10 AM   #27
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
Quote:
Originally Posted by l0f4r0 View Post
What do you mean and what is the purpose?
You can split the table and that may help you to avoid the mentioned problem.
Probably sum of 10000 lines is still "small" enough and that way you will have 6 [partial] results to compare.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortran 90 "Assertion exponent < 10000 failed" suicidaleggroll Programming 13 07-05-2013 03:12 AM
simple exponent distributive law question nadroj General 11 07-26-2007 08:29 AM
fprint Exponent printing question mjamal Programming 3 10-22-2006 02:27 PM
Problems with Apache2 and exponent CMS install dthacker Linux - Software 0 01-29-2005 05:48 PM
exponent suchi_s Programming 1 10-30-2004 07:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration