Re: Index Choice Problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adam Alkins <adam(dot)alkins(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Index Choice Problem
Date: 2006-02-18 05:53:04
Message-ID: 15893.1140241984@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Adam Alkins <adam(dot)alkins(at)gmail(dot)com> writes:
> SELECT t.topic_id
> FROM phpbb_topics AS t
> WHERE t.forum_id = 71
> AND t.topic_id NOT IN (205026, 29046, 144569, 59780, 187424,
> 138635, 184973, 170551, 22419, 181690, 197254, 205130)
> ORDER BY t.topic_last_post_time DESC
> LIMIT 23 OFFSET 0

If you're using 8.1, you'd probably find that an index on (forum_id,
topic_last_post_time) would work nicely for this. You could use it
in prior versions too, but you'd have to spell the ORDER BY rather
strangely:
ORDER BY forum_id desc, topic_last_post_time desc
The reason for this trickery is to get the planner to realize that
the index order matches the ORDER BY ...

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Adam Alkins 2006-02-18 07:29:00 Re: Index Choice Problem
Previous Message Gregory Maxwell 2006-02-17 22:36:10 Re: qsort again (was Re: [PERFORM] Strange Create