Re: generate_series from now to infinity...

Lists: pgsql-hackers
From: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>
To: pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: generate_series from now to infinity...
Date: 2009-05-17 02:10:20
Message-ID: ae46fee10905161910l44d97a5bt16db68725e9ada04@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi all

Is a simple "SELECT generate_series(now(), CAST('infinity'::date AS
timestamp), interval '1 hour');" working forever, an expected
behavior?

regards...
--
Dickson S. Guedes
-
mail/xmpp: guedes(at)guedesoft(dot)net - skype: guediz
http://guedesoft.net - http://www.postgresql.org.br


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>
Cc: pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 03:40:42
Message-ID: 14729.1242531642@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Dickson S. Guedes" <listas(at)guedesoft(dot)net> writes:
> Is a simple "SELECT generate_series(now(), CAST('infinity'::date AS
> timestamp), interval '1 hour');" working forever, an expected
> behavior?

Uh, what were you expecting it to do?

Actually, I believe it will fail eventually when the repeated additions
overflow ... in 294277 AD. So you've got about 2 billion timestamp
additions to wait through.

regards, tom lane


From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>, pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 03:58:41
Message-ID: 37ed240d0905162058q5531f183t1bbc395ed74533cf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, May 17, 2009 at 1:40 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Dickson S. Guedes" <listas(at)guedesoft(dot)net> writes:
>> Is a simple "SELECT generate_series(now(), CAST('infinity'::date AS
>> timestamp), interval '1 hour');" working forever, an expected
>> behavior?
>
> Uh, what were you expecting it to do?

It appears that any generate_series involving infinity is guaranteed to fail.

That being the case, wouldn't it be more useful to throw an error than
to just keep on running until overflow?

Cheers,
BJ


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Brendan Jurd <direvus(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>, pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 11:37:38
Message-ID: 0A5E0082-1745-4AAB-98B5-E8DD132866C3@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On May 16, 2009, at 11:58 PM, Brendan Jurd <direvus(at)gmail(dot)com> wrote:

> On Sun, May 17, 2009 at 1:40 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> "Dickson S. Guedes" <listas(at)guedesoft(dot)net> writes:
>>> Is a simple "SELECT generate_series(now(), CAST('infinity'::date AS
>>> timestamp), interval '1 hour');" working forever, an expected
>>> behavior?
>>
>> Uh, what were you expecting it to do?
>
> It appears that any generate_series involving infinity is guaranteed
> to fail.
>
> That being the case, wouldn't it be more useful to throw an error than
> to just keep on running until overflow?

What if it were combined with LIMIT?

...Robert


From: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 16:38:35
Message-ID: 1242578315.18964.31.camel@guedes-laptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Em Sáb, 2009-05-16 às 23:40 -0400, Tom Lane escreveu:
> "Dickson S. Guedes" <listas(at)guedesoft(dot)net> writes:
> > Is a simple "SELECT generate_series(now(), CAST('infinity'::date AS
> > timestamp), interval '1 hour');" working forever, an expected
> > behavior?
>
> Uh, what were you expecting it to do?

Perhaps, a HINT?

> Actually, I believe it will fail eventually when the repeated additions
> overflow ... in 294277 AD. So you've got about 2 billion timestamp
> additions to wait through.

A customer are porting his application to 8.4, and are using a query
like that. Someone unintentionally included a "infinity" date and that
query have been running until they see the test server memory at 99% and
cpu at 100%.

I suggested him to use LIMIT.

[]s
--
Dickson S. Guedes
mail/xmpp: guedes(at)guedesoft(dot)net - skype: guediz
http://guedesoft.net - http://www.postgresql.org.br


From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 17:22:02
Message-ID: 20090517172202.GA26881@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, May 17, 2009 at 01:38:35PM -0300, Dickson S. Guedes wrote:
> I suggested him to use LIMIT.

interesting. I just tested (on beta1), that while limit works in this
query:
SELECT generate_series(now(), CAST('infinity'::date AS timestamp), interval '1 hour') limit 3;

i.e. it returns 3 rows instantly,
it doesn't for this query:

SELECT i from generate_series(now(), CAST('infinity'::date AS timestamp), interval '1 hour') as x (i) limit 3;

which (as far as i understand it) should be the same.

why is it not limiting generate_series in the second example? is it
intentional?

Best regards,

depesz

--
Linkedin: http://www.linkedin.com/in/depesz / blog: http://www.depesz.com/
jid/gtalk: depesz(at)depesz(dot)com / aim:depeszhdl / skype:depesz_hdl / gg:6749007


From: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>
To: depesz(at)depesz(dot)com
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 17:50:55
Message-ID: 1242582655.18964.33.camel@guedes-laptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Em Dom, 2009-05-17 às 19:22 +0200, hubert depesz lubaczewski escreveu:
> it doesn't for this query:
>
> SELECT i from generate_series(now(), CAST('infinity'::date AS
> timestamp), interval '1 hour') as x (i) limit 3;
>
> which (as far as i understand it) should be the same.
>
> why is it not limiting generate_series in the second example? is it
> intentional?

The EXPLAIN output differ between both.

postgres=# EXPLAIN SELECT generate_series(now(), CAST('infinity'::date
AS timestamp), interval '1 hour') limit 3;
QUERY PLAN
------------------------------------------------
Limit (cost=0.00..0.02 rows=1 width=0)
-> Result (cost=0.00..0.02 rows=1 width=0)

postgres=# explain SELECT i from generate_series(now(),
CAST('infinity'::date AS timestamp), interval '1 hour') as x (i) limit
3;
QUERY PLAN
--------------------------------------------------------------------------------
Limit (cost=0.00..0.05 rows=3 width=8)
-> Function Scan on generate_series x (cost=0.00..17.50 rows=1000
width=8)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: depesz(at)depesz(dot)com
Cc: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>, pg-dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series from now to infinity...
Date: 2009-05-17 17:53:22
Message-ID: 29572.1242582802@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

hubert depesz lubaczewski <depesz(at)depesz(dot)com> writes:
> why is it not limiting generate_series in the second example?

nodeFunctionscan.c sucks the whole SRF output into a tuplestore before
returning any of it. In principle you could do something different for
a value-per-call SRF, but it would require a second whole code path
(or else major refactoring of ExecMakeTableFunctionResult and related
code). The performance implications are unclear too.

I seem to recall there was some discussion of this point when that code
was first written, but nobody bothered to do anything about it.

regards, tom lane