Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to add index columns in greenDao?

I am building a data model in greenDAO. It is a port of an iOS app that uses Core Data. In iOS we use indexes (indices?) to increase lookup performance in a table of 20 columns (properties) where 5 columns are frequently queried. I know this results in extra storage and provides slower writes into the table.

Digging in the documentation, I came across the addIndex(Index index) method in Entity and the index() method in Property.PropertyBuilder. Which is the correct way to add an index to an Entity?

Entity entity = schema.addEntity("entity");
entity.setSuperclass("SuperClass");
entity.addIdProperty();
entity.addIntProperty("property").index();

or

Entity entity = schema.addEntity("entity");
entity.setSuperclass("SuperClass");
entity.addIdProperty();
Property property = entity.addIntProperty("property").getProperty();
entity.setIndex(property);

Or do they both do the same thing?

like image 610
Ralph Pina Avatar asked Feb 28 '13 22:02

Ralph Pina


1 Answers

Use myProperty.index() for single property indexes (because it is most convenient).

For more complex indexes, like multi-column indexes, use addIndex(index):

Index index = new Index();
index.addProperty(property1);
index.addProperty(property2);
entity.addIndex(index);
like image 179
Markus Junginger Avatar answered Oct 18 '22 07:10

Markus Junginger