Re: Using a compound primary key - Mailing list pgsql-sql

From Tom Lane
Subject Re: Using a compound primary key
Date
Msg-id 27209.1059371154@sss.pgh.pa.us
Whole thread Raw
In response to Using a compound primary key  ("David Witham" <davidw@unidial.com.au>)
List pgsql-sql
"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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Can a table have a reference to itself?
Next
From: Bruno Wolff III
Date:
Subject: Re: Problem using Subselect results