Re: 7.4 Wishlist

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Magnus Naeslund(f)" <mag(at)fbab(dot)net>, "Bruce Momjian" <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 7.4 Wishlist
Date: 2002-12-03 05:20:17
Message-ID: 03de01c29a8b$aac36920$6500a8c0@internal
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-advocacy pgsql-general 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

In response to

Browse pgsql-advocacy by date

  From Date Subject
Next Message Bruce Momjian 2002-12-03 05:27:03 Re: 7.4 Wishlist
Previous Message Magnus Naeslund(f) 2002-12-03 05:14:13 Re: 7.4 Wishlist

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-12-03 05:27:03 Re: 7.4 Wishlist
Previous Message Magnus Naeslund(f) 2002-12-03 05:14:13 Re: 7.4 Wishlist

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2002-12-03 05:27:03 Re: 7.4 Wishlist
Previous Message Magnus Naeslund(f) 2002-12-03 05:14:13 Re: 7.4 Wishlist