Earlier quoted context omitted.
Possibly, you don't actually know since it is external data.
We do know because the database owner has openly talked about how the keys are derived. That still doesn't make it a good key for your database, but I can assure you that the world doesn't revolve around you. It is someone's surrogate key – therefore it is a surrogate key.
You'll regret using natural keys
551–560 of 568 posts
Re: You'll regret using natural keys
#552Earlier quoted context omitted.
Fast-forward a couple years: now I have scripts that launch sub-tasks more than once a second.
So use timestamps with sub-second precision, which virtually every SQL database supports (even ones like SQLite that don't have built-in date/time types).
The timestamp generated in a transaction is generally the time the transaction started, which means it is always the same within the same transaction.
Re: You'll regret using natural keys
#553Earlier quoted context omitted.
Bah ? Got a new car, used it for 150k km Tweak the odometer and set it to 50k, sell the car How could the government know I cheated ? Especially for an old car which are not connected (so even the manufacturer cannot tell) (btw, this is used in thief networks to refurg stolen cars)
> How could the government know I cheated You would have to perjure yourself on your yearly registration, when you get emissions testing you would need the tech to perjure themselves, and if you go to any mechanic that reports the mileage to the state (which some do, depending on the state) you would need them to perjure themselves too. > Tweak the odometer and set it to 50k, sell the car If the most recent registrat…
We only declare odometer's when we sell the car. There is a technical checkup every two years which may be send that intel to the gov. Does not matter anyway : what matters is that a counter that should only be increased can be decreased, because car manufacturer do not care about any kind of IT security
Re: You'll regret using natural keys
#554Earlier quoted context omitted.
As always, depends on the implementation. Hash maps should generally always have faster lookups than Btree based structures. However, they'll have slower writes especially when contested. A key issue hash tables have to deal with is what happens when a remapping needs to happen. For example, when 2 keys have the same hash. In that case, locking becomes a lot more messy. For a btree this is simpler. It's built to be a…
Hm yeah, now I'm wondering how MySQL implements it. Consistent hashing is one way to limit the scope of a remap.
Re: You'll regret using natural keys
#555Earlier quoted context omitted.
So use timestamps with sub-second precision, which virtually every SQL database supports (even ones like SQLite that don't have built-in date/time types).
I don't think you know enough about how databases work to even try to be giving advice. The timestamp generated in a transaction is generally the time the transaction started, which means it is always the same within the same transaction.
Re: You'll regret using natural keys
#556Earlier quoted context omitted.
Because - and _ break text selection in existing systems you do not have control over, if you use those characters your ids will become harder to select.
Someone already made this point, and once again, "break" is completely undefined. It is not at all impossible or even difficult to select text with - or _, so what's "broken" exactly? At worst it takes one extra step to extend the default selection. These are such weird objections.
Re: You'll regret using natural keys
#557Earlier quoted context omitted.
Yeah, fsck your co-workers and your replacement when you quit.
If you’re good to your future self you’re also good to them.
Re: You'll regret using natural keys
#558Re: You'll regret using natural keys
#559I've become a fan of unique, relatively short and "human-readable" IDs, such at the ones used by Stripe, e.g. `cus_MJA953cFzEuO1z` for an ID of a customer. Here's a Stripe dev article on the topic: https://dev.to/stripe/designing-apis-for-humans-object-ids-3... If you use JavaScript/TypeScript, you can make them like this: function makeSlug(length: number): string { const validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde…
Re: You'll regret using natural keys
#560Earlier quoted context omitted.
Usually one is not in control over every place where text can be selected. As a developer I will be exposed to ids being displayed in code, terminals, browsers of various sorts, database editors, json dumps, text editors, api responses, chat messages, you name it.
Sure, I agree. I'm not sure what point you're trying to make though.
The _ and - symbols make this difficult in the edge cases of all of the above. Do you call it dash, or underscore? Line? Hyphen? Binder-strich?
&etc.
I would have gone with adding the @ and ~ symbols, those are at least parsable in human form as well .. ".. email symbol and squiggly thing .. "