erquhart
erquhart2y ago

Upper and lower bounds support for multiple fields

I've run into a few situations where I need an index that has upper/lower boundaries using more than one field. Curious if this is on the radar.
7 Replies
jamwt
jamwt2y ago
@erquhart convex should support all the same strategies as other index systems. can you given an example? does chaining like this example (https://docs.convex.dev/database/indexes/#querying-documents-using-indexes ) not work out?
Indexes | Convex Developer Hub
Indexes are a data structure that allow you to speed up your
jamwt
jamwt2y ago
@erquhart ah, I think I understand what you mean. in that case, due to the way the index is structured, the secondary field has to be just an in-memory filter or a second query with .eq on the primary field and then your range on the secondary field for each matching record in the range on the primary field
erquhart
erquhartOP2y ago
Yeah that was my understanding. I was curious whether this is an inherent limitation or if multiple field boundaries could be supported in the future.
jamwt
jamwt2y ago
inheritent limitation b/c those values are not actually adjacent in the index in other words, there are "gaps" between the secondary field ranges, if you follow. imaging there's a kind of tree providing these fast lookups
erquhart
erquhartOP2y ago
Ah okay, gotcha
jamwt
jamwt2y ago
now it's possible to provide a kind of "macro" layer which automatically does the subfetches for each matching record in the primary range, but we don't have that layer yet. it could be written as a kind of paginated helper, but would probably take a bit of thought (this is what a SQL query planner might do for you, create a plan for all those dependent index lookups)
erquhart
erquhartOP2y ago
yeah pagination was the next thing I was going to reach for

Did you find this page helpful?