Re: PLEASE GOD HELP US!

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Scott Marlowe <smarlowe(at)qwest(dot)net>
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-02 21:42:57
Message-ID: 20041002143450.V11227@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Sat, 2 Oct 2004, Scott Marlowe wrote:

> On Sat, 2004-10-02 at 09:14, Stephan Szabo wrote:
> > On Fri, 1 Oct 2004, Scott Marlowe wrote:
> >
> > > On Fri, 2004-10-01 at 14:26, Shane | SkinnyCorp wrote:
> > > > Okay, just so no one posts about this again...
> > > >
> > > > the 'ORDER BY t.status=5,lastreply' clause is meant to float the threads
> > > > with a status of '5' to the top of the list... it is NOT meant to only grab
> > > > threads where the status = 5. Oh and believe me, when I take this out of
> > > > the query, it CERTAINLY doesn't add any more than possible 1/4 of a
> > > > millesecond to the speed of the SELECT statement.
> > >
> > >
> > > Wouldn't this work just as well?
> > >
> > > SELECT * FROM thread_listing AS t ORDER BY t.status
> > > DESC,t.lastreply desc LIMIT 25 OFFSET 0
> >
> > Probably not, because I don't think he wants the other statuses to have
> > special ranking over the others, so a status=4 and status=1 row should be
> > sorted by lastreply only effectively. This is the problem of combining
> > separate status flags into a single field if you want to be doing these
> > sorts of queries.
> >
>
> 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.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message John McBride 2004-10-02 22:30:20 Re: fedora core 2 postgresql regression tests fail
Previous Message Scott Marlowe 2004-10-02 21:10:54 Re: PLEASE GOD HELP US!