7 ms·
Something I always liked but have never done -- start auto-increment IDs at some number other than 1. I worked on a system where account IDs started with 10000
by jrockway 5y ago
Something I always liked but have never done -- start auto-increment IDs at some number other than 1. I worked on a system where account IDs started with 1000000, invoice IDs started with 2000000, etc. That way, if you saw a random number laying around like "1001234", you knew it was an account ID. "2000123", an invoice! I don't remember how often it helped things, but it was more than 0 times, and it always "felt" good. I never loved the implicit upper bound, but it was also never a problem.
(And remember, the values are in different tables, so the only disadvantage is that your millionth user has ID 2000000. To the trained eye they look like an invoice; but there is no way for the system itself to treat that as an invoice, so it's only confusing to humans. If you use auto-increment keys that start at 1, you have the same problem. Account 1 and Invoice 1 are obviously different things.)
- Twisol 5y ago> but there is no way for the system itself to treat that as an invoice, so it's only confusing to humans. I agree in principle, but then you have Windows skipping version 9 because of all of the `version.hasPrefix("9")` out in the world that were trying to cleverly handle both 95 and 98 at once. If a feature of data is exploitable, there's a strong chance it will be exploited.
- 9dev 5y agoI use this for internal items, as in: real customer IDs start at 10,000, so we have 9,999 possible users/invoices/whatever for our own usage in the database. That makes it easy to filter demo accounts of your sales employees, or production test accounts, in queries: just add an offset. Re: the upper bound: if you reach a million customers, you have lots of other nice problems, like how to spend all the money they earn you :-)
- gavinray 5y agoThis is clever. You could use "is_test_account" or whatnot, but that adds an unnecessary column (for ~99% of records) I like this -- will keep it in mind!
- avar 5y agoI worked on an existing database once that stored geographic locations and used the signed bit for namespacing. Positive IDs were home-grown, negative ones were Unique Feature Identifiers from some old GNS system import (from some ancient US Government/Military dataset). Then when something had to be edited/replaced/created it would possibly change a previously negative ID to positive, fun times.
- bombcar 5y agoI’ve seen systems that had to track only two types of things - one started at half the value and went up; the other started just below that and went down. Think 500000+ vs 499999-