@@ -122,6 +122,12 @@ import (
122122//
123123// TODO: null rejecting tables
124124type joinOrderBuilder struct {
125+ // plans maps from a set of base relations to the memo group for the join tree
126+ // that contains those relations (and only those relations). As an example,
127+ // the group for [xy, ab, uv] might contain the join trees (xy, (ab, uv)),
128+ // ((xy, ab), uv), (ab, (xy, uv)), etc.
129+ //
130+ // The group for a single base relation is the base relation itself.
125131 m * Memo
126132 innerEdges edgeSet
127133 nonInnerEdges edgeSet
@@ -362,7 +368,7 @@ func (j *joinOrderBuilder) ensureClosure(grp *ExprGroup) {
362368
363369// hasEqEdge returns true if the inner edges include a direct equality between
364370// the two given columns (e.g. x = a).
365- func (j joinOrderBuilder ) hasEqEdge (leftCol , rightCol sql.ColumnId ) bool {
371+ func (j * joinOrderBuilder ) hasEqEdge (leftCol , rightCol sql.ColumnId ) bool {
366372 for idx , ok := j .innerEdges .Next (0 ); ok ; idx , ok = j .innerEdges .Next (idx + 1 ) {
367373 for _ , f := range j .edges [idx ].filters {
368374 var l * expression.GetField
@@ -839,24 +845,49 @@ func (j *joinOrderBuilder) allEdges() edgeSet {
839845// tree. It is used in calculating the total eligibility sets for edges from any
840846// 'parent' joins which were originally above this one in the tree.
841847type operator struct {
842- leftEdges edgeSet
843- rightEdges edgeSet
844- leftVertices vertexSet
848+ // leftEdges is the set of edges that were constructed from join operators
849+ // that were in the left input of the original join operator.
850+ leftEdges edgeSet
851+ // rightEdgers is the set of edges that were constructed from join operators
852+ // that were in the right input of the original join operator.
853+ rightEdges edgeSet
854+ // leftVertices is the set of vertexes (base relations) that were in the left
855+ // input of the original join operator.
856+ leftVertices vertexSet
857+ // rightVertices is the set of vertexes (base relations) that were in the
858+ // right input of the original join operator.
845859 rightVertices vertexSet
846- joinType plan.JoinType
860+ // joinType is the operator type of the original join operator.
861+ joinType plan.JoinType
847862}
848863
849864// edge is a generalization of a join edge that embeds rules for
850865// determining the applicability of arbitrary subtrees. An edge is added to the
851866// join graph when a new plan can be constructed between two vertexSet.
852867type edge struct {
853- freeVars sql.ColSet
854- op * operator
855- filters []sql.Expression
856- rules []conflictRule
868+ freeVars sql.ColSet
869+ // op is the original join node source for the edge. there are multiple edges
870+ // per op for inner joins with conjunct-predicate join conditions. Different predicates
871+ // will have different conflict rules.
872+ op * operator
873+ // filters is the set of join filters that will be used to construct new join
874+ // ON conditions.
875+ filters []sql.Expression
876+ // rules is a set of conflict rules which must evaluate to true in order for
877+ // a join between two sets of vertexes to be valid.
878+ rules []conflictRule
879+ // nullRejectedRels is the set of vertexes on which nulls are rejected by the
880+ // filters. We do not set any nullRejectedRels currently, which is not accurate
881+ // but prevents potentially invalid transformations.
857882 nullRejectedRels vertexSet
858- ses vertexSet
859- tes vertexSet
883+ // ses is the syntactic eligibility set of the edge; in other words, it is the
884+ // set of base relations (tables) referenced by the filters field.
885+ ses vertexSet
886+ // tes is the total eligibility set of the edge. The TES gives the set of base
887+ // relations (vertexes) that must be in the input of any join that uses the
888+ // filters from this edge in its ON condition. The TES is initialized with the
889+ // SES, and then expanded by the conflict detection algorithm.
890+ tes vertexSet
860891}
861892
862893func (e * edge ) populateEdgeProps (tableIds []sql.TableId , edges []edge ) {
0 commit comments