@@ -24,8 +24,9 @@ import (
24
24
"github.com/pingcap/tidb/pkg/parser/ast"
25
25
"github.com/pingcap/tidb/pkg/planner/core/base"
26
26
"github.com/pingcap/tidb/pkg/planner/core/operator/logicalop"
27
+ ruleutil "github.com/pingcap/tidb/pkg/planner/core/rule/util"
27
28
"github.com/pingcap/tidb/pkg/planner/util/optimizetrace"
28
- "github.com/pingcap/tidb/pkg/util/set "
29
+ "github.com/pingcap/tidb/pkg/util/intset "
29
30
)
30
31
31
32
// OuterJoinEliminator is used to eliminate outer join.
@@ -52,24 +53,24 @@ func (o *OuterJoinEliminator) tryToEliminateOuterJoin(p *logicalop.LogicalJoin,
52
53
53
54
outerPlan := p .Children ()[1 ^ innerChildIdx ]
54
55
innerPlan := p .Children ()[innerChildIdx ]
55
- outerUniqueIDs := set . NewInt64Set ()
56
+ outerUniqueIDs := intset . NewFastIntSet ()
56
57
for _ , outerCol := range outerPlan .Schema ().Columns {
57
- outerUniqueIDs .Insert (outerCol .UniqueID )
58
+ outerUniqueIDs .Insert (int ( outerCol .UniqueID ) )
58
59
}
59
60
60
61
// in case of count(*) FROM R LOJ S, the parentCols is empty, but
61
62
// still need to proceed to check whether we can eliminate outer join.
62
63
// In fact, we only care about whether there is any column from inner
63
64
// table, if there is none, we are good.
64
65
if len (parentCols ) > 0 {
65
- matched := IsColsAllFromOuterTable (parentCols , outerUniqueIDs )
66
+ matched := ruleutil . IsColsAllFromOuterTable (parentCols , & outerUniqueIDs )
66
67
if ! matched {
67
68
return p , false , nil
68
69
}
69
70
}
70
71
71
72
// outer join elimination with duplicate agnostic aggregate functions
72
- matched := IsColsAllFromOuterTable (aggCols , outerUniqueIDs )
73
+ matched := ruleutil . IsColsAllFromOuterTable (aggCols , & outerUniqueIDs )
73
74
if matched {
74
75
appendOuterJoinEliminateAggregationTraceStep (p , outerPlan , aggCols , opt )
75
76
return outerPlan , true , nil
@@ -105,22 +106,6 @@ func (*OuterJoinEliminator) extractInnerJoinKeys(join *logicalop.LogicalJoin, in
105
106
return expression .NewSchema (joinKeys ... )
106
107
}
107
108
108
- // IsColsAllFromOuterTable check whether the cols all from outer plan
109
- func IsColsAllFromOuterTable (cols []* expression.Column , outerUniqueIDs set.Int64Set ) bool {
110
- // There are two cases "return false" here:
111
- // 1. If cols represents aggCols, then "len(cols) == 0" means not all aggregate functions are duplicate agnostic before.
112
- // 2. If cols represents parentCols, then "len(cols) == 0" means no parent logical plan of this join plan.
113
- if len (cols ) == 0 {
114
- return false
115
- }
116
- for _ , col := range cols {
117
- if ! outerUniqueIDs .Exist (col .UniqueID ) {
118
- return false
119
- }
120
- }
121
- return true
122
- }
123
-
124
109
// check whether one of unique keys sets is contained by inner join keys
125
110
func (* OuterJoinEliminator ) isInnerJoinKeysContainUniqueKey (innerPlan base.LogicalPlan , joinKeys * expression.Schema ) (bool , error ) {
126
111
for _ , keyInfo := range innerPlan .Schema ().PKOrUK {
0 commit comments