Friday, 25 November 2016

Re: [firebird-support] Overflow problem

 

Are you trying to store details of the American public debt? or the world's
public debt? Just kiding.... Not

How about assigning another integer field to each record with a value
representing the "segment" for the value you are trying to store, and then
use an index on that value, I'll explain with an example:

Say your table contains values from 0 to 1,000,000,0000,000,000

Add another field called "segment" and convert your values as follows:

where the original record value was 1:
Value = 1
Segment = 0

Where the original record was 65534
Value = 65534
Segment = 0

Where the original record was 65537
Value = 1
Segment = 1 (Segment 1 = 2 bytes segment, representing 256*256 = 65536)
So Value 1 plus segment 1 = 1+65536 = 65537

Where the original record was 131073
Value = 1
Segment = 2 (Segment 2 = 2 bytes segment, representing 256*256 * 2 = 131072)
So Value 1 plus segment 2 = 1+131072 = 131073

If you use 4 bytes for the segment then the segment 1 = 256*256*256*256 =
4228250625 = 4GB

Now the important part, when running the select say I want to get all values
between 2GB and 3GB, then :

Select value from my_table where segment between 2GB / 65536 and 3GB /
65536 (if you choose to use 2 bytes for the segment)

This will fly compared to any other solution asuming you have an index on
segment.

Are you storing prime number in your DB? is that what you are trying to
resolve? If yes, I believe using the solution I am mentioning will work
fine, perhaps you may need 2 or more segment fields to get the best
performance,

Cheers,
Fabian

__._,_.___

Posted by: <fabianch@itbizolutions.com.au>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu.  Try FAQ and other links from the left-side menu there.

Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.

__,_._,___

No comments:

Post a Comment