Skip to content

Commit

Permalink
Revert "fix a bug that cause tpch performance regression (matrixorigi…
Browse files Browse the repository at this point in the history
…n#17310)"

This reverts commit 14556b3.
  • Loading branch information
XuPeng-SH committed Jul 3, 2024
1 parent 6786951 commit d99d3d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 57 deletions.
64 changes: 19 additions & 45 deletions pkg/sql/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ func (c *Compile) compilePlanScope(step int32, curNodeIdx int32, ns []*plan.Node
return nil, err
}
c.setAnalyzeCurrent(right, curr)
ss = c.compileSort(n, c.compileJoin(n, ns[n.Children[0]], ns[n.Children[1]], ns, left, right))
ss = c.compileSort(n, c.compileJoin(n, ns[n.Children[0]], ns[n.Children[1]], left, right))
return ss, nil
case plan.Node_SORT:
curr := c.anal.curr
Expand Down Expand Up @@ -2564,11 +2564,11 @@ func (c *Compile) compileUnionAll(ss []*Scope, children []*Scope) []*Scope {
return []*Scope{rs}
}

func (c *Compile) compileJoin(node, left, right *plan.Node, ns []*plan.Node, probeScopes, buildScopes []*Scope) []*Scope {
func (c *Compile) compileJoin(node, left, right *plan.Node, probeScopes, buildScopes []*Scope) []*Scope {
if node.Stats.HashmapStats.Shuffle {
return c.compileShuffleJoin(node, left, right, probeScopes, buildScopes)
}
rs := c.compileBroadcastJoin(node, left, right, ns, probeScopes, buildScopes)
rs := c.compileBroadcastJoin(node, left, right, probeScopes, buildScopes)
if c.IsTpQuery() {
//construct join build operator for tp join
buildScopes[0].appendInstruction(constructJoinBuildInstruction(c, rs[0].Instructions[0], false, false))
Expand Down Expand Up @@ -2604,21 +2604,19 @@ func (c *Compile) compileShuffleJoin(node, left, right *plan.Node, lefts, rights
}

parent, children := c.newShuffleJoinScopeList(lefts, rights, node)
if parent != nil {
lastOperator := make([]vm.Instruction, 0, len(children))
lastOperator := make([]vm.Instruction, 0, len(children))
for i := range children {
ilen := len(children[i].Instructions) - 1
lastOperator = append(lastOperator, children[i].Instructions[ilen])
children[i].Instructions = children[i].Instructions[:ilen]
}

defer func() {
// recovery the children's last operator
for i := range children {
ilen := len(children[i].Instructions) - 1
lastOperator = append(lastOperator, children[i].Instructions[ilen])
children[i].Instructions = children[i].Instructions[:ilen]
children[i].appendInstruction(lastOperator[i])
}

defer func() {
// recovery the children's last operator
for i := range children {
children[i].appendInstruction(lastOperator[i])
}
}()
}
}()

switch node.JoinType {
case plan.Node_INNER:
Expand Down Expand Up @@ -2689,13 +2687,10 @@ func (c *Compile) compileShuffleJoin(node, left, right *plan.Node, lefts, rights
panic(moerr.NewNYI(c.proc.Ctx, fmt.Sprintf("shuffle join do not support join type '%v'", node.JoinType)))
}

if parent != nil {
return parent
}
return children
return parent
}

func (c *Compile) compileBroadcastJoin(node, left, right *plan.Node, ns []*plan.Node, probeScopes, buildScopes []*Scope) []*Scope {
func (c *Compile) compileBroadcastJoin(node, left, right *plan.Node, probeScopes, buildScopes []*Scope) []*Scope {
var rs []*Scope
isEq := plan2.IsEquiJoin2(node.OnList)

Expand All @@ -2709,10 +2704,6 @@ func (c *Compile) compileBroadcastJoin(node, left, right *plan.Node, ns []*plan.
leftTyps[i] = dupType(&expr.Typ)
}

if plan2.IsShuffleChildren(left, ns) {
probeScopes = c.mergeShuffleJoinScopeList(probeScopes)
}

switch node.JoinType {
case plan.Node_INNER:
rs = c.newBroadcastJoinScopeList(probeScopes, buildScopes, node)
Expand Down Expand Up @@ -3740,26 +3731,11 @@ func (c *Compile) newBroadcastJoinScopeList(probeScopes []*Scope, buildScopes []
return rs
}

func (c *Compile) mergeShuffleJoinScopeList(child []*Scope) []*Scope {
lenCN := len(c.cnList)
dop := len(child) / lenCN
mergeScope := make([]*Scope, 0, lenCN)
for i, n := range c.cnList {
start := i * dop
end := start + dop
ss := child[start:end]
mergeScope = append(mergeScope, c.newMergeRemoteScope(ss, n))
}
return mergeScope
}

func (c *Compile) newShuffleJoinScopeList(left, right []*Scope, n *plan.Node) ([]*Scope, []*Scope) {
single := len(c.cnList) <= 1
if single {
if len(c.cnList) <= 1 {
n.Stats.HashmapStats.ShuffleTypeForMultiCN = plan.ShuffleTypeForMultiCN_Simple
}

var parent []*Scope
parent := make([]*Scope, 0, len(c.cnList))
children := make([]*Scope, 0, len(c.cnList))
lnum := len(left)
sum := lnum + len(right)
Expand All @@ -3779,9 +3755,7 @@ func (c *Compile) newShuffleJoinScopeList(left, right []*Scope, n *plan.Node) ([
}
}
children = append(children, ss...)
if !single {
parent = append(parent, c.newMergeRemoteScope(ss, cn))
}
parent = append(parent, c.newMergeRemoteScope(ss, cn))
}

currentFirstFlag := c.anal.isFirst
Expand Down
12 changes: 0 additions & 12 deletions pkg/sql/plan/shuffle.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,3 @@ func shouldUseShuffleRanges(s *pb.ShuffleRange) []float64 {
}
return s.Result
}

func IsShuffleChildren(n *plan.Node, ns []*plan.Node) bool {
switch n.NodeType {
case plan.Node_JOIN:
if n.Stats.HashmapStats.Shuffle {
return true
}
case plan.Node_FILTER:
return IsShuffleChildren(ns[n.Children[0]], ns)
}
return false
}

0 comments on commit d99d3d1

Please sign in to comment.