Re: extending ORDER BY make query much slower

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dan Langille" <dan(at)langille(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: extending ORDER BY make query much slower
Date: 2003-03-12 22:00:58
Message-ID: 29647.1047506458@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"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? 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.

If you had an index matching the second ORDER BY clause, you'd probably
get a plan similar to the first case.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jordan S. Jones 2003-03-12 22:01:12 Retrieving Definition for Composite Type
Previous Message Tomasz Myrta 2003-03-12 21:46:25 Re: "hide" values in a column