diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-12-12 23:33:34 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-12-12 23:33:34 +0000 |
| commit | 17b843d67718a716c1abb4afd2abf8a5edba9f32 (patch) | |
| tree | a6ed16c25800f101e8c3d2b246460dc45a3ae5dd /src/backend/optimizer | |
| parent | 77c443f8cd24ed439538db699de04c44474d9f33 (diff) | |
| download | postgresql-17b843d67718a716c1abb4afd2abf8a5edba9f32.tar.gz | |
Cache eval cost of qualification expressions in RestrictInfo nodes to
avoid repeated evaluations in cost_qual_eval(). This turns out to save
a useful fraction of planning time. No change to external representation
of RestrictInfo --- although that node type doesn't appear in stored
rules anyway.
Diffstat (limited to 'src/backend/optimizer')
| -rw-r--r-- | src/backend/optimizer/path/costsize.c | 46 | ||||
| -rw-r--r-- | src/backend/optimizer/plan/initsplan.c | 3 | ||||
| -rw-r--r-- | src/backend/optimizer/prep/prepunion.c | 5 |
3 files changed, 37 insertions, 17 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 8251b8d451..c19ae3883d 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -42,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.64 2000/10/05 19:48:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.65 2000/12/12 23:33:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -672,8 +672,38 @@ Cost cost_qual_eval(List *quals) { Cost total = 0; + List *l; - cost_qual_eval_walker((Node *) quals, &total); + /* We don't charge any cost for the implicit ANDing at top level ... */ + + foreach(l, quals) + { + Node *qual = (Node *) lfirst(l); + + /* + * RestrictInfo nodes contain an eval_cost field reserved for this + * routine's use, so that it's not necessary to evaluate the qual + * clause's cost more than once. If the clause's cost hasn't been + * computed yet, the field will contain -1. + */ + if (qual && IsA(qual, RestrictInfo)) + { + RestrictInfo *restrictinfo = (RestrictInfo *) qual; + + if (restrictinfo->eval_cost < 0) + { + restrictinfo->eval_cost = 0; + cost_qual_eval_walker((Node *) restrictinfo->clause, + &restrictinfo->eval_cost); + } + total += restrictinfo->eval_cost; + } + else + { + /* If it's a bare expression, must always do it the hard way */ + cost_qual_eval_walker(qual, &total); + } + } return total; } @@ -748,18 +778,6 @@ cost_qual_eval_walker(Node *node, Cost *total) } /* fall through to examine args of Expr node */ } - - /* - * expression_tree_walker doesn't know what to do with RestrictInfo - * nodes, but we just want to recurse through them. - */ - if (IsA(node, RestrictInfo)) - { - RestrictInfo *restrictinfo = (RestrictInfo *) node; - - return cost_qual_eval_walker((Node *) restrictinfo->clause, total); - } - /* Otherwise, recurse. */ return expression_tree_walker(node, cost_qual_eval_walker, (void *) total); } diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index ee037c750b..12698f5e5f 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.53 2000/11/23 03:57:31 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.54 2000/12/12 23:33:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -338,6 +338,7 @@ distribute_qual_to_rels(Query *root, Node *clause, bool can_be_equijoin; restrictinfo->clause = (Expr *) clause; + restrictinfo->eval_cost = -1; /* not computed until needed */ restrictinfo->subclauseindices = NIL; restrictinfo->mergejoinoperator = InvalidOid; restrictinfo->left_sortop = InvalidOid; diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index ebb09f5939..d52ed8fb92 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.56 2000/11/12 00:36:59 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.57 2000/12/12 23:33:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -652,7 +652,7 @@ adjust_inherited_attrs_mutator(Node *node, /* * We have to process RestrictInfo nodes specially: we do NOT want to * copy the original subclauseindices list, since the new rel may have - * different indices. The list will be rebuilt during planning anyway. + * different indices. The list will be rebuilt during later planning. */ if (IsA(node, RestrictInfo)) { @@ -666,6 +666,7 @@ adjust_inherited_attrs_mutator(Node *node, adjust_inherited_attrs_mutator((Node *) oldinfo->clause, context); newinfo->subclauseindices = NIL; + newinfo->eval_cost = -1; /* reset this too */ return (Node *) newinfo; } |
