Skip to content

test: failing tests for AND/OR queries mixing indexed and non-indexed conditions#1581

Open
kevin-dp wants to merge 2 commits into
TanStack:mainfrom
kevin-dp:test/showcase-index-optimization-or-and-bugs
Open

test: failing tests for AND/OR queries mixing indexed and non-indexed conditions#1581
kevin-dp wants to merge 2 commits into
TanStack:mainfrom
kevin-dp:test/showcase-index-optimization-or-and-bugs

Conversation

@kevin-dp

@kevin-dp kevin-dp commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds seven unit tests to collection-indexes.test.ts that assert the expected results of currentStateAsChanges for where clauses that the index optimizer currently gets wrong. All tests are written purely in terms of expected behaviour.

Mixing indexed and non-indexed conditions (e.g. length(name) > 6):

  1. OR — the result must be the union of rows matching either condition. Currently rows matched only by the non-indexed condition are missing.
  2. AND — every condition must be enforced. Currently rows failing the non-indexed condition are included.
  3. Compound range + condition on another (indexed) field — all conditions must be enforced. Currently only the range is applied.

Range boundary handling:
4. Strictest lower boundgte(age, 25) AND gt(age, 25) must reduce to age > 25 regardless of argument order. Currently the inclusive bound wins.
5. Strictest upper boundlte(age, 30) AND lt(age, 30) must reduce to age < 30. Currently the inclusive bound wins.
6. Date bounds at the same value — distinct Date instances representing the same time must be treated as equal when picking the strictest bound. (Also exercises one-sided compound ranges, which currently return an empty result.)
7. Strict comparisons on date fieldsgt(createdAt, date) must exclude the boundary row. Currently the BTree index includes it because it compares the normalized indexed value against the raw Date.

⚠️ These tests fail on main by design — they pin down the expected behaviour. The follow-up PR #1582 provides the fixes that make them pass.

🤖 Generated with Claude Code

…d non-indexed conditions

These tests assert the expected results of currentStateAsChanges for
AND/OR where clauses that combine conditions on indexed fields with
conditions that cannot be served by an index. They currently fail.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds tests ensuring date gt is strict and expands Complex Query Optimization coverage with mixed indexed/computed predicate cases, overlapping-range precedence, equal-date-instance bound handling, and full conjunction enforcement across fields.

Changes

Complex Query Optimization & Date-bound Tests

Layer / File(s) Summary
Date gt strictness on createdAt
packages/db/tests/collection-indexes.test.ts
Verifies gt on a createdAt date field excludes rows equal to the boundary.
Mixed indexed vs computed predicate boolean ops
packages/db/tests/collection-indexes.test.ts
or(...) returns the union when one branch is index-backed and the other is a non-indexed computed predicate; and(...) enforces conjunction when mixing indexed and computed predicates.
Overlapping range bound precedence
packages/db/tests/collection-indexes.test.ts
Confirms overlapping lower (gte + gt) and upper (lte + lt) bounds apply the strictest bound so shared boundaries are excluded/included correctly.
Date instance equality for range bounds
packages/db/tests/collection-indexes.test.ts
Checks distinct Date instances with identical timestamps are treated as equal for bound enforcement, enforcing the strictest bound.
Compound range with predicate on another field
packages/db/tests/collection-indexes.test.ts
Asserts conjunction semantics when a compound range on one field is combined with a predicate on another field, returning only rows matching the full conjunction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through tests at dawn,

Dates and ranges neatly drawn,
Or and And danced, bounds set right,
Conjunctions matched by morning light,
Hooray — the queries pass tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding failing tests for AND/OR query optimization issues with mixed indexed and non-indexed conditions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description comprehensively covers all changes, provides clear context for why tests are failing, and includes justification for the test-only nature of the changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1581

@tanstack/browser-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1581

@tanstack/capacitor-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1581

@tanstack/cloudflare-durable-objects-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1581

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1581

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1581

@tanstack/db-sqlite-persistence-core

npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1581

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1581

@tanstack/electron-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1581

@tanstack/expo-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1581

@tanstack/node-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1581

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1581

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1581

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1581

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1581

@tanstack/react-native-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1581

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1581

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1581

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1581

@tanstack/tauri-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1581

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1581

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1581

commit: ac26205

Adds expected-behaviour tests for range conditions:
- compound ranges sharing a boundary value must apply the strictest
  bound regardless of argument order, including for date values
- one-sided compound ranges must return the matching rows
- strict comparisons (gt) on date fields must exclude the boundary row

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant