Fix isWhereSubset to handle AND subset with OR superset#1275
Open
KyleAMathews wants to merge 2 commits intomainfrom
Open
Fix isWhereSubset to handle AND subset with OR superset#1275KyleAMathews wants to merge 2 commits intomainfrom
KyleAMathews wants to merge 2 commits intomainfrom
Conversation
… when offline The `isWhereSubsetInternal` function had a critical ordering issue in its predicate checking logic. When a query with `and(eq(...), isNull(...))` was checked against a union superset like `or(and(eq(...), isNull(...)), ...)`, the AND decomposition ran before the OR superset check. This caused the function to decompose the AND into individual conjuncts (eq and isNull), neither of which could independently prove subset of the OR expression, even though the full AND expression was structurally equal to one of the OR disjuncts. The fix reorders the checks so that: 1. superset AND is handled first (unchanged) 2. subset OR is handled next (moved up from after AND) 3. superset OR is handled next (moved up from after IN) 4. subset AND decomposition happens last This ensures that when subset=AND and superset=OR, the full AND expression is checked against each OR disjunct (where structural equality catches it), before being decomposed into individual conjuncts that lose the ability to match compound disjuncts. Reported scenario: on-demand sync with `isNull(soft_deleted_at)` in a where clause caused `isLoadingSubset` to stay true after going offline and remounting, because the DeduplicatedLoadSubset couldn't recognize that data for the predicate was already loaded. https://claude.ai/code/session_01TmGem9Pj1NnXfaWY5FZJdb
|
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: |
Contributor
|
Size Change: -2 B (0%) Total Size: 92.1 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.7 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.
🎯 Changes
Fixed a bug in the
isWhereSubsetpredicate utility where an AND expression was not correctly recognized as a subset of an OR expression containing matching disjuncts.The Problem:
When checking if
and(eq(project_id, X), isNull(soft_deleted_at))is a subset ofor(and(eq(project_id, X), isNull(soft_deleted_at)), and(eq(project_id, Y), isNull(soft_deleted_at))), the function was incorrectly returningfalse. This caused the query system to not recognize that data for project X was already loaded when re-requesting it.The Fix:
Reordered the predicate checks in
isWhereSubsetInternalto handle OR expressions in the superset before decomposing AND expressions in the subset. This ensures that when an AND expression structurally matches one of the OR disjuncts, it's recognized as a subset via direct equality rather than being decomposed into individual conjuncts that can't prove the subset relationship.The key insight:
and(A, B) ⊆ or(and(A, B), and(C, D))must be checked as a whole expression against the OR disjuncts, not by checking if individual conjuncts A or B are subsets of the OR.Changes Made:
isWhereSubsetInternalisNullpredicate handling in various contexts✅ Checklist
pnpm test.🚀 Release Impact
https://claude.ai/code/session_01TmGem9Pj1NnXfaWY5FZJdb