Re: Column order in multi column primary key

From: "Craig Boucher" <craig(at)wesvic(dot)com>
To: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "'David G(dot) Johnston'" <david(dot)g(dot)johnston(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Column order in multi column primary key
Date: 2016-08-08 21:01:37
Message-ID: 0da301d1f1b8$0e0218f0$2a064ad0$@wesvic.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks Tom for the link.

It could actually be beneficial if we need to migrate a customer from one
database to another because wouldn't have to worry about pk constraint
violations.

Craig

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Monday, August 8, 2016 1:47 PM
To: Craig Boucher <craig(at)wesvic(dot)com>
Cc: 'David G. Johnston' <david(dot)g(dot)johnston(at)gmail(dot)com>;
pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Column order in multi column primary key

"Craig Boucher" <craig(at)wesvic(dot)com> writes:
> I should have pointed out in my last response that I was wondering if the
performance of the pk index on work_session would be better if my primary
key was (customer_id, work_session_id) or if (work_session_id, customer_id)
will be fine. Customer_id will be repeated quite a bit in the table but
work_session_id should be unique across the whole table.

You almost certainly want the more-unique column first, so far as the
performance of the index itself goes. See
https://www.postgresql.org/docs/9.5/static/indexes-multicolumn.html

Having said that, I'm pretty skeptical of the notion of redefining what your
PK is on performance grounds. With this definition, you'd allow two entries
with the same work_session_id, if they chanced to have different
customer_ids. Is that really OK?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2016-08-08 21:44:18 Re: Column order in multi column primary key
Previous Message Tom Lane 2016-08-08 20:46:38 Re: Column order in multi column primary key