Subject | Re: [firebird-support] Overflow problem |
---|---|
Author | |
Post date | 2016-11-25T14:11Z |
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
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