Skip to content
Source
Sign inSign up
TanStack/db

fix(db-ivm): use row keys for stable ORDER BY tie-breaking #957

Mergedsamwillis(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/957/headmerged by samwillis(GitHub profile, opens in a new tab)

Showing 5 changed files with 51 additions and 62 deletions (loading 2).

x
0 of 5 viewed, 5 left
9 additions and 0 deletions.changeset/stable-order-tiebreaker.mdAdded
View file
@@ -0,0 +1,9 @@
+---
+'@tanstack/db-ivm': patch
+---
+​
+Use row keys for stable tie-breaking in ORDER BY operations instead of hash-based object IDs.
+​
+Previously, when multiple rows had equal ORDER BY values, tie-breaking used `globalObjectIdGenerator.getId(key)` which could produce hash collisions and wasn't stable across page reloads for object references. Now, the row key (which is always `string | number` and unique per row) is used directly for tie-breaking, ensuring deterministic and stable ordering.
+​
+This also simplifies the internal `TaggedValue` type from a 3-tuple `[K, V, Tag]` to a 2-tuple `[K, V]`, removing unnecessary complexity.
1 addition and 0 deletionspackages/db-ivm/src/index.tsModified
View file
@@ -2,3 +2,4 @@
export * from './multiset.js'
export * from './operators/index.js'
export * from './types.js'
+export { compareKeys } from './utils.js'
41 additions and 62 deletionspackages/db-ivm/src/operators/topKWithFractionalIndex.tsModified
View file
@@ -2,11 +2,7 @@
import { DifferenceStreamWriter, UnaryOperator } from '../graph.js'
import { StreamBuilder } from '../d2.js'