"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