* ----------------
*/
Node_Copy(from, newnode, clause);
+ newnode->eval_cost = from->eval_cost;
newnode->ispusheddown = from->ispusheddown;
Node_Copy(from, newnode, subclauseindices);
newnode->mergejoinoperator = from->mergejoinoperator;
{
if (!equal(a->clause, b->clause))
return false;
+ /*
+ * ignore eval_cost, since it may not be set yet, and should be
+ * derivable from the clause anyway
+ */
if (a->ispusheddown != b->ispusheddown)
return false;
if (!equal(a->subclauseindices, b->subclauseindices))
token = lsptok(NULL, &length); /* now read it */
local_node->hashjoinoperator = (Oid) atol(token);
+ /* eval_cost is not part of saved representation; compute on first use */
+ local_node->eval_cost = -1;
+
return local_node;
}
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;
}
}
/* 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);
}
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;
/*
* 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))
{
adjust_inherited_attrs_mutator((Node *) oldinfo->clause, context);
newinfo->subclauseindices = NIL;
+ newinfo->eval_cost = -1; /* reset this too */
return (Node *) newinfo;
}
* A mergejoin path has these fields.
*
* path_mergeclauses lists the clauses (in the form of RestrictInfos)
- * that will be used in the merge. (Before 7.0, this was a list of
- * bare clause expressions, but we can save on list memory by leaving
- * it in the form of a RestrictInfo list.)
+ * that will be used in the merge. (Before 7.0, this was a list of bare
+ * clause expressions, but we can save on list memory and cost_qual_eval
+ * work by leaving it in the form of a RestrictInfo list.)
*
* Note that the mergeclauses are a subset of the parent relation's
* restriction-clause list. Any join clauses that are not mergejoinable
Expr *clause; /* the represented clause of WHERE or JOIN */
+ Cost eval_cost; /* eval cost of clause; -1 if not yet set */
+
bool ispusheddown; /* TRUE if clause was pushed down in level */
/* only used if clause is an OR clause: */