3 ms·
Oh wow, yup that will do it. That was my second suggestion for what is "correct" but I never heard of your #2 suggestion, so I thought there would still be perf
by crazygringo 3y ago
Oh wow, yup that will do it. That was my second suggestion for what is "correct" but I never heard of your #2 suggestion, so I thought there would still be performance issues because you'd have to shift all the values above. I'm kind of annoyed now I didn't know about this before... :)
Yes, this should definitely considered to be the correct, definitive, performant solution then. Thank you!
I think you'll need a full table lock in the case of a race condition trying to do a remove and add at the same time, but that's probably not usually going to be an issue?
- munificent 3y agoActually, now that I think about it, step 1 isn't necessary. You don't actually need to shuffle the indexes since you always choose a random one anyway. It should be enough to just do the swap on deletes in order to keep the integers contiguous. > I think you'll need a full table lock in case you're ever trying to do a remove and add at the same time Yeah, I think you need some sort of locking to ensure N can't be concurrently modified but I'm not a DB person, so I don't know how to go about that.
- crazygringo 3y agoYup, agreed on step 1. Basic autoincrement is perfectly fine, since you pick a random number at query time.
- Levitating 3y agoWhat an incredibly simple solution for something that was just deemed rocket science. Also I liked your book.
- jprete 3y agoThanks to both of you for pointing out some quite good solutions to this problem.