42
42
* Portions Copyright (c) 1994, Regents of the University of California
43
43
*
44
44
* IDENTIFICATION
45
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.80 2002/03/01 04:09:24 tgl Exp $
45
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.81 2002/03/01 06:01:19 tgl Exp $
46
46
*
47
47
*-------------------------------------------------------------------------
48
48
*/
@@ -566,6 +566,7 @@ cost_mergejoin(Path *path, Query *root,
566
566
Cost startup_cost = 0 ;
567
567
Cost run_cost = 0 ;
568
568
Cost cpu_per_tuple ;
569
+ RestrictInfo * firstclause ;
569
570
double outer_rows ,
570
571
inner_rows ;
571
572
double ntuples ;
@@ -581,10 +582,18 @@ cost_mergejoin(Path *path, Query *root,
581
582
* Estimate fraction of the left and right inputs that will actually
582
583
* need to be scanned. We use only the first (most significant)
583
584
* merge clause for this purpose.
585
+ *
586
+ * Since this calculation is somewhat expensive, and will be the same
587
+ * for all mergejoin paths associated with the merge clause, we cache
588
+ * the results in the RestrictInfo node.
584
589
*/
585
- mergejoinscansel (root ,
586
- (Node * ) ((RestrictInfo * ) lfirst (mergeclauses ))-> clause ,
587
- & leftscan , & rightscan );
590
+ firstclause = (RestrictInfo * ) lfirst (mergeclauses );
591
+ if (firstclause -> left_mergescansel < 0 ) /* not computed yet? */
592
+ mergejoinscansel (root , (Node * ) firstclause -> clause ,
593
+ & firstclause -> left_mergescansel ,
594
+ & firstclause -> right_mergescansel );
595
+ leftscan = firstclause -> left_mergescansel ;
596
+ rightscan = firstclause -> right_mergescansel ;
588
597
589
598
outer_rows = outer_path -> parent -> rows * leftscan ;
590
599
inner_rows = inner_path -> parent -> rows * rightscan ;
@@ -1099,9 +1108,9 @@ cost_qual_eval_walker(Node *node, Cost *total)
1099
1108
* big difference.)
1100
1109
*
1101
1110
* The "dirty" part comes from the fact that the selectivities of multiple
1102
- * clauses are estimated independently and multiplied together. Currently,
1103
- * clauselist_selectivity can seldom do any better than that anyhow, but
1104
- * someday it might be smarter.
1111
+ * clauses are estimated independently and multiplied together. Now
1112
+ * clauselist_selectivity often can't do any better than that anyhow, but
1113
+ * for some situations (such as range constraints) it is smarter.
1105
1114
*
1106
1115
* Since we are only using the results to estimate how many potential
1107
1116
* output tuples are generated and passed through qpqual checking, it
0 commit comments