fix: normalize keys before join operation - #1229
Conversation
🦋 Changeset detectedLatest commit: 5bcb579 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 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: |
…tion The join lazy-loading path passes normalized join keys (e.g. Date→timestamp) into `inArray`, but the `in` evaluator compared raw field values against them using `Array.includes` (strict equality). This meant the optimization silently fell back to loading the full collection for Date-keyed joins. Normalize the value in the `in` evaluator, consistent with how `eq` already normalizes both operands. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the fix! I pushed an additional commit to also normalize the value in the Why this is needed: The join compiler has a lazy-loading optimization where the active side's join keys are passed into The fix normalizes the value in the |
Move the two Date join tests from the separate join-date.test.ts file into the existing Complex Join Scenarios block in join.test.ts, keeping all join tests in one place. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a test verifying that inArray correctly filters rows by Date field values when the array contains Date objects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `in` evaluator used `array.includes(value)` which relies on strict equality. When either the value or the array elements are Date objects (or other types that normalizeValue handles), reference equality fails even when the underlying values are the same. Normalize array elements via `array.some(item => normalizeValue(item) === value)` so that both sides are compared as primitives, consistent with how `eq` already normalizes both operands. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
While reviewing, I found an additional related bug: For example, This is the same class of bug as the original join issue — just in a different code path. The fix (commit 3a23b30) normalizes both the value and the array elements in the // Before
return array.includes(value)
// After
return array.some((item) => normalizeValue(item) === value)This makes |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🎉 This PR has been released! Thank you for your contribution! |
Canonicalize satisfiable join operands through the compilation ValueIdentity, keep nullish operands row-disjoint, and preserve raw lazy-demand values with stable representatives. This restores equality-predicate consistency for binary and other established value domains without adding compound join syntax. Provenance: #593 Lucas Duailibe and Sam Willis; #861 Vincent Chan; #896 Tomas Zaluckij; #779/#899/#1258 Kyle Mathews and Claude; #899 review by Sam Willis; #1229 Hieu Nguyen, Hiếu Nguyễn Minh, Kevin De Porre, and Claude Opus 4.6; #1797 ValueIdentity architecture by Kyle Mathews. Prior art informed the evidence and design; no prior implementation lines were reused. #593/#861 remain design-gated. Weight: production source net +30 lines; emitted join module +65 B ESM gzip and +60 B CJS gzip. No public API, export, dependency, compatibility branch, or db-ivm change.
Canonicalize satisfiable join operands through the compilation ValueIdentity, keep nullish operands row-disjoint, and preserve raw lazy-demand values with stable representatives. This restores equality-predicate consistency for binary and other established value domains without adding compound join syntax. Provenance: #593 Lucas Duailibe and Sam Willis; #861 Vincent Chan; #896 Tomas Zaluckij; #779/#899/#1258 Kyle Mathews and Claude; #899 review by Sam Willis; #1229 Hieu Nguyen, Hiếu Nguyễn Minh, Kevin De Porre, and Claude Opus 4.6; #1797 ValueIdentity architecture by Kyle Mathews. Prior art informed the evidence and design; no prior implementation lines were reused. #593/#861 remain design-gated. Weight: production source net +30 lines; emitted join module +65 B ESM gzip and +60 B CJS gzip. No public API, export, dependency, compatibility branch, or db-ivm change.
* fix(db): align join keys with equality identity Canonicalize satisfiable join operands through the compilation ValueIdentity, keep nullish operands row-disjoint, and preserve raw lazy-demand values with stable representatives. This restores equality-predicate consistency for binary and other established value domains without adding compound join syntax. Provenance: #593 Lucas Duailibe and Sam Willis; #861 Vincent Chan; #896 Tomas Zaluckij; #779/#899/#1258 Kyle Mathews and Claude; #899 review by Sam Willis; #1229 Hieu Nguyen, Hiếu Nguyễn Minh, Kevin De Porre, and Claude Opus 4.6; #1797 ValueIdentity architecture by Kyle Mathews. Prior art informed the evidence and design; no prior implementation lines were reused. #593/#861 remain design-gated. Weight: production source net +30 lines; emitted join module +65 B ESM gzip and +60 B CJS gzip. No public API, export, dependency, compatibility branch, or db-ivm change. * Apply join equality review fixes * Reduce join result processing overhead
Description
To fix the issue #934
Problem
eq(left.date, right.date)were using raw Date object as join keysSolution