Skip to content

Commit

Permalink
planner: set correct key type of equal condition in pb for null-aware…
Browse files Browse the repository at this point in the history
… semi join (#42304)

close #42303
  • Loading branch information
gengliqi authored Mar 16, 2023
1 parent af60ff8 commit fa28db1
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions planner/core/plan_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,31 +416,28 @@ func (p *PhysicalIndexScan) ToPB(_ sessionctx.Context, _ kv.StoreType) (*tipb.Ex
func (p *PhysicalHashJoin) ToPB(ctx sessionctx.Context, storeType kv.StoreType) (*tipb.Executor, error) {
sc := ctx.GetSessionVars().StmtCtx
client := ctx.GetClient()
var leftJoinKeys, rightJoinKeys []expression.Expression

if len(p.LeftJoinKeys) > 0 && len(p.LeftNAJoinKeys) > 0 {
return nil, errors.Errorf("join key and na join key can not both exist")
}

isNullAwareSemiJoin := len(p.LeftNAJoinKeys) > 0
var leftJoinKeys, rightJoinKeys []*expression.Column
if isNullAwareSemiJoin {
leftJoinKeys = make([]expression.Expression, 0, len(p.LeftNAJoinKeys))
rightJoinKeys = make([]expression.Expression, 0, len(p.RightNAJoinKeys))
for _, leftKey := range p.LeftNAJoinKeys {
leftJoinKeys = append(leftJoinKeys, leftKey)
}
for _, rightKey := range p.RightNAJoinKeys {
rightJoinKeys = append(rightJoinKeys, rightKey)
}
leftJoinKeys = p.LeftNAJoinKeys
rightJoinKeys = p.RightNAJoinKeys
} else {
leftJoinKeys = make([]expression.Expression, 0, len(p.LeftJoinKeys))
rightJoinKeys = make([]expression.Expression, 0, len(p.RightJoinKeys))
for _, leftKey := range p.LeftJoinKeys {
leftJoinKeys = append(leftJoinKeys, leftKey)
}
for _, rightKey := range p.RightJoinKeys {
rightJoinKeys = append(rightJoinKeys, rightKey)
}
leftJoinKeys = p.LeftJoinKeys
rightJoinKeys = p.RightJoinKeys
}

leftKeys := make([]expression.Expression, 0, len(leftJoinKeys))
rightKeys := make([]expression.Expression, 0, len(rightJoinKeys))
for _, leftKey := range leftJoinKeys {
leftKeys = append(leftKeys, leftKey)
}
for _, rightKey := range rightJoinKeys {
rightKeys = append(rightKeys, rightKey)
}

lChildren, err := p.children[0].ToPB(ctx, storeType)
Expand All @@ -452,11 +449,11 @@ func (p *PhysicalHashJoin) ToPB(ctx sessionctx.Context, storeType kv.StoreType)
return nil, errors.Trace(err)
}

left, err := expression.ExpressionsToPBList(sc, leftJoinKeys, client)
left, err := expression.ExpressionsToPBList(sc, leftKeys, client)
if err != nil {
return nil, err
}
right, err := expression.ExpressionsToPBList(sc, rightJoinKeys, client)
right, err := expression.ExpressionsToPBList(sc, rightKeys, client)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -509,9 +506,16 @@ func (p *PhysicalHashJoin) ToPB(ctx sessionctx.Context, storeType kv.StoreType)
case AntiLeftOuterSemiJoin:
pbJoinType = tipb.JoinType_TypeAntiLeftOuterSemiJoin
}
probeFiledTypes := make([]*tipb.FieldType, 0, len(p.EqualConditions))
buildFiledTypes := make([]*tipb.FieldType, 0, len(p.EqualConditions))
for _, equalCondition := range p.EqualConditions {

var equalConditions []*expression.ScalarFunction
if isNullAwareSemiJoin {
equalConditions = p.NAEqualConditions
} else {
equalConditions = p.EqualConditions
}
probeFiledTypes := make([]*tipb.FieldType, 0, len(equalConditions))
buildFiledTypes := make([]*tipb.FieldType, 0, len(equalConditions))
for _, equalCondition := range equalConditions {
retType := equalCondition.RetType.Clone()
chs, coll := equalCondition.CharsetAndCollation()
retType.SetCharset(chs)
Expand Down

0 comments on commit fa28db1

Please sign in to comment.