什么是Xcode Core-Data数据模型检查器中的索引 [英] What are Indexes in the Xcode Core-Data data model inspector

查看:251
本文介绍了什么是Xcode Core-Data数据模型检查器中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode中,您可以为数据模型检查器中的实体添加索引。

In Xcode you can add "Indexes" for an entity in the data model inspector.

对于截图我点击添加两次,所以逗号,分隔,属性只是默认值。

For the screenshot I did hit "add" twice so "comma,separated,properties" is just the default value.

这些索引究竟是什么?

它们与索引属性有什么关系吗?如果他们在这个检查器中指定索引和为个别属性选择索引之间有什么区别?

What exactly are those indexes?
Do they have anything to do with indexed attributes? And if they have what is the difference between specifying the Indexes in this inspector and selecting "Indexed" for the individual attribute?

推荐答案

优化核心数据搜索和排序

如标题所示,索引是加快搜索和排序数据库。但是,它会减慢保存更改到持久存储。当您在查询中使用 NSPredicates NSSortDescriptor 对象时,这很重要。

As the title says, indexing is to speed up searching and sorting your database. However it slows down saving changes to persistant store. It matters when you are using NSPredicates and NSSortDescriptor objects within your query.

我们假设你有两个实体: PBOUser PBOLocation / em>。您可以在下面的图片中查看其属性:

Let's say you have two entities: PBOUser and PBOLocation (many to many). You can see its properties at the image below:

假设在数据库中有10 000个用户和5万个位置。现在,我们需要找到每个用户的电子邮件从 a 开始。如果我们提供这种无索引的查询,Core Data必须检查每个记录(基本上10 000)

Suppose that in database there is 10 000 users, and 50 000 locations. Now we need to find every user with email starting on a. If we provide such query without indexing, Core Data must check every record (basically 10 000).

但是如果已编入索引(如果按电子邮件降序排列) - >然后CoreData只检查以 a 开头的记录。如果Core Data达到 b ,则停止搜索,因为显然没有更多以 a 开头的电子邮件已编入索引。

如何操作?

But what if it is indexed (in the other words sorted by email descending)? --> Then CoreData checks only those records started with a. If Core Data reach b then stop searching, because it is obvious that there is no more email starting with a since it is indexed.
How to do that?



或:


or:

希望它们是等效的: - )

Hopefully they are equivalent:-)

但是如果您愿意:电子邮件以 a 开头,名称以 b 开头您可以做这个检查INDEXED为实体的属性属性,或:

But what if you wish: Emails started with a and name starts with b You can do this checking INDEXED for name property for PBOUser entity, or:

>

是如何优化您的数据库:-)

This is how you can optimise your database:-)

这篇关于什么是Xcode Core-Data数据模型检查器中的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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