Re: Column order in multi column primary key - Mailing list pgsql-general

From David G. Johnston
Subject Re: Column order in multi column primary key
Date
Msg-id CAKFQuwYPzpvKkgOx9HrxYYYuDVTfsJiHiDCVE=kXALLeNzN7rw@mail.gmail.com
Whole thread Raw
In response to Re: Column order in multi column primary key  ("Craig Boucher" <craig@wesvic.com>)
Responses Re: Column order in multi column primary key  ("Craig Boucher" <craig@wesvic.com>)
List pgsql-general
On Mon, Aug 8, 2016 at 3:06 PM, Craig Boucher <craig@wesvic.com> wrote:

Here is one of the tables that can have millions of rows and foreign key constraints to 5 other tables.

 

CREATE TABLE public.work_session

(

  work_session_id integer NOT NULL DEFAULT nextval('worksession_worksessionid_seq'::regclass),

  customer_id integer NOT NULL,

  store_id integer NOT NULL,

  department_id integer NOT NULL,

  station_id integer NOT NULL,


 

CREATE TABLE public.department

(

  department_id integer NOT NULL DEFAULT nextval('department_departmentid_seq'::regclass),

  customer_id integer NOT NULL,



No low-hanging fruit that I can see.

This is just some thought food - much 
would depend on the usage patterns of the table and the exact relationship between the different attributes.  Specifically, you've modeled this as an intersection of 4 orthogonal aspects (customer, store, department, station) while in reality these items likely exist in a strict hierarchy. It would
​be ​
possible to have the only FK on work_session be (station_id, customer_id) - and have station have the FK (department_id, customer_id) - and so forth.

David J.
 

pgsql-general by date:

Previous
From: "Craig Boucher"
Date:
Subject: Re: Column order in multi column primary key
Next
From: "Craig Boucher"
Date:
Subject: Re: Column order in multi column primary key