在greenDao中添加索引列的正确方法?

Ral*_*ina 8 orm android greendao

我正在greenDAO中构建数据模型.它是使用Core Data的iOS应用程序的端口.在iOS中,我们使用索引(索引?)来增加20列(属性)表中的查找性能,其中经常查询5列.我知道这会导致额外的存储空间,并且会在表中提供更慢的写入速度

在文档中进行挖掘,我偶然发现在addIndex(指数指数)方法的实体和索引()方法Property.PropertyBuilder.向实体添加索引的正确方法是什么?

Entity entity = schema.addEntity("entity");
entity.setSuperclass("SuperClass");
entity.addIdProperty();
entity.addIntProperty("property").index();
Run Code Online (Sandbox Code Playgroud)

要么

Entity entity = schema.addEntity("entity");
entity.setSuperclass("SuperClass");
entity.addIdProperty();
Property property = entity.addIntProperty("property").getProperty();
entity.setIndex(property);
Run Code Online (Sandbox Code Playgroud)

或者他们都做同样的事情?

Mar*_*ger 18

myProperty.index()用于单个属性索引(因为它最方便).

对于更复杂的索引,例如多列索引,请使用addIndex(index):

Index index = new Index();
index.addProperty(property1);
index.addProperty(property2);
entity.addIndex(index);
Run Code Online (Sandbox Code Playgroud)