As originally requested on Twitter https://twitter.com/maciejtrybilo/status/619168172076363776
This feature would be great. We have a database containing coordinates (latitude/longitude) and need to query for coordinate regions, e.g. latitude between 10 and 11 and longitude between 45 and 46. Indexing the coordinates would speed up these queries.
@florianreinhart indexing actually wouldn't speed up comparison queries, as realm currently only uses indices for exact equality queries.
Based on documentation I guess that integer means 32 bit int
We have 64bit integers as keys in our server side db and would like to generate realm db with that.
Would it be indexed in realm ?
Realm supports 64-bit integers. All supported integer types can be indexed.
Thank you !
@segiddins
@florianreinhart indexing actually wouldn't speed up comparison queries, as realm currently only uses indices for exact equality queries.
Is this still true? Is indexing useful only for equality? And not for comparison!?
Yes, that's still true.
Are there plans to support the following?
1) floating point indexing
2) comparison and indexing
I'm a bit confused about how I should be using indexes properly in Realm. I have a feeling I may be abusing them.
So creating an index on a property that is used for a sort will not provide any real benefit? What about an IN filter?
https://realm.io/docs/swift/latest/#indexing-properties
Indexing properties
To index a property, override Object.indexedProperties(). Like primary keys, indexes make writes slightly slower, but makes queries using comparison operators faster. (It also makes your Realm file slightly larger, to store the index.) It鈥檚 best to only add indexes when you鈥檙e optimizing the read performance for specific situations.
Reading that makes it sound like comparison is supported. I want to make sure i'm not conflating best practices in traditional RDBMS for best practicing in realm. I got here because i need to sort a collection on score of type float or double and I just realized it's not supported. Basically any property involved in a filter or sort i have been indexing, am I adding unnecessary overhead?
IN queries use the index. Sorting still does not.
That bit of the docs is badly worded and really should say "using equality operators".
got it, thanks just wanted to confirm
Most helpful comment
This feature would be great. We have a database containing coordinates (latitude/longitude) and need to query for coordinate regions, e.g. latitude between 10 and 11 and longitude between 45 and 46. Indexing the coordinates would speed up these queries.