Re: IMMUTABLE break inlining simple SQL functions. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: IMMUTABLE break inlining simple SQL functions.
Date
Msg-id 451.1249230559@sss.pgh.pa.us
Whole thread Raw
In response to IMMUTABLE break inlining simple SQL functions.  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
Pavel Stehule <pavel.stehule@gmail.com> writes:
> I though, so simple SQL functions should be inlined everywhere. When I
> tested sample for recent discussion, I found so immutable flag breaks
> inlining.

Your example proves nothing of the sort, since you have forgotten to
allow for immutable functions being folded to constants.

Actually, AFAICS both of these cases end up being folded to a constant,
but I think the processing path is different --- one will just be
evaluated on sight, the other gets inlined and is then seen to be a
constant expression:

regression=# create or replace function foo(a int) returns int as $$
regression$# select $1+1$$ language sql STRICT IMMUTABLE;
CREATE FUNCTION
regression=# explain verbose select foo(12);               QUERY PLAN                
------------------------------------------Result  (cost=0.00..0.01 rows=1 width=0)  Output: 13
(2 rows)

regression=# create or replace function foo(a int) returns int as $$
select $1+1$$ language sql STRICT ;         
CREATE FUNCTION
regression=# explain verbose select foo(12);               QUERY PLAN                
------------------------------------------Result  (cost=0.00..0.01 rows=1 width=0)  Output: 13
(2 rows)

The fact that it gets inlined rather than evaluated per se is probably
why the stats counter isn't affected.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: machine-readable explain output v4
Next
From: Tom Lane
Date:
Subject: Re: WIP: to_char, support for EEEE format