Pavel Stehule <pavel.steh...@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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to