fix(db): preserve lexical source identity during optimization - #1978
Closed
KyleAMathews wants to merge 1 commit into
Closed
KyleAMathews wants to merge 1 commit into
KyleAMathews wants to merge 1 commit into
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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: |
Contributor
|
Size Change: -15 B (-0.01%) Total Size: 174 kB 📦 View Changed
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 8.51 kB ℹ️ View Unchanged
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A live query can omit parent rows when a joined subquery and a sibling include use the same alias. Jaime02 reported this regression in #1976. The optimizer created new source IDs while it copied collection references. The compiler then associated the joined source with the include input. This PR preserves each lexical source reference during optimization.
Behavior and repair
The reported query joins project rows to issues and includes the project's issues. The join and include both use
ias an alias. On the current main branch, the query returns no project. The expected result contains the Alpha project and its two issues.The optimizer now reuses a
CollectionRefwhen it copies a query or moves a predicate. It also reuses that reference when it removes a redundant subquery. These rewrites keep the source ID and the source collection together.cloneQueryForPlacementstill creates a new reference for each new lexical position.This is an independent implementation of the bug repair in #1976. It does not change Jaime02's PR or its proposed API.
Evidence
[]at the public initial checkpoint. The reference model expects Alpha with two issues.@tanstack/dbself import. The standard package command stops on that unresolved self import.node_modules/.vite-tempin the managed worktree.Scope
The public oracle compares parent and included rows after preload and each source update. It crosses reused and distinct sibling aliases, three predicate forms, and joined or included issue updates. Its bounded model has one matching joined row per parent. An existing part of the oracle covers join multiplicity.
Direct checks cover eleven optimizer shapes and two separate placement clones. They also check that optimization leaves the input query containers and source fields unchanged. These checks do not establish arbitrary nested include graphs or caller mutation of public IR after construction. The coverage map records the remaining paths.
Reported by Jaime02 in #1976. This PR contains an independent repair and an expanded executable oracle.