Re: 7.4 Wishlist

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: 7.4 Wishlist
Дата
Msg-id 03de01c29a8b$aac36920$6500a8c0@internal
обсуждение исходный текст
Ответ на Re: 7.4 Wishlist  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
> Good!
> Now convert this query so that it only evaluates the date_part thing
> ONCE:
>
> select t.id, date_part('days',now()-t.stamp) from table_name t where
> date_part('days',now()-t.stamp) > 20;

Yes, it's a bit of a bugger that one.

> I hope you all are kidding me in not seeing the real issue i'm trying to
> show here.

I see, yes.  I guess the MySQL idea is to make it explicit to the parser
which parts of the expression are constant and equivalent.

Still, if the parser was smart enough, it could handle the above example
automatically.  However, I think it would be an O(n^2) problem to solve -
matching all subexpressions against all other subexpressions to find the
ones that match...so the MySQL idea is a valid one.

One trick that many people don't know is that you can do it fast in the
GROUP BY clause, just not the WHERE clause:

select t.id, date_part('days',now()-t.stamp) from table_name t group by 2;

Which is something I just discovered recently.

Chris




В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Magnus Naeslund(f)"
Дата:
Сообщение: Re: 7.4 Wishlist
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: 7.4 Wishlist