Re: [HACKERS] Nested CASE-WHEN scoping

2011-06-17 Thread Heikki Linnakangas
On 16.06.2011 23:56, Tom Lane wrote: Heikki Linnakangas writes: The complicated part is to ensure that levelsup is always set correctly. At parse time, levelsup is always set to 0, as the syntax doesn't allow referencing upper levels directly. When an SQL function is inlined, any ExpressionPara

Re: [HACKERS] Nested CASE-WHEN scoping

2011-06-16 Thread Tom Lane
Heikki Linnakangas writes: > The complicated part is to ensure that levelsup is always set correctly. > At parse time, levelsup is always set to 0, as the syntax doesn't allow > referencing upper levels directly. When an SQL function is inlined, any > ExpressionParams in the expressions that ar

Re: [HACKERS] Nested CASE-WHEN scoping

2011-06-16 Thread Heikki Linnakangas
On 16.06.2011 22:46, Pavel Stehule wrote: I have a query - should be ExpressionParam used for removing a multiple function call when composite result is expanded? With some similar optimization a SELECT (fce(x)).* FROM tab will be optimal Hmm, I don't think it will work as is for that purpose,

Re: [HACKERS] Nested CASE-WHEN scoping

2011-06-16 Thread Pavel Stehule
Hello 2011/6/3 Heikki Linnakangas : > On 31.05.2011 19:10, Heikki Linnakangas wrote: >> >> For index expressions, we could use a function similar to >> ChangeVarNodes(), that shifts all the paramids in the already-planned >> expression, preparing it for inclusion within the enclosing plan. I'm a >

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-31 Thread Heikki Linnakangas
On 30.05.2011 17:21, Tom Lane wrote: Heikki Linnakangas writes: 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, Huh? That's a waste of time and effort. Just make sure that each such spot has its own Pa

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-30 Thread Heikki Linnakangas
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 con

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-30 Thread Tom Lane
Heikki Linnakangas writes: > 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, Huh? That's a waste of time and effort. Just make sure that each such spot has its own Param number. That's why I'm telling

Displaying optimized CASE expressions (was Re: [HACKERS] Nested CASE-WHEN scoping)

2011-05-25 Thread Tom Lane
I wrote: > Heikki Linnakangas writes: >> BTW, i just stumbled into this: >> postgres=# explain verbose SELECT CASE now() WHEN (29+random()::int4) >> THEN 'foo' ELSE 'bar' END; >> ERROR: unexpected CASE WHEN clause: 326 >> Looks like ruleutils.c is also not prepared for the case that the >> im

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Tom Lane
Heikki Linnakangas writes: > On 25.05.2011 17:47, Tom Lane wrote: >> [ scratches head ... ] Why does the save/restore in ExecEvalCase not >> take care of this? > The mistake happens during planning, when the SQL function is inlined > and pre-evaluated. OK, I see the problem now: we have a Case

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Heikki Linnakangas
On 25.05.2011 20:11, Tom Lane wrote: Heikki Linnakangas writes: On 25.05.2011 17:47, Tom Lane wrote: [ scratches head ... ] Why does the save/restore in ExecEvalCase not take care of this? The mistake happens during planning, when the SQL function is inlined and pre-evaluated. Hm. I'm i

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Tom Lane
Heikki Linnakangas writes: > On 25.05.2011 17:47, Tom Lane wrote: >> [ scratches head ... ] Why does the save/restore in ExecEvalCase not >> take care of this? > The mistake happens during planning, when the SQL function is inlined > and pre-evaluated. Hm. I'm inclined to think this may be mo

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Heikki Linnakangas
On 25.05.2011 17:47, Tom Lane wrote: Heikki Linnakangas writes: While looking at fixing the multiple-evaluation issue in IN and BETWEEN discussed a while ago, I realized that the current assumption that only one CaseTestExpr placeholder needs to be valid at any given time is not true. [ scrat

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Tom Lane
Heikki Linnakangas writes: > While looking at fixing the multiple-evaluation issue in IN and BETWEEN > discussed a while ago, I realized that the current assumption that only > one CaseTestExpr placeholder needs to be valid at any given time is not > true. [ scratches head ... ] Why does the

Re: [HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Heikki Linnakangas
On 25.05.2011 14:57, Heikki Linnakangas wrote: Here's a bit contrived example: CREATE FUNCTION evileq (timestamptz, int4) returns boolean AS $$ SELECT case $2 WHEN length($1::text) THEN true ELSE false END; $$ language sql; CREATE OPERATOR = (procedure = evileq, leftarg = timestamptz, rightarg =

[HACKERS] Nested CASE-WHEN scoping

2011-05-25 Thread Heikki Linnakangas
While looking at fixing the multiple-evaluation issue in IN and BETWEEN discussed a while ago, I realized that the current assumption that only one CaseTestExpr placeholder needs to be valid at any given time is not true. Here's a bit contrived example: CREATE FUNCTION evileq (timestamptz, in