I have an auto increment id generated from sql server table. It generates values such as 1,2,3,4 and so on. So when I insert new record in it it generates a new auto increment value. For example if the previous value is 4, it returns 5. It works well. I am just thinking what will happen if one day this generated auto increment number is too large e.g 1000000000000000000000000000. what will happen in that case to my application?
Thanks. The datatype is int. Is it better to change it to long?. Although the max limit of long is good enough and very high value, what would happen to application in the hypothetical scenario that this application is used so much that even that limit crosses?
I suggest you measure your current usage and extrapolate it out to see how long it'll take to become a problem.
How many new records are created in a day on average? You can determine this from your application history
What's the maximum value for the index data type?
What index are you currently on?
From this you can calculate how many days from now you'll likely overflow you data type. If it's next week then it's probably worth doing something about it. If it's hundreds of years in the future then don't worry about it.
Tim Driven Development
posted 1 month ago
Thanks. I will check the rate. Suppose by that rate it goes of limit in 10 years time and by that long time I may not even be working in this project, will it not be a problem for whosoever is maintaining this application at that time?
If i recall correctly, once an int reaches the maximum value and is incremented, it rolls over to the lower bound negative value, and starts counting back up to zero.
Note that this is something you can test with a simple program. Just set your variable to Integer.MAX_VALUE, print it, add one, print it again.
Now, there is no way for us to tell what impact this might have on your program. you might have "take the sqrt of the number", which would cause a problem. You might have "use this as an index on an array - which could cause a problem. You might only be able to display 5 digits..There are many, many ways it could cause a problem, any or all of which might be in your code.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Monica Shiralkar wrote:...e.g 1000000000000000000000000000. what will happen in that case to my application?...
That is a large number indeed. I am not sure what that Id represents in your system. Can you share the field name if possible ?
To put things into perspective, there are 31536000000 milliseconds in a year (non leap). Even after a 100 years, the number of milliseconds passed would not even come close to your number. So, even if you're system is generating ids a 1000 times a second, you're not going to reach that value ever.
As long as comparision is the only thing done by the application, I dont think you need to worry about it. Next, is your system generating a huge number of requests as Tim asked above ? Even if you generate 1 request every second for 24 hours every day, I think it will take 65+ years for your system to reach it's max for a sql int value max (2147483647). You dont need to worry about it