Realm on iOS(swift): Best practices for using multiple indexes #7988
Unanswered
dmorgereth
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a collection that requires filtering on multiple fields (e.g. startDate + endDate + accountId). I have indexed each of these fields but am seeing a performance hit whenever I try to filter on more than one field. Is there a way to create a compound index in Swift (e.g. an index that includes multiple properties)? Are there any best practices for creating performant queries when filtering on multiple properties?
Here is an example of what I'm trying to do:
class Event: Object {
@persisted var id: String // Primary key
@persisted(indexed: true) var accountId: Int // Each account has its own events
@persisted(indexed: true) var startedAt: Date // Events can be filtered by date
@persisted(indexed: true) var eventType: String // Events can be filtered by type
@persisted var notes: String
}
For a collection with 20K objects, performance is acceptable as l filter on only startedAt and EndedAt. As soon as I add the filter for accountId, performance degrades drastically. The order of the filters doesn't seem to matter
Beta Was this translation helpful? Give feedback.
All reactions