Skip to content

Commit 7931bfa

Browse files
committed
Make eval_const_expressions simplify FieldSelect from a whole-row Var
into an ordinary one-field Var. Per example from Chris Mungall.
1 parent 2a1ef30 commit 7931bfa

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.131 2003/03/10 03:53:50 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.132 2003/03/14 00:55:17 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHOR DATE MAJOR EVENT
@@ -1497,6 +1497,28 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
14971497
newcoalesce->args = newargs;
14981498
return (Node *) newcoalesce;
14991499
}
1500+
if (IsA(node, FieldSelect))
1501+
{
1502+
/*
1503+
* We can optimize field selection from a whole-row Var into a
1504+
* simple Var. (This case won't be generated directly by the
1505+
* parser, because ParseComplexProjection short-circuits it.
1506+
* But it can arise while simplifying functions.) If the argument
1507+
* isn't a whole-row Var, just fall through to do generic processing.
1508+
*/
1509+
FieldSelect *fselect = (FieldSelect *) node;
1510+
Var *argvar = (Var *) fselect->arg;
1511+
1512+
if (argvar && IsA(argvar, Var) &&
1513+
argvar->varattno == InvalidAttrNumber)
1514+
{
1515+
return (Node *) makeVar(argvar->varno,
1516+
fselect->fieldnum,
1517+
fselect->resulttype,
1518+
fselect->resulttypmod,
1519+
argvar->varlevelsup);
1520+
}
1521+
}
15001522

15011523
/*
15021524
* For any node type not handled above, we recurse using

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy