Re: Using a compound primary key

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David Witham" <davidw(at)unidial(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using a compound primary key
Date: 2003-07-28 05:45:54
Message-ID: 27209.1059371154@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"David Witham" <davidw(at)unidial(dot)com(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2003-07-28 16:41:29 Re: Problem using Subselect results
Previous Message Tom Lane 2003-07-28 05:31:29 Re: Can a table have a reference to itself?