Skip to content

Commit 1879175

Browse files
committed
Fix performance bug in constant-expression simplifier. After finding
that the inputs to a given operator can be recursively simplified to constants, it was evaluating the operator using the op's *original* (unsimplified) arg list, so that any subexpressions had to be evaluated again. A constant subexpression at depth N got evaluated N times. Probably not very important in practical situations, but it made us look real slow in MySQL's 'crashme' test...
1 parent ef3386a commit 1879175

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 13 additions & 5 deletions
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.60 2000/02/20 21:32:06 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.61 2000/03/12 19:32:06 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHOR DATE MAJOR EVENT
@@ -991,18 +991,26 @@ eval_const_expressions_mutator (Node *node, void *context)
991991
* duplication of code and ensure we get the same result
992992
* as the executor would get.
993993
*
994-
* The only setup needed here is the replace_opid()
995-
* that we already did for the OP_EXPR case.
996-
*
994+
* Build a new Expr node containing the already-simplified
995+
* arguments. The only other setup needed here is the
996+
* replace_opid() that we already did for the OP_EXPR case.
997+
*/
998+
newexpr = makeNode(Expr);
999+
newexpr->typeOid = expr->typeOid;
1000+
newexpr->opType = expr->opType;
1001+
newexpr->oper = expr->oper;
1002+
newexpr->args = args;
1003+
/*
9971004
* It is OK to pass econtext = NULL because none of the
9981005
* ExecEvalExpr() code used in this situation will use
9991006
* econtext. That might seem fortuitous, but it's not
10001007
* so unreasonable --- a constant expression does not
10011008
* depend on context, by definition, n'est ce pas?
10021009
*/
1003-
const_val = ExecEvalExpr((Node *) expr, NULL,
1010+
const_val = ExecEvalExpr((Node *) newexpr, NULL,
10041011
&const_is_null, &isDone);
10051012
Assert(isDone); /* if this isn't set, we blew it... */
1013+
pfree(newexpr);
10061014
/*
10071015
* Make the constant result node.
10081016
*/

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