Re: 7.4 Wishlist - Mailing list pgsql-hackers

From Christopher Kings-Lynne
Subject Re: 7.4 Wishlist
Date
Msg-id 03de01c29a8b$aac36920$6500a8c0@internal
Whole thread Raw
In response to Re: 7.4 Wishlist  (Bruce Momjian <pgman@candle.pha.pa.us>)
List 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 by date:

Previous
From: "Magnus Naeslund(f)"
Date:
Subject: Re: 7.4 Wishlist
Next
From: Bruce Momjian
Date:
Subject: Re: 7.4 Wishlist