Re: IMMUTABLE break inlining simple SQL functions.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: IMMUTABLE break inlining simple SQL functions.
Date: 2009-08-02 16:29:19
Message-ID: 451.1249230559@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-08-02 16:34:10 Re: WIP: to_char, support for EEEE format
Previous Message Andres Freund 2009-08-02 16:06:40 Re: machine-readable explain output v4