-
Notifications
You must be signed in to change notification settings - Fork 55
Index that uses B+ tree #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 0b2875e The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@tanstack/db-example-react-todo @tanstack/db
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Size Change: +5.49 kB (+10.44%) Total Size: 58.1 kB
ℹ️ View Unchanged
|
Size Change: 0 B Total Size: 1.05 kB ℹ️ View Unchanged
|
Some quick microbenchmarks confirm that the B+ tree index is faster for inserts/updates/deletes and similar for range queries:
All operations were performed on an index containing 100K rows. |
Currently, we have an
OrderedIndex
that internally keeps an ordered array of indexed values. While this allows for efficient range queries, it introduces significant overhead on inserts and deletes because inserting/deleting in the array is in linear time.This PR introduces a
BTreeIndex
which internally keeps a B+ tree of indexed values. This still allows for efficient range queries but also makes insertions/deletions efficient (logarithmic time). I think it makes theOrderedIndex
completely obsolete and we should remove it in favor ofBTreeIndex
.Note that the B+ tree is only needed for range queries but some collections might never use range queries. So it would be good to introduce also a
HashIndex
in a follow up PR which only keeps a map of indexed values to PKs. That will reduce bookkeeping overhead on inserts/deletes further from logarithmic to constant time.