Re: PLEASE GOD HELP US!

From: "Scott Marlowe" <smarlowe(at)qwest(dot)net>
To: "Stephan Szabo" <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: "Shane|SkinnyCorp" <shanew(at)skinnycorp(dot)com>, "PgSQL ADMIN" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: PLEASE GOD HELP US!
Date: 2004-10-03 03:39:21
Message-ID: 1096774761.32732.11.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Sat, 2004-10-02 at 15:42, Stephan Szabo wrote:
> On Sat, 2 Oct 2004, Scott Marlowe wrote:
> > So would a union give good performance? Just union the first 25 or less
> > with status=5 with the rest, using a 1 and 0 in each union to order by
> > first? Hopefully the indexes would then be used.
>
> You'd want to use union all I think and you may have to put limits on the
> unioned arms to get good behavior. I think the expression index would
> probably work without changing the query (at least for relatively low
> offsets) at the cost of having an extra index to maintain.
>

I wonder if this would offer any improvement:

select * from (
(SELECT 2 as a,* FROM thread_listing AS t
where t.status=5
ORDER BY t.lastreply desc limit 25)
union
(SELECT 1 as a,* FROM thread_listing AS t
where t.status<>5
order by t.lastreply desc limit 25)
) as p
order by p.a desc, p.lastreply desc limit 25;

Or is there a moving offset we have to deal with here?

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Michael Long 2004-10-03 04:48:08 Re: Installing postgresql-8.0.0beta3
Previous Message Madhukar Gole 2004-10-03 03:09:01 Help needed in setting parameters for postgresql.conf