@@ -509,14 +509,44 @@ func (s *baseSingleGroupJoinOrderSolver) checkConnection(leftPlan, rightPlan Log
509
509
rightNode , leftNode = leftPlan , rightPlan
510
510
usedEdges = append (usedEdges , edge )
511
511
} else {
512
+ << << << < HEAD
512
513
newSf := expression .NewFunctionInternal (s .ctx , ast .EQ , edge .GetType (), rCol , lCol ).(* expression.ScalarFunction )
514
+ == == == =
515
+ newSf := expression .NewFunctionInternal (s .ctx .GetExprCtx (), ast .EQ , edge .GetType (), rCol , lCol ).(* expression.ScalarFunction )
516
+
517
+ // after creating the new EQ function, the 2 args might not be column anymore, for example `sf=sf(cast(col))`,
518
+ // which breaks the assumption that join eq keys must be `col=col`, to handle this, inject 2 projections.
519
+ _ , isCol0 := newSf .GetArgs ()[0 ].(* expression.Column )
520
+ _ , isCol1 := newSf .GetArgs ()[1 ].(* expression.Column )
521
+ if ! isCol0 || ! isCol1 {
522
+ if ! isCol0 {
523
+ leftPlan , rCol = s .injectExpr (leftPlan , newSf .GetArgs ()[0 ])
524
+ }
525
+ if ! isCol1 {
526
+ rightPlan , lCol = s .injectExpr (rightPlan , newSf .GetArgs ()[1 ])
527
+ }
528
+ leftNode , rightNode = leftPlan , rightPlan
529
+ newSf = expression .NewFunctionInternal (s .ctx .GetExprCtx (), ast .EQ , edge .GetType (),
530
+ rCol , lCol ).(* expression.ScalarFunction )
531
+ }
532
+ >> >> >> > 06 ee59bd9c6 (planner : add projections to keep join keys as `col=col` (#52989 ))
513
533
usedEdges = append (usedEdges , newSf )
514
534
}
515
535
}
516
536
}
517
537
return
518
538
}
519
539
540
+ func (* baseSingleGroupJoinOrderSolver ) injectExpr (p base.LogicalPlan , expr expression.Expression ) (base.LogicalPlan , * expression.Column ) {
541
+ proj , ok := p .(* LogicalProjection )
542
+ if ! ok {
543
+ proj = LogicalProjection {Exprs : cols2Exprs (p .Schema ().Columns )}.Init (p .SCtx (), p .QueryBlockOffset ())
544
+ proj .SetSchema (p .Schema ().Clone ())
545
+ proj .SetChildren (p )
546
+ }
547
+ return proj , proj .appendExpr (expr )
548
+ }
549
+
520
550
// makeJoin build join tree for the nodes which have equal conditions to connect them.
521
551
func (s * baseSingleGroupJoinOrderSolver ) makeJoin (leftPlan , rightPlan LogicalPlan , eqEdges []* expression.ScalarFunction , joinType * joinTypeWithExtMsg ) (LogicalPlan , []expression.Expression ) {
522
552
remainOtherConds := make ([]expression.Expression , len (s .otherConds ))
0 commit comments