Re: varchar as primary key

From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "Jeff Davis" <pgsql(at)j-davis(dot)com>
Cc: "Matthew Hixson" <hixson(at)poindextrose(dot)org>, "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: varchar as primary key
Date: 2007-05-03 21:03:14
Message-ID: 758d5e7f0705031403l7fb1c9f1m6b13cc9ca5574dae@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/3/07, Jeff Davis <pgsql(at)j-davis(dot)com> wrote:
> On Thu, 2007-05-03 at 08:58 -0700, Matthew Hixson wrote:
> > I'm investigating the usage of a UUID primary key generator using
> > Hibernate and Postgres. The reason for using a UUID is that we will
> > have an application hosted at different sites in different
> > databases. We will need to aggregate the data back into a single
> > database from time to time and we want to avoid PK collisions.
> > Is there a significant performance difference between using int
> > primary keys and string primary keys in Postgres?
>
> If the only thing you need to do is avoid primary key collisions, why
> not just store an extra int that represents the "site ID" and have a
> primary key on (the_key, site_id)?
>
> That way you're *sure* no collisions happen. A UUID has a lot of bits,
> but if the random generator is flawed a collision can still happen.

Also, why not simply use sequences?
You can declare sequence to START WITH 1 and INCREMENT BY 10,
and on the other site START WITH 2 INCREMENT BY 10.
There is no chance these will collide (unless human intervenes ;)),
and you can safely add 8 more similar servers, each with similar
sequence.

Regards,
Dawid

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Carlos Moreno 2007-05-03 21:06:30 Re: Feature Request --- was: PostgreSQL Performance Tuning
Previous Message Andrew Edson 2007-05-03 20:42:44 Indexing questions: Index == key? And index vs substring - how successful?