Re: Division by zero

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Division by zero
Дата
Msg-id 13886.1244126071@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Division by zero  (Sam Mason <sam@samason.me.uk>)
Ответы Re: Division by zero  (Sam Mason <sam@samason.me.uk>)
Список pgsql-general
Sam Mason <sam@samason.me.uk> writes:
> On Thu, Jun 04, 2009 at 09:48:17AM -0400, Tom Lane wrote:
>> Actually, if you're intending that a SQL function be inline-able then
>> it's best *not* to mark it as IMMUTABLE (nor STRICT either).  If the
>> marking matches the behavior of the contained expression then it
>> doesn't matter, but if the marking is stricter than the expression
>> it will prevent inlining.

> Why would strictness alter planning?

Because it alters behavior.  For example, consider

create function foo(int) returns int as
$$ select coalesce($1, 42); $$ language sql strict;

Because this function is declared STRICT, it must return null on null
input.  However, the contained expression would not act that way ---
it would in fact return 42 for null input.  Therefore inlining would
change the behavior, and therefore we don't inline.

The converse case (function not marked strict, but expression really
is) doesn't pose a hazard.  So it's easier to just not mark the function
strict than to think carefully about whether (a) the contained
expression is strict and (b) the planner will be able to prove that.

The same sorts of considerations arise for marking the function as
less volatile than the contained expression really is.  In this case
the "behavioral change" has to do with what later phases of the planner
will think they can do with the function or expression.  The bottom line
is the same though: easier to leave off the marking.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: inf200468@ucf.edu.cu
Дата:
Сообщение: no aparece opcion restaurar
Следующее
От: Bill Moran
Дата:
Сообщение: Re: Upgrading Database: need to dump and restore?