-
Notifications
You must be signed in to change notification settings - Fork 132
fix(db-ivm): use row keys for stable ORDER BY tie-breaking #957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 97bd6c9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 87.2 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.35 kB ℹ️ View Unchanged
|
kevin-dp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way better to tie break on the key rather than a hash.
Make sure to fix the problem with the current tie-breaker though such that it correctly compares keys of different types (strings vs numbers).
48853db to
f745b26
Compare
Replace hash-based object ID tie-breaking with direct key comparison for deterministic ordering when ORDER BY values are equal. - Use row key directly as tie-breaker (always string | number, unique per row) - Remove globalObjectIdGenerator dependency - Simplify TaggedValue from [K, V, Tag] to [K, T] tuple - Clean up helper functions (tagValue, getKey, getVal, getTag) This ensures stable, deterministic ordering across page reloads and eliminates potential hash collisions.
1047564 to
4c5cda6
Compare
Summary
TaggedValueabstractionglobalObjectIdGeneratordependency from the topK operatorsProblem
When multiple rows have equal ORDER BY values, the previous implementation used
globalObjectIdGenerator.getId(key)to generate a numeric tag for tie-breaking. This had several issues:TaggedValue<K, V> = [K, V, Tag]3-tuple added overheadSolution
Use the row key directly for tie-breaking:
This works because:
string | number(from collection'sgetKey)Changes
topKWithFractionalIndex.ts:TaggedValue<K, V>with[K, T]tupleglobalObjectIdGeneratorimporttagValue,getKey,getVal,getTaghelperstopKWithFractionalIndexBTree.ts: Update type signatures to use[K, T]Test plan
db-ivmtests pass (267 tests)dbpackage tests pass (1718 tests)