Re: UUID column as pimrary key?

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: dennis jenkins <dennis(dot)jenkins(dot)75(at)gmail(dot)com>
Cc: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: UUID column as pimrary key?
Date: 2011-01-05 23:47:44
Message-ID: AANLkTinANzm61UOURi27D+k56T=Mn33OvKuA7Tm6WBD8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6 January 2011 00:32, dennis jenkins <dennis(dot)jenkins(dot)75(at)gmail(dot)com> wrote:

> On Wed, Jan 5, 2011 at 1:03 PM, Bill Moran <wmoran(at)potentialtech(dot)com>
> wrote:
> >
> > But the point (that you are trying to sidestep) is that the UUID
> namespace
> > is finite, so therefore you WILL hit a problem with conflicts at some
> point.
> > Just because that point is larger than most people have to concern
> themselves
> > with isn't an invalidation.
>
> The UUID itself is 128 bits. Some of those bits are pre-determined.
> I don't recall, but I think that a "normal" UUID has 121 bits of
> randomness.
>
> How many would one have to store in a database before a collision
> would even be a concern. Such a database would be freaking huge.
> Probably far larger than anything that anyone has.
>

Not necessarily.

Bad luck: two inserts, and one collision.
Good luck: many many inserts, without any collision.

If you have ten pairs of socks... how many do you need to choose, to have
two from the same pair (to have a collision)?
Good luck: 2
Bad luck: 11

With uuid you can write a program that most of the time works correctly, but
sometimes not.
If you need a program that works correctly all the time, you can use UUID,
with the overhead of a procedure, that checks the collisions, and does
something with that, or you could generate the PK without UUID, and be sure
that the generator won't have collisions, just because it is a normal
sequence.

regards
Szymon

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Вячеслав Блинников 2011-01-06 00:14:17 Re: Asynchronous queries with bound data.
Previous Message Radosław Smogura 2011-01-05 23:44:40 Re: UUID column as pimrary key?