fix(db): isolate reused subquery placements - #1878
KyleAMathews wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/react-router-with-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +774 B (+0.47%) Total Size: 167 kB 📦 View Changed
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 7.34 kB ℹ️ View Unchanged
|
Reusing one subquery builder in both
FROMandJOINnow behaves like two lexical placements of the same relation. Same-key self-joins no longer collapse to an empty result.Root cause
CollectionRef.sourceIdidentifies a lexical source position, but embedding a query builder reused its existing IR and therefore reused its source IDs. The live-query graph then treated both sides of a self-join as one source position. Changing or bypassing the compiled-query cache did not help because the collision existed before compilation.Approach
CollectionRefnodes.WeakMap.FROM,JOIN, and included subqueries.Key invariants
offandeagerproduce the same public rows.Non-goals
unionAllbranches; that existing validation remains unchanged.Trade-offs
Cloning the small IR tree at placement time does modest extra construction work, but keeps runtime graph ownership explicit. Caching a logical plan factory could also instantiate fresh graph state, but would be a substantially larger compiler redesign.
Verification
The focused test set passes 200/200.
Files changed
clone-query.ts: cycle-safe placement cloning with fresh source identities.builder/index.ts: clones builders at subquery and include placement boundaries.join-subquery.test.ts: shared-versus-separate builder matrix across predicate and auto-index modes.@tanstack/db.Stacked on #1877, which supplies the adjacent pushed-predicate and alias-remapping fixes.