File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -1558,15 +1558,17 @@ func (t *Table) sortRows() {
15581558 }
15591559
15601560 var idx []partidx
1561+ t .partitionMux .RLock ()
15611562 for _ , k := range t .partitionKeys {
1562- t .partitionMux .RLock ()
15631563 p := t .partitions [string (k )]
15641564 for i := 0 ; i < len (p ); i ++ {
15651565 idx = append (idx , partidx {string (k ), i })
15661566 }
1567- t .partitionMux .RUnlock ()
15681567 }
1568+ t .partitionMux .RUnlock ()
15691569
1570+ t .partitionMux .Lock ()
1571+ defer t .partitionMux .Unlock ()
15701572 sort .Sort (partitionssort {& t .partitionMux , t .partitions , idx , less })
15711573}
15721574
@@ -1587,23 +1589,17 @@ func (ps partitionssort) Len() int {
15871589}
15881590
15891591func (ps partitionssort ) Less (i , j int ) bool {
1590- var less bool
1591- ps .partitionMux .RLock ()
15921592 lidx := ps .idx [i ]
15931593 ridx := ps .idx [j ]
15941594 lr := ps.ps [lidx.key ][lidx.i ]
15951595 rr := ps.ps [ridx.key ][ridx.i ]
1596- less = ps .less (lr , rr )
1597- ps .partitionMux .RUnlock ()
1598- return less
1596+ return ps .less (lr , rr )
15991597}
16001598
16011599func (ps partitionssort ) Swap (i , j int ) {
1602- ps .partitionMux .Lock ()
16031600 lidx := ps .idx [i ]
16041601 ridx := ps .idx [j ]
16051602 ps.ps [lidx.key ][lidx.i ], ps.ps [ridx.key ][ridx.i ] = ps.ps [ridx.key ][ridx.i ], ps.ps [lidx.key ][lidx.i ]
1606- ps .partitionMux .Unlock ()
16071603}
16081604
16091605func copyschema (sch sql.Schema ) sql.Schema {
Original file line number Diff line number Diff line change @@ -515,6 +515,8 @@ func (pke *pkTableEditAccumulator) ApplyEdits(ctx *sql.Context) error {
515515 }
516516 }
517517
518+ // Cost of synchronizing sorts is pretty hefty, so we're going to bypass that
519+ // for our use case...
518520 pke .table .sortRows ()
519521
520522 return nil
You can’t perform that action at this time.
0 commit comments