Skip to content

Commit cf509c5

Browse files
authored
Merge pull request #19 from trimble-oss/disable_sort
Implement Karnveer's idea. Drop sorts, since we really don't need it.
2 parents 85618f7 + 4997a62 commit cf509c5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

memory/table.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff 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

15891591
func (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

16011599
func (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

16091605
func copyschema(sch sql.Schema) sql.Schema {

memory/table_editor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ func (pke *pkTableEditAccumulator) ApplyEdits(ctx *sql.Context) error {
515515
}
516516
}
517517

518-
pke.table.sortRows()
518+
// Cost of synchronizing sorts is pretty hefty, so we're going to bypass that
519+
// for our use case...
520+
// pke.table.sortRows()
519521

520522
return nil
521523
}

0 commit comments

Comments
 (0)