Re: Seq scan on zero-parameters function

From: "Octavio Alvarez" <alvarezp(at)alvarezp(dot)ods(dot)org>
To: "Tomasz Myrta" <jasiek(at)klaster(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Seq scan on zero-parameters function
Date: 2004-02-06 08:43:12
Message-ID: 4795.192.168.0.64.1076056992.squirrel@alvarezp.ods.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance pgsql-sql


Tomasz Myrta said:
> Dnia 2004-02-06 08:19, U¿ytkownik Octavio Alvarez napisa³:
>> In each couple, the first one has a WHERE field = function()
>> condition, just like the second one, but in the form WHERE field =
>> (SELECT function()). In my opinion, both should have the same execution
>> plan, as the function has no parameters and, therefore, is constant.
>
> Nope.
>
> What would you say about function without params returning timeofday()?
> Is it constant?

No... :-P ;-)

> If you are sure, that your function returns constant value - declare it
> as IMMUTABLE. (look at CREATE FUNCTION documentation)

Thanks for the hint.

In fact, my current_period_id() is based on time, but it should be
constant along the query execution. I mean, I don't want some records
filtered with some values and other with other values... I'll have an
uncongruent recordset.

Say SELECT [field-list] FROM [complex-join] WHERE sec = datepart('second',
now()); Now suppose the query takes always more than 1 second because of
the complex-join or whatever reason: I will naver have a congruent
recordset.

IMMUTABLE wouldn't help here, only wrapping the function in a subquery. Is
this expected behavior? Is this standards compliant (if it can be
qualified as such)?

Octavio.

--
Octavio Alvarez.
E-mail: alvarezp(at)alvarezp(dot)ods(dot)org(dot)

Agradezco que sus correos sean enviados siempre a esta dirección.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Richard Huxton 2004-02-06 08:50:50 Re: Seq scan on zero-parameters function
Previous Message Octavio Alvarez 2004-02-06 07:19:04 Seq scan on zero-parameters function

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2004-02-06 08:50:50 Re: Seq scan on zero-parameters function
Previous Message Tomasz Myrta 2004-02-06 07:28:39 [Fwd: Re: [PERFORM] Seq scan on zero-parameters function]