8

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

在文档中挖掘,我遇到了Entity中的 addIndex(Index index) 方法和Property.PropertyBuilder中的 index() 方法。向实体添加索引的正确方法是什么?

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

或者

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

还是他们都做同样的事情?

4

1 回答 1

18

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

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

Index index = new Index();
index.addProperty(property1);
index.addProperty(property2);
entity.addIndex(index);
于 2013-03-04T18:18:33.883 回答