Re: Order by optimisations?

From: "Michael Paesold" <mpaesold(at)gmx(dot)at>
To: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>, "Hannu Krosing" <hannu(at)skype(dot)net>
Cc: "Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Order by optimisations?
Date: 2005-07-14 09:32:44
Message-ID: 012501c58856$fe0f0790$d501a8c0@zaphod
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Christopher Kings-Lynne wrote:
> Doesn't seem like it does:
>
> usatest=# explain select * from users_myfoods_map where date='2004-11-21'
> order by date;
> QUERY PLAN
> ---------------------------------------------------------------------------
> Sort (cost=17.17..17.48 rows=123 width=22)
> Sort Key: date
> -> Seq Scan on users_myfoods_map (cost=0.00..12.90 rows=123 width=22)
> Filter: (date = '2004-11-21'::date)
> (4 rows)
>
> The sort cost is non-zero. Or am I not looking at the right thing...

You are looking at the right thing, AFAIK. Well, it seems the planner cannot
reason that if a field should have only one value, sorting on that field is
not needed.

I remember there are examples where the planner will know that the input to
a sort is already sorted and will skip the sort. Tom will be able to explain
if this here is a reasonable optimization. I *guess* it could be done, with
some restrictions.

Best Regards,
Michael Paesold

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2005-07-14 11:38:20 Re: Order by optimisations?
Previous Message Christopher Kings-Lynne 2005-07-14 09:06:06 Re: Order by optimisations?