Re: Sorting. When?

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Nicolas Barbier" <nicolas(dot)barbier(at)gmail(dot)com>, "mac_man2008(at)yahoo(dot)it" <mac_man2008(at)yahoo(dot)it>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Sorting. When?
Date: 2011-02-11 20:46:09
Message-ID: 4D554BB1020000250003A8CC@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"mac_man2008(at)yahoo(dot)it" <mac_man2008(at)yahoo(dot)it> wrote:

> I need to know, from an algorithmic point of view, in which cases
> sorting is invoked.

Well, I think the only accurate answer to that is "when the
estimated cost of a plan using a sort is lower than the estimated
cost of any alternatives". There are cases where you can be sure a
sort will be used, like when you have an ORDER BY clause and there
is no index which can scan rows in that order; but there are a lot
of situations where plans which involve sorts are in competition
with plans which don't. The plan chosen can depend on such things
as how bloated your table is, how close the order of the tuples in
the heap corresponds to the order of a particular index, how many
rows are in which tables, what work_mem is set to, etc.

Are your really looking to categorize the types of queries where
sorting is *invoked*, or the ones where it is *considered*? Or
perhaps only those where it is *required*, since there are no
possible plans without sorting?

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-02-11 20:46:53 Re: ALTER EXTENSION UPGRADE, v3
Previous Message Gurjeet Singh 2011-02-11 20:44:22 Fix for Index Advisor related hooks