pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Witham <davidw@unidial.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Using a compound primary key
Date: Mon, 28 Jul 2003 01:45:54 -0400
Message-ID: <27209.1059371154@sss.pgh.pa.us> (raw)
In-Reply-To: <CFA248776934FD43847E740E43C346D199D7E1@ozimelb03.ozicom.com>
References: <CFA248776934FD43847E740E43C346D199D7E1@ozimelb03.ozicom.com>

"David Witham" <davidw@unidial.com.au> writes:
> select * from tariff
> where tariff_type = 'UIA'
> and prefix in ('44','441','4412','44123','441234','4412345','44123456')
> order by prefix desc limit 1;

> The query doesn't use the primary key index as I might expect:

Flip the index column order --- this should do what you want if prefix
is the first column in the index.  (Improving that is on the wish-list,
but it seems to require a wholesale rethink of the way the planner
searches for indexes matching OR-clauses.)  You may also need to phrase
the ORDER BY as "prefix desc, tariff_type desc" to make it perfectly
clear to the planner that you don't need a separate sort step ... not
quite sure whether that will be needed or not.

			regards, tom lane



view thread (2+ messages)

Message-ID: <27209.1059371154@sss.pgh.pa.us>
Permalink:  ../27209.1059371154@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27209.1059371154@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, davidw@unidial.com.au
  Subject: Re: Using a compound primary key
  In-Reply-To: <27209.1059371154@sss.pgh.pa.us>

* 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