From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Nested CASE-WHEN scoping
Date: Mon, 30 May 2011 15:25:49 +0300
Message-ID: <4DE38CCD.80702@enterprisedb.com> (raw)
In-Reply-To: <27772.1306359110@sss.pgh.pa.us>
References: <4DDCEEB8.50602@enterprisedb.com>
<5487.1306334876@sss.pgh.pa.us>
<4DDD35B6.2050203@enterprisedb.com>
<27772.1306359110@sss.pgh.pa.us>
On 26.05.2011 00:31, Tom Lane wrote:
> The main annoyance here is that standalone expressions may now need
> Param slots to execute, which will complicate places that need to
> evaluate them, but there's probably no way around that
Yeah, I can see two complications:
1. Domain constraints
Domain constraint check expressions are fetched and constant-folded
separately from the enclosing expression, in ExecInitExpr(). In order to
allocate distinct paramids for any CASE values within the domain check
expression, we'd need to know how many paramids are in use in the parent
expression. We could dig into the parent PlanState and its EState to get
that, but we don't have that for stand-alone expressions.
2. Index expressions
Index expressions are stored in relcache after constant evaluation, so
any CaseTestExprs will already be replaced with Params. When the recheck
expression is evaluated, the paramids used in the recheck expression
will clash with real PARAM_EXEC params used to pass values up and down
subqueries, as well as any params used for CASEs.
I think we can work around both of those by just saving and restoring
the value of each Param that we set while evaluating an expression, as
the values should not be used simultaneously, but it makes me a bit
uncomfortable. If we ever try to inline those expressions into other
expressions, we'll be right back to the issue we have with nested CASE
now. I'm not sure if we might already do that for index recheck
expressions. Alternatively, we could adjust the paramids when an
expression is inlined into another, similar to what OffsetVarNodes does
for Vars.
For debugging purposes, it seems like a good idea to invent a new kind
of Param for these, and keep them separate from PARAM_EXEC params. The
scope would be different, PARAM_EXECs are used to pass values between
planner nodes, while these new kind of Params would be used to pass
values within a single expression.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
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-hackers@postgresql.org
Cc: heikki.linnakangas@enterprisedb.com, tgl@sss.pgh.pa.us
Subject: Re: Nested CASE-WHEN scoping
In-Reply-To: <4DE38CCD.80702@enterprisedb.com>
References: <4DDCEEB8.50602@enterprisedb.com> <5487.1306334876@sss.pgh.pa.us> <4DDD35B6.2050203@enterprisedb.com> <27772.1306359110@sss.pgh.pa.us> <4DE38CCD.80702@enterprisedb.com>
* 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