From: | Oliver Jowett <oliver(at)opencloud(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Delaying the planning of unnamed statements until Bind |
Date: | 2004-06-14 02:01:00 |
Message-ID: | 40CD06DC.9030309@opencloud.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane wrote:
> Oliver Jowett <oliver(at)opencloud(dot)com> writes:
>
>>At execution time the executor can cache the results of expressions
>>flagged as constant at execution, assuming there's somewhere safe to
>>cache the result for just that execution (ExprState?).
>
>
> That would be the problem; there isn't anyplace appropriate. I'm not
> sure this is really worth pursuing...
Bear with me for a moment then :) .. It'd be nice to have for cases
where there's a frequently evaluated expensive expression that could be
constant-folded if it wasn't parameterized.
I guess that ExprState does not live long enough to be useful. How about
a single-entry cache in the expression node itself, with cache validity
tied to the ExprContext it was evaluated in? i.e. something like: use a
global counter to assign a sufficiently-unique ID to each ExprContext,
copy the context's ID to the cache when filling the cache, and only
treat the cache as valid when the cache's ID matches the current
context's ID.
>>I took a quick look through the executor code, but couldn't see where
>>STABLE function results are cached (for the same arguments).
>
>
> They aren't. STABLE is not a cache-enabling modifier: what it is
> actually for is to license the function to be used in an indexscan
> qualification.
> This is why the definition of STABLE refers to holding still throughout
> a table scan, rather than other reasonable alternatives one might
> consider (such as being constant throughout one transaction).
Ok. The CREATE FUNCTION documentation is a bit misleading: it does
specify the requirement to be immutable during a single table scan, but
the text and examples that follow describe a stronger requirement.
How about introducing a function modifier that provides stronger
guarantees than STABLE, along the lines of "immutable during execution
of a single SQL statement"? From a quick skim of pg_proc, it looks like
most if not all of the existing STABLE functions also meet the stronger
requirement.
-O
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2004-06-14 03:04:03 | Weird 'bit' type behaviour |
Previous Message | pgsql | 2004-06-14 01:35:11 | Re: I just got it: PostgreSQL Application Server -- a |