正确方法greenDao添加索引列? [英] Proper way to add index columns in greenDao?

查看:5186
本文介绍了正确方法greenDao添加索引列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立在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.

挖掘的文档中,我在<一个碰到的addIndex(指数指数)的方法href="http://greendao-orm.com/javadoc/greendao-generator/index.html?de/greenrobot/daogenerator/Entity.html">Entity和在<一个的索引()方法href="http://greendao-orm.com/javadoc/greendao-generator/de/greenrobot/daogenerator/Property.PropertyBuilder.html">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);

这篇关于正确方法greenDao添加索引列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆