Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8f0a9e8

Browse files
committed
Second thoughts dept: arrange to cache mergejoin scan selectivity
in RestrictInfo nodes, instead of recomputing on every use.
1 parentf8c1095 commit8f0a9e8

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

‎src/backend/nodes/copyfuncs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.163 2002/02/26 22:47:05 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.164 2002/03/01 06:01:18 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1406,6 +1406,8 @@ _copyRestrictInfo(RestrictInfo *from)
14061406
*/
14071407
newnode->left_pathkey=NIL;
14081408
newnode->right_pathkey=NIL;
1409+
newnode->left_mergescansel=from->left_mergescansel;
1410+
newnode->right_mergescansel=from->right_mergescansel;
14091411
newnode->hashjoinoperator=from->hashjoinoperator;
14101412
newnode->left_bucketsize=from->left_bucketsize;
14111413
newnode->right_bucketsize=from->right_bucketsize;

‎src/backend/nodes/readfuncs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.114 2002/02/26 22:47:07 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.115 2002/03/01 06:01:18 tgl Exp $
1212
*
1313
* NOTES
1414
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -1846,9 +1846,11 @@ _readRestrictInfo(void)
18461846
local_node->eval_cost=-1;
18471847
/* ditto for this_selec */
18481848
local_node->this_selec=-1;
1849-
/* ditto for cached pathkeys and bucketsize */
1849+
/* ditto for cached pathkeys, selectivity, bucketsize */
18501850
local_node->left_pathkey=NIL;
18511851
local_node->right_pathkey=NIL;
1852+
local_node->left_mergescansel=-1;
1853+
local_node->right_mergescansel=-1;
18521854
local_node->left_bucketsize=-1;
18531855
local_node->right_bucketsize=-1;
18541856

‎src/backend/optimizer/path/costsize.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
*
4444
* IDENTIFICATION
45-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.80 2002/03/0104:09:24 tgl Exp $
45+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.81 2002/03/0106:01:19 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -566,6 +566,7 @@ cost_mergejoin(Path *path, Query *root,
566566
Coststartup_cost=0;
567567
Costrun_cost=0;
568568
Costcpu_per_tuple;
569+
RestrictInfo*firstclause;
569570
doubleouter_rows,
570571
inner_rows;
571572
doublentuples;
@@ -581,10 +582,18 @@ cost_mergejoin(Path *path, Query *root,
581582
* Estimate fraction of the left and right inputs that will actually
582583
* need to be scanned. We use only the first (most significant)
583584
* 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.
584589
*/
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;
588597

589598
outer_rows=outer_path->parent->rows*leftscan;
590599
inner_rows=inner_path->parent->rows*rightscan;
@@ -1099,9 +1108,9 @@ cost_qual_eval_walker(Node *node, Cost *total)
10991108
* big difference.)
11001109
*
11011110
* The "dirty" part comes from the fact that the selectivities of multiple
1102-
* clauses are estimated independently and multiplied together.Currently,
1103-
* clauselist_selectivitycan 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_selectivityoften can't do any better than that anyhow, but
1113+
*for some situations (such as range constraints) it is smarter.
11051114
*
11061115
* Since we are only using the results to estimate how many potential
11071116
* output tuples are generated and passed through qpqual checking, it

‎src/backend/optimizer/plan/initsplan.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.65 2001/10/25 05:49:33 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.66 2002/03/01 06:01:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -370,6 +370,8 @@ distribute_qual_to_rels(Query *root, Node *clause,
370370
restrictinfo->right_sortop=InvalidOid;
371371
restrictinfo->left_pathkey=NIL;/* not computable yet */
372372
restrictinfo->right_pathkey=NIL;
373+
restrictinfo->left_mergescansel=-1;/* not computed until needed */
374+
restrictinfo->right_mergescansel=-1;
373375
restrictinfo->hashjoinoperator=InvalidOid;
374376
restrictinfo->left_bucketsize=-1;/* not computed until needed */
375377
restrictinfo->right_bucketsize=-1;

‎src/backend/optimizer/prep/prepunion.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.69 2001/11/12 20:04:20 tgl Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.70 2002/03/01 06:01:20 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -777,6 +777,8 @@ adjust_inherited_attrs_mutator(Node *node,
777777
newinfo->this_selec=-1;
778778
newinfo->left_pathkey=NIL;/* and these */
779779
newinfo->right_pathkey=NIL;
780+
newinfo->left_mergescansel=-1;
781+
newinfo->right_mergescansel=-1;
780782
newinfo->left_bucketsize=-1;
781783
newinfo->right_bucketsize=-1;
782784

‎src/include/nodes/relation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: relation.h,v 1.61 2001/11/05 17:46:34 momjian Exp $
10+
* $Id: relation.h,v 1.62 2002/03/01 06:01:20 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -521,6 +521,10 @@ typedef struct RestrictInfo
521521
List*left_pathkey;/* canonical pathkey for left side */
522522
List*right_pathkey;/* canonical pathkey for right side */
523523

524+
/* cache space for mergeclause processing; -1 if not yet set */
525+
Selectivityleft_mergescansel;/* fraction of left side to scan */
526+
Selectivityright_mergescansel;/* fraction of right side to scan */
527+
524528
/* valid if clause is hashjoinable, else InvalidOid: */
525529
Oidhashjoinoperator;/* copy of clause operator */
526530

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp