First off, I am assuming that it is possible for a database to generate but not insert a duplicate UUID value for a column that has a unique constraint.
Is there any intelligent way that databases typically create UUID values for unique columns or does it simply go through the loop of:
- Generate a random UUID value for the column.
- Check to see if the value is unique in the context of that column.
- Insert the value into the column if it is unique, go back to step 1 if it isn't.
until it generates a unique value. I'm aware that the possibility of the database having to do a second iteration in a situation like this is infinitesimally small, but it's still possible. I'm just wondering how database engines deal with this possibility and if my description of the loop is similar to what actually happens.