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

Commitcb02610

Browse files
committed
Adjust nestloop-with-inner-indexscan plan generation so that we catch
some cases of redundant clauses that were formerly not caught. We haveto special-case this because the clauses involved never get attached tothe same join restrictlist and so the existing logic does not noticethat they are redundant.
1 parent3fb6f13 commitcb02610

File tree

10 files changed

+284
-137
lines changed

10 files changed

+284
-137
lines changed

‎src/backend/nodes/list.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.49 2003/05/28 22:32:49 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.50 2003/06/15 22:51:45 tgl Exp $
1313
*
1414
* NOTES
1515
* XXX a few of the following functions are duplicated to handle
@@ -358,6 +358,21 @@ llast(List *l)
358358
returnlfirst(l);
359359
}
360360

361+
/*
362+
*llastnode
363+
*
364+
*Get the last node of l ... NIL if empty list
365+
*/
366+
List*
367+
llastnode(List*l)
368+
{
369+
if (l==NIL)
370+
returnNIL;
371+
while (lnext(l)!=NIL)
372+
l=lnext(l);
373+
returnl;
374+
}
375+
361376
/*
362377
*freeList
363378
*

‎src/backend/nodes/outfuncs.c

Lines changed: 5 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/nodes/outfuncs.c,v 1.207 2003/06/06 15:04:02 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.208 2003/06/15 22:51:45 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -933,6 +933,7 @@ _outIndexPath(StringInfo str, IndexPath *node)
933933

934934
WRITE_NODE_FIELD(indexinfo);
935935
WRITE_NODE_FIELD(indexqual);
936+
WRITE_NODE_FIELD(indexjoinclauses);
936937
WRITE_ENUM_FIELD(indexscandir,ScanDirection);
937938
WRITE_FLOAT_FIELD(rows,"%.2f");
938939
}
@@ -1034,6 +1035,7 @@ _outRestrictInfo(StringInfo str, RestrictInfo *node)
10341035
{
10351036
WRITE_NODE_TYPE("RESTRICTINFO");
10361037

1038+
/* NB: this isn't a complete set of fields */
10371039
WRITE_NODE_FIELD(clause);
10381040
WRITE_BOOL_FIELD(ispusheddown);
10391041
WRITE_NODE_FIELD(subclauseindices);
@@ -1042,6 +1044,8 @@ _outRestrictInfo(StringInfo str, RestrictInfo *node)
10421044
WRITE_OID_FIELD(mergejoinoperator);
10431045
WRITE_OID_FIELD(left_sortop);
10441046
WRITE_OID_FIELD(right_sortop);
1047+
WRITE_NODE_FIELD(left_pathkey);
1048+
WRITE_NODE_FIELD(right_pathkey);
10451049
WRITE_OID_FIELD(hashjoinoperator);
10461050
}
10471051

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

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.143 2003/05/28 22:32:49 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.144 2003/06/15 22:51:45 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -59,10 +59,10 @@ static bool match_or_subclause_to_indexkey(RelOptInfo *rel,
5959
IndexOptInfo*index,
6060
Expr*clause);
6161
staticList*group_clauses_by_indexkey(RelOptInfo*rel,IndexOptInfo*index);
62-
staticList*group_clauses_by_indexkey_for_join(RelOptInfo*rel,
63-
IndexOptInfo*index,
64-
Relidsouter_relids,
65-
boolisouterjoin);
62+
staticList*group_clauses_by_indexkey_for_join(Query*root,
63+
RelOptInfo*rel,IndexOptInfo*index,
64+
Relidsouter_relids,
65+
JoinTypejointype,boolisouterjoin);
6666
staticboolmatch_clause_to_indexcol(RelOptInfo*rel,IndexOptInfo*index,
6767
intindexcol,Oidopclass,Expr*clause);
6868
staticboolmatch_join_clause_to_indexcol(RelOptInfo*rel,IndexOptInfo*index,
@@ -583,8 +583,10 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
583583
* will already have been generated for it.)
584584
*/
585585
staticList*
586-
group_clauses_by_indexkey_for_join(RelOptInfo*rel,IndexOptInfo*index,
587-
Relidsouter_relids,boolisouterjoin)
586+
group_clauses_by_indexkey_for_join(Query*root,
587+
RelOptInfo*rel,IndexOptInfo*index,
588+
Relidsouter_relids,
589+
JoinTypejointype,boolisouterjoin)
588590
{
589591
FastListclausegroup_list;
590592
booljfound= false;
@@ -629,6 +631,24 @@ group_clauses_by_indexkey_for_join(RelOptInfo *rel, IndexOptInfo *index,
629631
}
630632
}
631633

634+
/*
635+
* If we found join clauses in more than one joininfo list, we may
636+
* now have clauses that are known redundant. Get rid of 'em.
637+
* (There is no point in looking at restriction clauses, because
638+
* remove_redundant_join_clauses will never think they are
639+
* redundant, so we do this before adding restriction clauses to
640+
* the clause group.)
641+
*/
642+
if (FastListValue(&clausegroup)!=NIL)
643+
{
644+
List*nl;
645+
646+
nl=remove_redundant_join_clauses(root,
647+
FastListValue(&clausegroup),
648+
jointype);
649+
FastListFromList(&clausegroup,nl);
650+
}
651+
632652
/* We can also use plain restriction clauses for the rel */
633653
foreach(i,rel->baserestrictinfo)
634654
{
@@ -1461,9 +1481,11 @@ best_inner_indexscan(Query *root, RelOptInfo *rel,
14611481
List*clausegroups;
14621482

14631483
/* find useful clauses for this index and outerjoin set */
1464-
clausegroups=group_clauses_by_indexkey_for_join(rel,
1484+
clausegroups=group_clauses_by_indexkey_for_join(root,
1485+
rel,
14651486
index,
14661487
index_outer_relids,
1488+
jointype,
14671489
isouterjoin);
14681490
if (clausegroups)
14691491
{
@@ -1520,7 +1542,7 @@ make_innerjoin_index_path(Query *root,
15201542
*allclauses,
15211543
*l;
15221544

1523-
/* XXX this codeought to be merged with create_index_path? */
1545+
/* XXXperhapsthis codeshould be merged with create_index_path? */
15241546

15251547
pathnode->path.pathtype=T_IndexScan;
15261548
pathnode->path.parent=rel;
@@ -1535,12 +1557,25 @@ make_innerjoin_index_path(Query *root,
15351557
/* Convert RestrictInfo nodes to indexquals the executor can handle */
15361558
indexquals=expand_indexqual_conditions(index,clausegroups);
15371559

1560+
/*
1561+
* Also make a flattened list of the RestrictInfo nodes; createplan.c
1562+
* will need this later. We assume here that we can destructively
1563+
* modify the passed-in clausegroups list structure.
1564+
*/
1565+
allclauses=NIL;
1566+
foreach(l,clausegroups)
1567+
{
1568+
/* nconc okay here since same clause couldn't be in two sublists */
1569+
allclauses=nconc(allclauses, (List*)lfirst(l));
1570+
}
1571+
15381572
/*
15391573
* Note that we are making a pathnode for a single-scan indexscan;
1540-
* therefore,bothindexinfo and indexqual should be single-element lists.
1574+
* therefore, indexinfo and indexqual should be single-element lists.
15411575
*/
15421576
pathnode->indexinfo=makeList1(index);
15431577
pathnode->indexqual=makeList1(indexquals);
1578+
pathnode->indexjoinclauses=makeList1(allclauses);
15441579

15451580
/* We don't actually care what order the index scans in ... */
15461581
pathnode->indexscandir=NoMovementScanDirection;
@@ -1558,17 +1593,9 @@ make_innerjoin_index_path(Query *root,
15581593
* linking them into different lists, it should be sufficient to use
15591594
* pointer comparison to remove duplicates.)
15601595
*
1561-
* We assume we can destructively modify the input sublists.
1562-
*
15631596
* Always assume the join type is JOIN_INNER; even if some of the
15641597
* join clauses come from other contexts, that's not our problem.
15651598
*/
1566-
allclauses=NIL;
1567-
foreach(l,clausegroups)
1568-
{
1569-
/* nconc okay here since same clause couldn't be in two sublists */
1570-
allclauses=nconc(allclauses, (List*)lfirst(l));
1571-
}
15721599
allclauses=set_ptrUnion(rel->baserestrictinfo,allclauses);
15731600
pathnode->rows=rel->tuples*
15741601
restrictlist_selectivity(root,

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

Lines changed: 4 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/path/orindxpath.c,v 1.50 2003/05/28 22:32:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.51 2003/06/15 22:51:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -89,6 +89,9 @@ create_or_index_paths(Query *root, RelOptInfo *rel)
8989
*/
9090
pathnode->path.pathkeys=NIL;
9191

92+
/* It's not an innerjoin path. */
93+
pathnode->indexjoinclauses=NIL;
94+
9295
/* We don't actually care what order the index scans in. */
9396
pathnode->indexscandir=NoMovementScanDirection;
9497

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp