Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Indexed Property of a CoreData attribute do?

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?

model

enter image description here

like image 807
Robert Avatar asked Oct 28 '11 21:10

Robert


People also ask

How do I get Data from Core Data?

Fetching Data From CoreData We have created a function fetch() whose return type is array of College(Entity). For fetching the data we just write context. fetch and pass fetchRequest that will generate an exception so we handle it by writing try catch, so we fetched our all the data from CoreData.

How do I use Core Data?

Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.

Does SQL use Core Data?

Even though Core Data knows how to use a SQLite database as its persistent store, that doesn't mean you can hand it any SQLite database. The database schema of the SQLite database used by Core Data is an implementation detail of the framework. It isn't publicly documented and liable to change.

What is a fetch index?

Fetch Index Elements are part of Apple's new indexing API, announced at WWDC 2017. They allow you to specify one or more Index Elements; properties that are used to create an index for faster database searches.


2 Answers

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.

like image 166
Stanislav Yaglo Avatar answered Oct 17 '22 17:10

Stanislav Yaglo


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.

like image 21
FeifanZ Avatar answered Oct 17 '22 18:10

FeifanZ