1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00

Second thoughts dept: arrange to cache mergejoin scan selectivity

in RestrictInfo nodes, instead of recomputing on every use.
This commit is contained in:
Tom Lane
2002-03-01 06:01:20 +00:00
parent f8c109528c
commit 8f0a9e85b3
6 changed files with 34 additions and 13 deletions

View File

@@ -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.80 2002/03/01 04:09:24 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.81 2002/03/01 06:01:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -566,6 +566,7 @@ cost_mergejoin(Path *path, Query *root,
Cost startup_cost = 0;
Cost run_cost = 0;
Cost cpu_per_tuple;
RestrictInfo *firstclause;
double outer_rows,
inner_rows;
double ntuples;
@@ -581,10 +582,18 @@ cost_mergejoin(Path *path, Query *root,
* Estimate fraction of the left and right inputs that will actually
* need to be scanned. We use only the first (most significant)
* merge clause for this purpose.
*
* Since this calculation is somewhat expensive, and will be the same
* for all mergejoin paths associated with the merge clause, we cache
* the results in the RestrictInfo node.
*/
mergejoinscansel(root,
(Node *) ((RestrictInfo *) lfirst(mergeclauses))->clause,
&leftscan, &rightscan);
firstclause = (RestrictInfo *) lfirst(mergeclauses);
if (firstclause->left_mergescansel < 0) /* not computed yet? */
mergejoinscansel(root, (Node *) firstclause->clause,
&firstclause->left_mergescansel,
&firstclause->right_mergescansel);
leftscan = firstclause->left_mergescansel;
rightscan = firstclause->right_mergescansel;
outer_rows = outer_path->parent->rows * leftscan;
inner_rows = inner_path->parent->rows * rightscan;
@@ -1099,9 +1108,9 @@ cost_qual_eval_walker(Node *node, Cost *total)
* big difference.)
*
* The "dirty" part comes from the fact that the selectivities of multiple
* clauses are estimated independently and multiplied together. Currently,
* clauselist_selectivity can seldom do any better than that anyhow, but
* someday it might be smarter.
* clauses are estimated independently and multiplied together. Now
* clauselist_selectivity often can't do any better than that anyhow, but
* for some situations (such as range constraints) it is smarter.
*
* Since we are only using the results to estimate how many potential
* output tuples are generated and passed through qpqual checking, it

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.65 2001/10/25 05:49:33 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.66 2002/03/01 06:01:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -370,6 +370,8 @@ distribute_qual_to_rels(Query *root, Node *clause,
restrictinfo->right_sortop = InvalidOid;
restrictinfo->left_pathkey = NIL; /* not computable yet */
restrictinfo->right_pathkey = NIL;
restrictinfo->left_mergescansel = -1; /* not computed until needed */
restrictinfo->right_mergescansel = -1;
restrictinfo->hashjoinoperator = InvalidOid;
restrictinfo->left_bucketsize = -1; /* not computed until needed */
restrictinfo->right_bucketsize = -1;

View File

@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.69 2001/11/12 20:04:20 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.70 2002/03/01 06:01:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -777,6 +777,8 @@ adjust_inherited_attrs_mutator(Node *node,
newinfo->this_selec = -1;
newinfo->left_pathkey = NIL; /* and these */
newinfo->right_pathkey = NIL;
newinfo->left_mergescansel = -1;
newinfo->right_mergescansel = -1;
newinfo->left_bucketsize = -1;
newinfo->right_bucketsize = -1;