pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gar8@pitt.edu
To: pgsql-admin@postgresql.org
Subject: Primary key order matters?
Date: 11 Sep 2002 07:55:17 -0700
Message-ID: <a1688e61.0209110655.ee37154@posting.google.com> (raw)

I've been tinkering with my database design over the last few months
and today have found something significant that I wanted to share.

It looks as though the order of the primary key index matters. I had
originally had the order set the way I would typically think of the
data if I were to look it up by hand (subject, arm, repetition). But
then, I switched the order so that the field "repetition" was first.
My queries sped up several orders of magnitude! (The cost went from
something like 295,000 to 295). I think this is because there are many
more repetitions than subjects. So at least for me, the primary key
should be order so that the fields with more variance are listed
first.

Perhaps, this is known already to SQL gurus, but I hadn't come across
it in reading about database optimization.

-Tony



Message-ID: <a1688e61.0209110655.ee37154@posting.google.com>
Permalink:  ../a1688e61.0209110655.ee37154@posting.google.com/
Also on:    postgresql.org/message-id/a1688e61.0209110655.ee37154@posting.google.com

 · 

reply

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-admin@postgresql.org
  Cc: gar8@pitt.edu
  Subject: Re: Primary key order matters?
  In-Reply-To: <a1688e61.0209110655.ee37154@posting.google.com>
  References: <a1688e61.0209110655.ee37154@posting.google.com>

* 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