Re: Primary keys and composite unique keys(basic question)

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Mohan Radhakrishnan <radhakrishnan(dot)mohan(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Primary keys and composite unique keys(basic question)
Date: 2021-04-02 02:28:59
Message-ID: CAHyXU0xSOZgcnifzC5c+RkGAbsDpf_bbGiZYYFny6ke69DBoxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 31, 2021 at 3:36 AM Mohan Radhakrishnan
<radhakrishnan(dot)mohan(at)gmail(dot)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 using this 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 query planner 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2021-04-02 03:26:30 Re: Primary keys and composite unique keys(basic question)
Previous Message Bruce Momjian 2021-04-02 01:56:17 Re: Upgrading from 11 to 13