From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Bryn Llewellyn <bryn(at)yugabyte(dot)com> |
Cc: | Christophe Pettus <xof(at)thebuild(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane PostgreSQL <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: User's responsibility when using a chain of "immutable" functions? |
Date: | 2022-06-29 19:57:16 |
Message-ID: | CAKFQuwaA8c6CD+c6q6LHtNedRZtmmq2yJNhArQ2+V5EXndBKyg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wednesday, June 29, 2022, Bryn Llewellyn <bryn(at)yugabyte(dot)com> wrote:
>
> When I drop the first link, f1() in the chain of "immutable" functions, I
> see that I cannot invoke f(2) because it now complains that f1() doesn't
> exist. This surprises me because, after all, the result of f2() is now
> cached (at least as I suppose) and its body isn't executed to produce the
> result. This outcome almost suggests that there is, after all, a dependency
> tracking scheme at work.
>
> Yet I can still invoke the third link, f(3), and it still does produce the
> value that it had cached!
>
The “cache” is just a prepared statement plan. You didn’t create any of
those yourself at the top SQL context so you don’t see caching effects in
the stuff you execute in SQL directly.
Pl/pgsql, however, creates prepared statement plans for any internal SQL it
executes (i.e., it compiles the function). That is the caching artefact
you are seeing and why I mentioned pl/pgsql in my reply where I described
why you saw the results you did.
IOW, when you write : “ select f2(); “ in SQL f2() is always called, it is
never durectly replaced with a cached value. The documentation does say
this though I lack the relevant paragraph reference at the moment.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Bryn Llewellyn | 2022-06-30 00:03:04 | Re: User's responsibility when using a chain of "immutable" functions? |
Previous Message | Bryn Llewellyn | 2022-06-29 19:36:30 | Re: User's responsibility when using a chain of "immutable" functions? |