Re: multiple UNIQUE indices for FK - Mailing list pgsql-general

From David G. Johnston
Subject Re: multiple UNIQUE indices for FK
Date
Msg-id CAKFQuwZ1rDPjEv2tAs9QRigUpea8J16AacXmNbxtQJR319SqEg@mail.gmail.com
Whole thread Raw
In response to Re: multiple UNIQUE indices for FK  (Rafal Pietrak <rafal@ztk-rp.eu>)
Responses Re: multiple UNIQUE indices for FK  (Rafal Pietrak <rafal@ztk-rp.eu>)
Re: multiple UNIQUE indices for FK  (Rafal Pietrak <rafal@ztk-rp.eu>)
List pgsql-general
W dniu 23.02.2016 o 09:39, Rafal Pietrak pisze:
> Can anybody suggest any other way out of this mass?

​The only thought that sticks while reading your prose is:​

​message ----> message-person <---- person​
 

​message-person (message_id, person_id, relationship_type[sender, receiver])

Partitioning and partial indexes both have considerable limitations that you might need to work around.  That said normalization exists for a reason and having multiple "person" columns in a table is a form of duplication that if left presents just the problems you are seeing.

I suspect your SSN should fit onto the message-person table.

The following doesn't make sense - if the SSN is sender unique then there is no expectation that a receiver would not receive two messages with the same SSN from different senders.
ALTER ... msgs_to_me ADD CONSTRINT them_uniq UNIQUE (THEM,SSN);

David J.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Designing tables based on user input and defined values
Next
From: Aaron Christensen
Date:
Subject: Re: Designing tables based on user input and defined values