Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ad48e76
feat(db): make indexing optional with separate entry point
claude Dec 2, 2025
ac382e9
feat(db): change autoIndex default to 'off', enable dev suggestions b…
claude Dec 2, 2025
2c14793
chore: increase collectionSizeThreshold to 1000
claude Dec 2, 2025
e824c74
chore: add changeset for optional indexing
claude Dec 2, 2025
c22c170
fix: changeset should be minor (pre-1.0)
claude Dec 2, 2025
4cb3415
feat(db): add MapIndex as lightweight alternative to BTreeIndex
claude Dec 2, 2025
48a4398
docs: clarify MapIndex falls back to scanning for range queries
claude Dec 2, 2025
4c76687
refactor(db): simplify indexing with BasicIndex and explicit defaultI…
claude Dec 2, 2025
647833e
Remove lazy-index file which re-appeared after rebase
kevin-dp Dec 11, 2025
b746aef
Fix merge conflicts that escaped rebasing
kevin-dp Dec 11, 2025
ddcb1d7
ci: apply automated fixes
autofix-ci[bot] Dec 11, 2025
26c8622
ci: apply automated fixes (attempt 2/3)
autofix-ci[bot] Jan 12, 2026
04cd99c
refactor(db): use shared array utility functions in BasicIndex
github-actions[bot] Jan 12, 2026
50a5fa2
refactor(db): optimize orderedEntriesArrayReversed to use single pass
github-actions[bot] Jan 12, 2026
e44fc72
Simplify equalityLookup
kevin-dp Jan 12, 2026
56230ac
ci: apply automated fixes
autofix-ci[bot] Jan 12, 2026
99bea20
Rename BasicIndex to ReadOptimizedIndex and BTreeIndex to WriteOptimi…
kevin-dp Jan 12, 2026
f91b250
Improved warning
kevin-dp Jan 12, 2026
4e9e770
Fix rangeQueryReversed for ReadOptimizedIndex
kevin-dp Jan 12, 2026
ca03120
ci: apply automated fixes
autofix-ci[bot] Jan 12, 2026
c2239d8
Fix problem with pagination when indexes aren't available. This fixes…
kevin-dp Jan 12, 2026
a758237
Renamed indexes in changeset
kevin-dp Jan 12, 2026
f2796da
Merge branch 'main' into claude/estimate-bundle-without-indexing-01Rp…
KyleAMathews Jan 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .changeset/optional-indexing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
'@tanstack/db': minor
---

Make indexing explicit with two index types for different use cases

**Breaking Changes:**

- `autoIndex` now defaults to `off` instead of `eager`
- `BTreeIndex` is no longer exported from `@tanstack/db` main entry point
- To use `createIndex()` or `autoIndex: 'eager'`, you must set `defaultIndexType` on the collection

**Changes:**

- New `@tanstack/db/indexing` entry point for tree-shakeable indexing
- **BasicIndex** - Lightweight index using Map + sorted Array for both equality and range queries (`eq`, `in`, `gt`, `gte`, `lt`, `lte`). O(n) updates but fast reads.
- **BTreeIndex** - Full-featured index with O(log n) updates and sorted iteration for ORDER BY optimization on large collections (10k+ items)
- Dev mode suggestions (ON by default) warn when indexes would help

**Migration:**

If you were relying on auto-indexing, set `defaultIndexType` on your collections:

1. **Lightweight indexing** (good for most use cases):

```ts
import { BasicIndex } from '@tanstack/db/indexing'

const collection = createCollection({
defaultIndexType: BasicIndex,
autoIndex: 'eager',
// ...
})
```

2. **Full BTree indexing** (for ORDER BY optimization on large collections):

```ts
import { BTreeIndex } from '@tanstack/db/indexing'

const collection = createCollection({
defaultIndexType: BTreeIndex,
autoIndex: 'eager',
// ...
})
```

3. **Per-index explicit type** (mix index types):

```ts
import { BasicIndex, BTreeIndex } from '@tanstack/db/indexing'

const collection = createCollection({
defaultIndexType: BasicIndex, // Default for createIndex()
// ...
})

// Override for specific indexes
collection.createIndex((row) => row.date, { indexType: BTreeIndex })
```

**Bundle Size Impact:**

- No indexing: ~30% smaller bundle
- BasicIndex: ~5 KB (~1.3 KB gzipped)
- BTreeIndex: ~33 KB (~7.8 KB gzipped)
Loading