Re: [HACKERS] Order by optimisations?

2005-07-17 Thread Christopher Kings-Lynne
Does it know that the input to the sort routine is already sorted and hence is a no-op? Yes No, but in most cases this will use an index and hence will assume that the index is responsible for ordering. regards, tom lane ---(end of

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Hannu Krosing
On K, 2005-07-13 at 16:08 +0800, Christopher Kings-Lynne wrote: Hi, Does PostgreSQL do the following optimisation: SELECT * FROM diary WHERE date = '2005-05-01' ORDER BY date; or in fact even better (for my situation) SELECT * FROM diary WHERE date BETWEEN '2005-05-01' AND

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Christopher Kings-Lynne
Hannu Krosing wrote: On K, 2005-07-13 at 16:08 +0800, Christopher Kings-Lynne wrote: Hi, Does PostgreSQL do the following optimisation: SELECT * FROM diary WHERE date = '2005-05-01' ORDER BY date; or in fact even better (for my situation) SELECT * FROM diary WHERE date BETWEEN

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Michael Paesold
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

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Andrew Dunstan
Christopher Kings-Lynne said: usatest=# explain select * from users_myfoods_map where date='2004-11-21' order by date; I assume that this is program generated SQL, as I hope a human would know better than to write this. In which case, isn't the answer to improve the generator rather than

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Jochem van Dieten
On 7/14/05, Michael Paesold wrote: Christopher Kings-Lynne wrote: usatest=# explain select * from users_myfoods_map where date='2004-11-21' order by date; QUERY PLAN --- Sort

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Tom Lane
Hannu Krosing [EMAIL PROTECTED] writes: On K, 2005-07-13 at 16:08 +0800, Christopher Kings-Lynne wrote: Does it know that the input to the sort routine is already sorted and hence is a no-op? Yes No, but in most cases this will use an index and hence will assume that the index is

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Christopher Kings-Lynne
I assume that this is program generated SQL, as I hope a human would know better than to write this. In which case, isn't the answer to improve the generator rather than expect postgres to make up for its defficiencies? Well, the issue in my case is we have user food diaries. Usually,

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Christopher Kings-Lynne
Does it know that the input to the sort routine is already sorted and hence is a no-op? Yes No, but in most cases this will use an index and hence will assume that the index is responsible for ordering. OK, so what's going on here? usa= explain select * from users_myfoods_map where

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Tom Lane
Christopher Kings-Lynne [EMAIL PROTECTED] writes: OK, so what's going on here? usa= explain select * from users_myfoods_map where user_id=1 and date='2003-11-03' order by date; QUERY PLAN

Re: [HACKERS] Order by optimisations?

2005-07-14 Thread Christopher Kings-Lynne
Well, date evidently isn't the high-order key of this index. But why exactly are you worried about a sort of 2 rows? Aha that's nailed it: usa= explain select * from users_myfoods_map where user_id=1 and date between '2003-11-03' and '2003-11-03' order by user_id, date;

[HACKERS] Order by optimisations?

2005-07-13 Thread Christopher Kings-Lynne
Hi, Does PostgreSQL do the following optimisation: SELECT * FROM diary WHERE date = '2005-05-01' ORDER BY date; or in fact even better (for my situation) SELECT * FROM diary WHERE date BETWEEN '2005-05-01' AND '2005-05-01' ORDER BY date; Does it know that the input to the sort routine is