@@ -16,9 +16,10 @@ package merge
1616
1717import (
1818 "bytes"
19+ "cmp"
1920 "context"
2021 "fmt"
21- "sort "
22+ "slices "
2223 "sync"
2324
2425 "github.com/matrixorigin/matrixone/pkg/logutil"
@@ -131,9 +132,7 @@ func (o *customConfigProvider) String() string {
131132 for k := range o .configs {
132133 keys = append (keys , k )
133134 }
134- sort .Slice (keys , func (i , j int ) bool {
135- return keys [i ] < keys [j ]
136- })
135+ slices .SortFunc (keys , func (a , b uint64 ) int { return cmp .Compare (a , b ) })
137136 buf := bytes.Buffer {}
138137 buf .WriteString ("customConfigProvider: " )
139138 for _ , k := range keys {
@@ -172,12 +171,12 @@ func NewBasicPolicy() Policy {
172171}
173172
174173// impl Policy for Basic
175- func (o * basic ) OnObject (obj * catalog.ObjectEntry ) {
174+ func (o * basic ) OnObject (obj * catalog.ObjectEntry , force bool ) {
176175 rowsLeftOnObj := obj .GetRemainingRows ()
177176 osize := obj .GetOriginSize ()
178177
179- iscandidate := func () bool {
180- // objext with a lot of holes
178+ isCandidate := func () bool {
179+ // object with a lot of holes
181180 if rowsLeftOnObj < obj .GetRows ()/ 2 {
182181 return true
183182 }
@@ -192,7 +191,7 @@ func (o *basic) OnObject(obj *catalog.ObjectEntry) {
192191 return false
193192 }
194193
195- if iscandidate () {
194+ if force || isCandidate () {
196195 o .objHeap .pushWithCap (& mItem [* catalog.ObjectEntry ]{
197196 row : rowsLeftOnObj ,
198197 entry : obj ,
@@ -237,11 +236,17 @@ func (o *basic) GetConfig(tbl *catalog.TableEntry) any {
237236 return r
238237}
239238
240- func (o * basic ) Revise (cpu , mem int64 ) ([]* catalog.ObjectEntry , TaskHostKind ) {
239+ func (o * basic ) Revise (cpu , mem int64 , littleFirst bool ) ([]* catalog.ObjectEntry , TaskHostKind ) {
241240 objs := o .objHeap .finish ()
242- sort .Slice (objs , func (i , j int ) bool {
243- return objs [i ].GetRemainingRows () < objs [j ].GetRemainingRows ()
244- })
241+ if littleFirst {
242+ slices .SortFunc (objs , func (a , b * catalog.ObjectEntry ) int {
243+ return cmp .Compare (a .GetRemainingRows (), b .GetRemainingRows ())
244+ })
245+ } else {
246+ slices .SortFunc (objs , func (a , b * catalog.ObjectEntry ) int {
247+ return - cmp .Compare (a .GetRemainingRows (), b .GetRemainingRows ())
248+ })
249+ }
245250
246251 isStandalone := common .IsStandaloneBoost .Load ()
247252 mergeOnDNIfStandalone := ! common .ShouldStandaloneCNTakeOver .Load ()
@@ -327,16 +332,12 @@ func (o *basic) controlMem(objs []*catalog.ObjectEntry, mem int64) []*catalog.Ob
327332 }
328333
329334 needPopout := func (ss []* catalog.ObjectEntry ) bool {
330- osize , esize , _ := estimateMergeConsume (ss )
331- if esize > int (2 * mem / 3 ) {
332- return true
333- }
334-
335335 if len (ss ) <= 2 {
336336 return false
337337 }
338- // make object averaged size
339- return osize > int (o .config .MaxOsizeMergedObj )
338+
339+ _ , esize , _ := estimateMergeConsume (ss )
340+ return esize > int (2 * mem / 3 )
340341 }
341342 for needPopout (objs ) {
342343 objs = objs [:len (objs )- 1 ]
0 commit comments