From: | Dan Langille <dan(at)langille(dot)org> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: extending ORDER BY make query much slower |
Date: | 2003-03-12 22:48:06 |
Message-ID: | 20030312173223.E95239@xeon.unixathome.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 12 Mar 2003, Tom Lane wrote:
> "Dan Langille" <dan(at)langille(dot)org> writes:
> > I've found that adding another field to the ORDER BY clause, times go
> > through the roof.
>
> Why does that surprise you?
Because I wasn't using the logic you describe below.
> The original query is using an index to
> achieve the required ordering, so it can give you the first 100 rows
> without bothering to compute the remainder. The modified query has to
> actually compute all the rows, and sort them, before it knows which are
> the first 100.
Where as I was thinking, well, it would sort the columns by the first bit,
then by the second bit... wrong....
Thank you, I was looking at it from my narrow point of view: sort them by
commit_date, but if there's two identical, sort those two by commit-id...
not the big picture solution.
> If you had an index matching the second ORDER BY clause, you'd probably
> get a plan similar to the first case.
Understood. FWIW, I created an index which uses both items, then did an
ORDER BY commit_date DESC, commit_log_id desc. Yep, I got good times from
that.
But I don't think I'm going to keep this index around for just this one
query. It's used often, for the main page of the website, but given that
I can get around it with slight modification to the select, I think I'll
use that instead.
From | Date | Subject | |
---|---|---|---|
Next Message | Dan Langille | 2003-03-12 22:59:53 | Re: extending ORDER BY make query much slower |
Previous Message | Steve Crawford | 2003-03-12 22:39:04 | Re: "hide" values in a column |