@@ -16,6 +16,8 @@ package pipeline
1616
1717import (
1818 "bytes"
19+ "fmt"
20+ "matrixone/pkg/container/batch"
1921 "matrixone/pkg/vm"
2022 "matrixone/pkg/vm/engine"
2123 "matrixone/pkg/vm/mempool"
@@ -86,6 +88,9 @@ func (p *Pipeline) Run(segs []engine.Segment, proc *process.Process) (bool, erro
8688}
8789
8890func (p * Pipeline ) RunMerge (proc * process.Process ) (bool , error ) {
91+ var end bool
92+ var err error
93+
8994 proc .Mp = mempool .New ()
9095 defer func () {
9196 proc .Reg .InputBatch = nil
@@ -96,11 +101,13 @@ func (p *Pipeline) RunMerge(proc *process.Process) (bool, error) {
96101 vm .Clean (p .instructions , proc )
97102 return false , err
98103 }
99- i := 0
100104 for {
101- i ++
102105 proc .Reg .InputBatch = nil
103- if end , err := vm .Run (p .instructions , proc ); err != nil || end {
106+ if end , err = vm .Run (p .instructions , proc ); err != nil || end {
107+ {
108+ fmt .Printf ("+++%p begin clean\n " , p )
109+ }
110+ p .clean (proc )
104111 return end , err
105112 }
106113 }
@@ -121,6 +128,30 @@ func (p *Pipeline) prefetch(segs []engine.Segment, proc *process.Process) *queue
121128 return q
122129}
123130
131+ func (p * Pipeline ) clean (proc * process.Process ) {
132+ for _ , reg := range proc .Reg .MergeReceivers {
133+ if reg .Ch != nil {
134+ v := <- reg .Ch
135+ switch {
136+ case v == nil :
137+ reg .Ch = nil
138+ reg .Wg .Done ()
139+ default :
140+ bat := v .(* batch.Batch )
141+ if bat == nil || bat .Attrs == nil {
142+ reg .Ch = nil
143+ reg .Wg .Done ()
144+ } else {
145+ bat .Clean (proc )
146+ reg .Ch = nil
147+ reg .Wg .Done ()
148+ }
149+ }
150+ }
151+ }
152+
153+ }
154+
124155// prefetch
125156func (q * queue ) prefetch (attrs []string ) error {
126157 if q .prefetchIndex == len (q .blocks ) {
0 commit comments