正确方法greenDao添加索引列?索引、正确、方法、greenDao

2023-09-05 03:37:58 作者:是梦必会醒

我建立在greenDAO的数据模型。这是一个iOS的应用程序,使用核心数据的端口。在IOS我们使用索引(索引?),以增加在20列(属性),其中5列经常查询的一个表查找性能。我知道,这将导致额外的存储空间,并提供速度较慢写入到表中。

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.

挖掘的文档中,我在Entity和在Property.PropertyBuilder.这是一个索引添加到实体?

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();

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?

推荐答案

使用 myProperty.index()作为单一的性能指标(因为它是最方便的)。

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

对于更复杂的指标,如多列索引,使用addIndex(指数):

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

Index index = new Index();
index.addProperty(property1);
index.addProperty(property2);
entity.addIndex(index);