From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: Immutable function WAY slower than Stable function?
Date: Tue, 07 Aug 2018 14:59:07 -0400
Message-ID: <28959.1533668347@sss.pgh.pa.us> (raw)
In-Reply-To: <CAD3a31W3WBedXgewoUt7OWRmz19xW3r9NyEW4tyXdkuV=-YFGw@mail.gmail.com>
References: <CAD3a31Vh6f5eLhK0kQL6b5mxr2Fc0qda1yW8YqTvDQRxcpg9jg@mail.gmail.com>
<03120a03-75d0-ad6c-691c-35ca7e7fccfa@aklaver.com>
<CAD3a31X3u8A2aqnOHcQG-dE_vaeC=jm+O2uAw8+svp5B0MxC+w@mail.gmail.com>
<27336.1533609731@sss.pgh.pa.us>
<CAD3a31Xu+XHf70HnWeS+rXEvBypOBihDNU1N8DOEaXB36HSi6Q@mail.gmail.com>
<24954.1533658221@sss.pgh.pa.us>
<CAD3a31W3WBedXgewoUt7OWRmz19xW3r9NyEW4tyXdkuV=-YFGw@mail.gmail.com>
Ken Tanzer <ken.tanzer@gmail.com> writes:
> I've wondered in the past about Immutable functions, and particularly the
> scope & lifetime of "forever" in "guaranteed to return the same results
> given the same arguments forever." I assume that's "for all users and all
> sessions," but either in theory or in practice is there a limit to how long
> a stale value might persist?
The two issues I can think of offhand are (a) plans that depend on the
assumption of immutability might persist for the life of active sessions;
(b) if you created an index on the result of an immutable function,
changing the function's behavior would likely render the index
inconsistent. (REINDEX would be enough to fix that, though.)
> And, if you were to drop and recreate a
> function with the same name & parameters, would it start fresh at that
> point?
DROP (not CREATE OR REPLACE) would surely get rid of any dependent
values.
> Finally, I'm wondering if there's any legitimate reason for a immutable
> function to call anything stable or volatile, and if not would it make any
> sense to emit a warning when the function is created.
We've been around on that before, and concluded that it's not worth it.
People have in the past used phony-immutable functions to coerce the
optimizer to do what they want --- in fact, that use case is one of the
reasons why we have the inlining restriction. I'm not sure if such
practices are still popular, but somebody who was doing that would not
appreciate nannyism.
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, ken.tanzer@gmail.com, adrian.klaver@aklaver.com
Subject: Re: Immutable function WAY slower than Stable function?
In-Reply-To: <28959.1533668347@sss.pgh.pa.us>
References: <CAD3a31Vh6f5eLhK0kQL6b5mxr2Fc0qda1yW8YqTvDQRxcpg9jg@mail.gmail.com> <03120a03-75d0-ad6c-691c-35ca7e7fccfa@aklaver.com> <CAD3a31X3u8A2aqnOHcQG-dE_vaeC=jm+O2uAw8+svp5B0MxC+w@mail.gmail.com> <27336.1533609731@sss.pgh.pa.us> <CAD3a31Xu+XHf70HnWeS+rXEvBypOBihDNU1N8DOEaXB36HSi6Q@mail.gmail.com> <24954.1533658221@sss.pgh.pa.us> <CAD3a31W3WBedXgewoUt7OWRmz19xW3r9NyEW4tyXdkuV=-YFGw@mail.gmail.com> <28959.1533668347@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