is column order important when creating a multi-column uniqueness constraint?

From: john snow <ofbizfanster(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: is column order important when creating a multi-column uniqueness constraint?
Date: 2018-01-07 10:35:33
Message-ID: CAE67tvXkXbPyo-Uu0p=yRqv8Yvr+mPH7oor0wZy2DQoVNAsGaw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

we have a table for storing transaction details where the combination of
the following 3 columns need to be a unique composite value (nulls in any
of the columns not allowed either, so composite could probably be a primary
key):

location_code (single char like 'A', 'B', etc; currently, only 4 different
values)

transaction_id (32 bit integer)

materialtype_id (32 bit integer, but currently numbers less than 10000
values)

will specifying the composite primary key or uniqueness constraint (during
creation or definition time) in the following ways result in any
significant differences in performance? in other words, does ordering of
the columns matter, and if yes, why or how?

primary key(location_code, transaction_id, materialtype_id)

primary key(transaction_id, ...)

primary key(materialtype_id, ...)

...

currently, i'm thinking that when querying against each of those columns
individually, filtering by location_id or transaction_id alone will occur
somewhat more frequently than filtering by materialtype_id

thanks for any help!

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Dani 2018-01-07 12:22:44 Re: is column order important when creating a multi-column uniqueness constraint?
Previous Message Rounak Jain 2018-01-07 08:48:53 update master db with records from slave db