From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mohan Radhakrishnan <radhakrishnan.mohan@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Primary keys and composite unique keys(basic question)
Date: Wed, 31 Mar 2021 10:12:53 -0400
Message-ID: <3168686.1617199973@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOoXFP8gdkAFyDSLbac+advQKPCORYobkGot5CWis+aYZhnb+A@mail.gmail.com>
References: <CAOoXFP8gdkAFyDSLbac+advQKPCORYobkGot5CWis+aYZhnb+A@mail.gmail.com>
Mohan Radhakrishnan <radhakrishnan.mohan@gmail.com> writes:
> 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.
You haven't provided a lot of detail, but use-a-UUID-as-a-primary-key
is often an antipattern. The UUIDs are quasi-random, meaning there's
no locality of reference in the primary key index, resulting in
inefficiency in searches and insertions. If the composite key you
mention has some actual relationship to your application's usage
patterns, it could be winning as a result of better locality of
access to that index.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, radhakrishnan.mohan@gmail.com
Subject: Re: Primary keys and composite unique keys(basic question)
In-Reply-To: <3168686.1617199973@sss.pgh.pa.us>
References: <CAOoXFP8gdkAFyDSLbac+advQKPCORYobkGot5CWis+aYZhnb+A@mail.gmail.com> <3168686.1617199973@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox