fix: NTX duplicate key sort — RecNo tiebreak for Harbour compatibility

sort.Slice is unstable: equal keys had random record order.
Harbour NTX B-tree orders equal keys by ascending RecNo.
Added RecNo tiebreak to sort comparator.

Result: 47/47 (100%) Harbour compatibility on rdd_compat test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-06 08:38:45 +09:00
parent 6e78d12cc2
commit af146f03f7

View File

@@ -91,8 +91,12 @@ func (a *DBFArea) OrderCreate(params hbrdd.OrderCreateParams) error {
}
// Sort keys before building index
// Harbour: equal keys ordered by RecNo ascending (stable by record number)
sort.Slice(keys, func(i, j int) bool {
cmp := bytes.Compare(keys[i].Key, keys[j].Key)
if cmp == 0 {
return keys[i].RecNo < keys[j].RecNo
}
if params.Descending {
return cmp > 0
}