What does the Indexed Property of a CoreData attribute do?

守給你的承諾、 提交于 2019-12-29 04:27:11

问题


I have a Core data model with a 32bit hash value. I need to look up specific hash values quickly. Should I use the indexed property? I have no idea what it does and the documentation is no help (am I looking in the wrong place?)

So what does indexed do exactly?


回答1:


I would recommend to read this on indexes: http://en.wikipedia.org/wiki/Index_(database). 

Simply put, a database engine creates a new structure which keeps the indexed column (which corresponds to a property) sorted and a link to the corresponding row for each entry (primary key). This allows for faster searches (since search in ordered lists is faster than in unordered lists). But this increases used storage (for the data structure), and insertion times (to keep the structure sorted).

So yes, you should use indexes in such cases.




回答2:


If you check the box, Core Data will build an index of the values, which will make searching faster and more efficient. It's like what Spotlight uses. Without the index it'll have to travel through the database every time. You say you need to look up the values quickly—then you should index them.



来源:https://stackoverflow.com/questions/7935348/what-does-the-indexed-property-of-a-coredata-attribute-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!