Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use @Index with Realm?

Tags:

android

realm

I have max. 600000 Realm objects in my database. I make queries by id(int)=, uuid=, and time(int)<= and the results is ordered by time. Should I use the @Index annotation for some of the fields and maybe change the id from Integer to String? Are the queries going to be slow because I cannot index the time field and cannot have a multiple field index? Would Sqlite better suit my need?

Also, if I'm storing a large number of objects to the database at once, should I use one transaction for all objects or create a new transaction for each objects? How much memory will a large transaction consume and is there a performance hit when creating a new transaction for each object?

The database will be in external storage (memory card) of the Android device.

like image 314
Tapani Avatar asked Apr 23 '15 16:04

Tapani


1 Answers

You should definitely use @Index on any field that you use in any query.

It greatly improves performance / query speed.

like image 193
EpicPandaForce Avatar answered Oct 03 '22 12:10

EpicPandaForce