Re: Order by optimisations? - Mailing list pgsql-hackers

From Michael Paesold
Subject Re: Order by optimisations?
Date
Msg-id 012501c58856$fe0f0790$d501a8c0@zaphod
Whole thread Raw
In response to Order by optimisations?  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
Responses Re: Order by optimisations?
List 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 



pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: Order by optimisations?
Next
From: Michael Fuhr
Date:
Subject: 7.3 regression failures after recent commit