Re: 7.4 Wishlist

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: "Magnus Naeslund(f)" <mag(at)fbab(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 7.4 Wishlist
Date: 2002-12-03 05:32:49
Message-ID: 20021202212905.R64892-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-advocacy pgsql-general pgsql-hackers


On Tue, 3 Dec 2002, Bruce Momjian wrote:

> Magnus Naeslund(f) wrote:
> > 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;
> >
> > I hope you all are kidding me in not seeing the real issue i'm trying to
> > show here.
>
> Does this work?
>
> SELECT t.id, x.date_part
> FROM table_name t, (select date_part('days',now()-t.stamp)) as x
> WHERE x.date_part > 20;

No, because the values in x are correlated to the particular row in
table_name, so I think you have to make it one big subselect in from. In
addition the optimizer is "smart" enough to push the condition down in
most cases which I think will force the function to be called twice unless
you trigger one of its cases that prevent it from doing so. That's an
optimizer hint I'd like (don't push conditions into this subquery,
really...). :)

In response to

Browse pgsql-advocacy by date

  From Date Subject
Next Message Tom Lane 2002-12-03 06:52:57 Re: Segmentation fault while COPY in 7.3
Previous Message Magnus Naeslund(f) 2002-12-03 05:31:52 Re: 7.4 Wishlist

Browse pgsql-general by date

  From Date Subject
Next Message Madhavi 2002-12-03 05:32:54 MORE INFORMATION ABOUT PGMAIL
Previous Message Magnus Naeslund(f) 2002-12-03 05:31:52 Re: 7.4 Wishlist

Browse pgsql-hackers by date

  From Date Subject
Next Message mlw 2002-12-03 06:17:23 Shrinkwrap Windows Product, any issues? Anyone?
Previous Message Magnus Naeslund(f) 2002-12-03 05:31:52 Re: 7.4 Wishlist