Re: Primary keys and composite unique keys(basic question) - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Primary keys and composite unique keys(basic question)
Date
Msg-id CAHyXU0xSOZgcnifzC5c+RkGAbsDpf_bbGiZYYFny6ke69DBoxA@mail.gmail.com
Whole thread Raw
In response to Primary keys and composite unique keys(basic question)  (Mohan Radhakrishnan <radhakrishnan.mohan@gmail.com>)
Responses Re: Primary keys and composite unique keys(basic question)  (Rob Sargent <robjsargent@gmail.com>)
Re: Primary keys and composite unique keys(basic question)  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-general
On Wed, Mar 31, 2021 at 3:36 AM Mohan Radhakrishnan
<radhakrishnan.mohan@gmail.com> wrote:
>
> Hello,
>              We have UUIDs in our tables which are primary keys. But in some cases
> we also identify a composite unique key apart from the primary key.
>
> My assumption is that there should be a unique key index created by us using the composite key. And when we fetch
usingthis composite key instead of the primary key we have a performance boost due to the index.
 
>
> Is this right ? Are there more details I should read to understand this better ? Please point. If I should use the
queryplanner to look at the statistics I will.
 

This is one of the great debates in computer science and it is not
settled.  There are various tradeoffs around using a composite key
derived from the data (aka natural key) vs generated identifiers. It's
a complex topic with many facets: performance, organization,
validation, and correctness are all relevant considerations.  I would
never use UUIDS for keys though.

merlin



pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Upgrading from 11 to 13
Next
From: Rob Sargent
Date:
Subject: Re: Primary keys and composite unique keys(basic question)