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

Commitbe6c38b

Browse files
committed
Adjust the definition of RestrictInfo's left_relids and right_relids
fields: now they are valid whenever the clause is a binary opclause,not only when it is a potential join clause (there is a new booleanfield canjoin to signal the latter condition). This lets us avoidrecomputing the relid sets over and over while examining indexes.Still more work to do to make this as useful as it could be, becausethere are places that could use the info but don't have access to theRestrictInfo node.
1 parent5e54515 commitbe6c38b

File tree

10 files changed

+104
-83
lines changed

10 files changed

+104
-83
lines changed

‎src/backend/nodes/copyfuncs.c

Lines changed: 4 additions & 3 deletions
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-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.269 2003/11/29 19:51:49 pgsql Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.270 2003/12/30 23:53:14 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1169,11 +1169,12 @@ _copyRestrictInfo(RestrictInfo *from)
11691169

11701170
COPY_NODE_FIELD(clause);
11711171
COPY_SCALAR_FIELD(ispusheddown);
1172+
COPY_SCALAR_FIELD(canjoin);
1173+
COPY_BITMAPSET_FIELD(left_relids);
1174+
COPY_BITMAPSET_FIELD(right_relids);
11721175
COPY_NODE_FIELD(subclauseindices);/* XXX probably bad */
11731176
COPY_SCALAR_FIELD(eval_cost);
11741177
COPY_SCALAR_FIELD(this_selec);
1175-
COPY_BITMAPSET_FIELD(left_relids);
1176-
COPY_BITMAPSET_FIELD(right_relids);
11771178
COPY_SCALAR_FIELD(mergejoinoperator);
11781179
COPY_SCALAR_FIELD(left_sortop);
11791180
COPY_SCALAR_FIELD(right_sortop);

‎src/backend/nodes/equalfuncs.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.210 2003/11/29 19:51:49 pgsql Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.211 2003/12/30 23:53:14 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -563,16 +563,9 @@ _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
563563
COMPARE_SCALAR_FIELD(ispusheddown);
564564

565565
/*
566-
* We ignore subclauseindices, eval_cost, this_selec,
567-
* left/right_relids, left/right_pathkey, and left/right_bucketsize,
568-
* since they may not be set yet, and should be derivable from the
569-
* clause anyway. Probably it's not really necessary to compare any
570-
* of these remaining fields ...
566+
* We ignore all the remaining fields, since they may not be set yet,
567+
* and should be derivable from the clause anyway.
571568
*/
572-
COMPARE_SCALAR_FIELD(mergejoinoperator);
573-
COMPARE_SCALAR_FIELD(left_sortop);
574-
COMPARE_SCALAR_FIELD(right_sortop);
575-
COMPARE_SCALAR_FIELD(hashjoinoperator);
576569

577570
return true;
578571
}

‎src/backend/nodes/outfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.222 2003/11/29 19:51:49 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.223 2003/12/30 23:53:14 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1074,9 +1074,10 @@ _outRestrictInfo(StringInfo str, RestrictInfo *node)
10741074
/* NB: this isn't a complete set of fields */
10751075
WRITE_NODE_FIELD(clause);
10761076
WRITE_BOOL_FIELD(ispusheddown);
1077-
WRITE_NODE_FIELD(subclauseindices);
1077+
WRITE_BOOL_FIELD(canjoin);
10781078
WRITE_BITMAPSET_FIELD(left_relids);
10791079
WRITE_BITMAPSET_FIELD(right_relids);
1080+
WRITE_NODE_FIELD(subclauseindices);
10801081
WRITE_OID_FIELD(mergejoinoperator);
10811082
WRITE_OID_FIELD(left_sortop);
10821083
WRITE_OID_FIELD(right_sortop);

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.150 2003/12/18 00:22:12 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.151 2003/12/30 23:53:14 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -64,9 +64,11 @@ static List *group_clauses_by_indexkey_for_join(Query *root,
6464
Relidsouter_relids,
6565
JoinTypejointype,boolisouterjoin);
6666
staticboolmatch_clause_to_indexcol(RelOptInfo*rel,IndexOptInfo*index,
67-
intindexcol,Oidopclass,Expr*clause);
67+
intindexcol,Oidopclass,
68+
Expr*clause,RestrictInfo*rinfo);
6869
staticboolmatch_join_clause_to_indexcol(RelOptInfo*rel,IndexOptInfo*index,
69-
intindexcol,Oidopclass,Expr*clause);
70+
intindexcol,Oidopclass,
71+
RestrictInfo*rinfo);
7072
staticOidindexable_operator(Expr*clause,Oidopclass,
7173
boolindexkey_on_left);
7274
staticboolpred_test(List*predicate_list,List*restrictinfo_list,
@@ -374,14 +376,14 @@ match_or_subclause_to_indexkey(RelOptInfo *rel,
374376
foreach(item, ((BoolExpr*)clause)->args)
375377
{
376378
if (match_clause_to_indexcol(rel,index,0,opclass,
377-
lfirst(item)))
379+
lfirst(item),NULL))
378380
return true;
379381
}
380382
return false;
381383
}
382384
else
383385
returnmatch_clause_to_indexcol(rel,index,0,opclass,
384-
clause);
386+
clause,NULL);
385387
}
386388

387389
/*----------
@@ -445,15 +447,15 @@ extract_or_indexqual_conditions(RelOptInfo *rel,
445447

446448
if (match_clause_to_indexcol(rel,index,
447449
indexcol,curClass,
448-
subsubclause))
450+
subsubclause,NULL))
449451
FastConc(&clausegroup,
450452
expand_indexqual_condition(subsubclause,
451453
curClass));
452454
}
453455
}
454456
elseif (match_clause_to_indexcol(rel,index,
455457
indexcol,curClass,
456-
orsubclause))
458+
orsubclause,NULL))
457459
FastConc(&clausegroup,
458460
expand_indexqual_condition(orsubclause,
459461
curClass));
@@ -470,7 +472,7 @@ extract_or_indexqual_conditions(RelOptInfo *rel,
470472

471473
if (match_clause_to_indexcol(rel,index,
472474
indexcol,curClass,
473-
rinfo->clause))
475+
rinfo->clause,rinfo))
474476
FastConc(&clausegroup,
475477
expand_indexqual_condition(rinfo->clause,
476478
curClass));
@@ -550,7 +552,8 @@ group_clauses_by_indexkey(RelOptInfo *rel, IndexOptInfo *index)
550552
index,
551553
indexcol,
552554
curClass,
553-
rinfo->clause))
555+
rinfo->clause,
556+
rinfo))
554557
FastAppend(&clausegroup,rinfo);
555558
}
556559

@@ -625,7 +628,8 @@ group_clauses_by_indexkey_for_join(Query *root,
625628
index,
626629
indexcol,
627630
curClass,
628-
rinfo->clause))
631+
rinfo->clause,
632+
rinfo))
629633
FastAppend(&clausegroup,rinfo);
630634
}
631635

@@ -654,7 +658,7 @@ group_clauses_by_indexkey_for_join(Query *root,
654658
index,
655659
indexcol,
656660
curClass,
657-
rinfo->clause))
661+
rinfo))
658662
{
659663
FastAppend(&clausegroup,rinfo);
660664
if (!jfoundhere)
@@ -726,6 +730,7 @@ group_clauses_by_indexkey_for_join(Query *root,
726730
* 'indexcol' is a column number of 'index' (counting from 0).
727731
* 'opclass' is the corresponding operator class.
728732
* 'clause' is the clause to be tested.
733+
* 'rinfo' is the clause's RestrictInfo, if available (NULL if not).
729734
*
730735
* Returns true if the clause can be used with this index key.
731736
*
@@ -737,7 +742,8 @@ match_clause_to_indexcol(RelOptInfo *rel,
737742
IndexOptInfo*index,
738743
intindexcol,
739744
Oidopclass,
740-
Expr*clause)
745+
Expr*clause,
746+
RestrictInfo*rinfo)
741747
{
742748
Node*leftop,
743749
*rightop;
@@ -754,9 +760,13 @@ match_clause_to_indexcol(RelOptInfo *rel,
754760
* Check for clauses of the form: (indexkey operator constant) or
755761
* (constant operator indexkey). Anything that is a "pseudo constant"
756762
* expression will do.
763+
*
764+
* If we have the RestrictInfo available, we can make a more efficient
765+
* test for pseudo-constness.
757766
*/
758767
if (match_index_to_operand(leftop,indexcol,rel,index)&&
759-
is_pseudo_constant_clause(rightop))
768+
(rinfo ?is_pseudo_constant_clause_relids(rightop,rinfo->right_relids)
769+
:is_pseudo_constant_clause(rightop)))
760770
{
761771
if (is_indexable_operator(clause,opclass, true))
762772
return true;
@@ -771,7 +781,8 @@ match_clause_to_indexcol(RelOptInfo *rel,
771781
}
772782

773783
if (match_index_to_operand(rightop,indexcol,rel,index)&&
774-
is_pseudo_constant_clause(leftop))
784+
(rinfo ?is_pseudo_constant_clause_relids(leftop,rinfo->left_relids)
785+
:is_pseudo_constant_clause(leftop)))
775786
{
776787
if (is_indexable_operator(clause,opclass, false))
777788
return true;
@@ -813,7 +824,7 @@ match_clause_to_indexcol(RelOptInfo *rel,
813824
* 'index' is an index on 'rel'.
814825
* 'indexcol' is a column number of 'index' (counting from 0).
815826
* 'opclass' is the corresponding operator class.
816-
* 'clause' is the clause to be tested.
827+
* 'rinfo' is the clause to be tested (as a RestrictInfo node).
817828
*
818829
* Returns true if the clause can be used with this index key.
819830
*
@@ -825,8 +836,9 @@ match_join_clause_to_indexcol(RelOptInfo *rel,
825836
IndexOptInfo*index,
826837
intindexcol,
827838
Oidopclass,
828-
Expr*clause)
839+
RestrictInfo*rinfo)
829840
{
841+
Expr*clause=rinfo->clause;
830842
Node*leftop,
831843
*rightop;
832844

@@ -846,27 +858,25 @@ match_join_clause_to_indexcol(RelOptInfo *rel,
846858
*/
847859
if (match_index_to_operand(leftop,indexcol,rel,index))
848860
{
849-
Relidsothervarnos=pull_varnos(rightop);
861+
Relidsothervarnos=rinfo->right_relids;
850862
boolisIndexable;
851863

852864
isIndexable=
853865
!bms_overlap(rel->relids,othervarnos)&&
854866
!contain_volatile_functions(rightop)&&
855867
is_indexable_operator(clause,opclass, true);
856-
bms_free(othervarnos);
857868
returnisIndexable;
858869
}
859870

860871
if (match_index_to_operand(rightop,indexcol,rel,index))
861872
{
862-
Relidsothervarnos=pull_varnos(leftop);
873+
Relidsothervarnos=rinfo->left_relids;
863874
boolisIndexable;
864875

865876
isIndexable=
866877
!bms_overlap(rel->relids,othervarnos)&&
867878
!contain_volatile_functions(leftop)&&
868879
is_indexable_operator(clause,opclass, false);
869-
bms_free(othervarnos);
870880
returnisIndexable;
871881
}
872882

@@ -1351,7 +1361,6 @@ indexable_outerrelids(RelOptInfo *rel, IndexOptInfo *index)
13511361
foreach(j,joininfo->jinfo_restrictinfo)
13521362
{
13531363
RestrictInfo*rinfo= (RestrictInfo*)lfirst(j);
1354-
Expr*clause=rinfo->clause;
13551364
intindexcol=0;
13561365
Oid*classes=index->classlist;
13571366

@@ -1363,7 +1372,7 @@ indexable_outerrelids(RelOptInfo *rel, IndexOptInfo *index)
13631372
index,
13641373
indexcol,
13651374
curClass,
1366-
clause))
1375+
rinfo))
13671376
{
13681377
match_found= true;
13691378
break;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.83 2003/11/29 19:51:50 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.84 2003/12/30 23:53:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -690,7 +690,7 @@ hash_inner_and_outer(Query *root,
690690
{
691691
RestrictInfo*restrictinfo= (RestrictInfo*)lfirst(i);
692692

693-
if (restrictinfo->left_relids==NULL||
693+
if (!restrictinfo->canjoin||
694694
restrictinfo->hashjoinoperator==InvalidOid)
695695
continue;/* not hashjoinable */
696696

@@ -809,12 +809,12 @@ select_mergejoin_clauses(RelOptInfo *joinrel,
809809
switch (jointype)
810810
{
811811
caseJOIN_RIGHT:
812-
if (restrictinfo->left_relids==NULL||
812+
if (!restrictinfo->canjoin||
813813
restrictinfo->mergejoinoperator==InvalidOid)
814814
returnNIL;/* not mergejoinable */
815815
break;
816816
caseJOIN_FULL:
817-
if (restrictinfo->left_relids==NULL||
817+
if (!restrictinfo->canjoin||
818818
restrictinfo->mergejoinoperator==InvalidOid)
819819
ereport(ERROR,
820820
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -826,7 +826,7 @@ select_mergejoin_clauses(RelOptInfo *joinrel,
826826
}
827827
}
828828

829-
if (restrictinfo->left_relids==NULL||
829+
if (!restrictinfo->canjoin||
830830
restrictinfo->mergejoinoperator==InvalidOid)
831831
continue;/* not mergejoinable */
832832

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp