From: Tom Lane <tgl@sss.pgh.pa.us>
To: Philip Semanchuk <philip@americanefficient.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Why is my function inlined only when STABLE?
Date: Tue, 29 Mar 2022 14:24:41 -0400
Message-ID: <51174.1648578281@sss.pgh.pa.us> (raw)
In-Reply-To: <867DEE4A-D480-4009-9DE9-5082B09B357C@americanefficient.com>
References: <867DEE4A-D480-4009-9DE9-5082B09B357C@americanefficient.com>
Philip Semanchuk <philip@americanefficient.com> writes:
> I have a function that isn't being inlined, and I would appreciate help to understand why that's the case.
The example you show *is* inline-able, as you can easily prove with EXPLAIN.
regression=# CREATE OR REPLACE FUNCTION f(foo text)
RETURNS text
AS $$
SELECT substring(foo FROM 1 FOR 2)
$$ LANGUAGE sql IMMUTABLE PARALLEL SAFE;
CREATE FUNCTION
regression=# explain verbose select f(f1) from text_tbl;
QUERY PLAN
----------------------------------------------------------------
Seq Scan on public.text_tbl (cost=0.00..1.02 rows=2 width=32)
Output: "substring"(f1, 1, 2)
(2 rows)
No f() anywhere there.
I think the test methodology you used is faulty, because it does not
distinguish between "inline-able" and "foldable to a constant".
Given an immutable function applied to constant(s), the planner prefers
to fold to a constant by just executing the function. The inline-ing
transformation is considered only when that case doesn't apply.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, philip@americanefficient.com
Subject: Re: Why is my function inlined only when STABLE?
In-Reply-To: <51174.1648578281@sss.pgh.pa.us>
References: <867DEE4A-D480-4009-9DE9-5082B09B357C@americanefficient.com> <51174.1648578281@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox