1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Reimplement CASE val WHEN compval1 THEN ... WHEN compval2 THEN ... END

so that the 'val' is computed only once, per recent discussion.  The
speedup is not much when 'val' is just a simple variable, but could be
significant for larger expressions.  More importantly this avoids issues
with multiple evaluations of a volatile 'val', and it allows the CASE
expression to be reverse-listed in its original form by ruleutils.c.
This commit is contained in:
Tom Lane
2004-03-17 20:48:43 +00:00
parent 8c702ea7ac
commit 55f7c3300d
16 changed files with 248 additions and 55 deletions

View File

@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.278 2004/03/11 01:47:35 ishii Exp $
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.279 2004/03/17 20:48:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -968,6 +968,20 @@ _copyCaseWhen(CaseWhen *from)
return newnode;
}
/*
* _copyCaseTestExpr
*/
static CaseTestExpr *
_copyCaseTestExpr(CaseTestExpr *from)
{
CaseTestExpr *newnode = makeNode(CaseTestExpr);
COPY_SCALAR_FIELD(typeId);
COPY_SCALAR_FIELD(typeMod);
return newnode;
}
/*
* _copyArrayExpr
*/
@ -2643,6 +2657,9 @@ copyObject(void *from)
case T_CaseWhen:
retval = _copyCaseWhen(from);
break;
case T_CaseTestExpr:
retval = _copyCaseTestExpr(from);
break;
case T_ArrayExpr:
retval = _copyArrayExpr(from);
break;