Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData. What's the difference between indexes and indexed?

I'm looking to speed up queries to my SQL backed CoreData instance (displaying records sorted by date). I know that indexing can help decrease query time, but what's the difference between:

Highlighting the entity that an attribute belongs to, then adding a comma separated list of attributes into the indexes field as seen here:

enter image description here

Or highlighting the attribute, then checking the indexed box as seen here:

enter image description here

like image 533
VaporwareWolf Avatar asked Mar 10 '16 03:03

VaporwareWolf


People also ask

What is Coredata in iOS?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

How do I use Coredata?

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.

Is core data a database?

Core Data is not a database. Core Data is a framework for managing an object graph. An object graph is nothing more than a collection of interconnected objects. The framework excels at managing complex object graphs.

What is core graph object in Swift?

It is a framework that you use to manage the object graph and persist that object graph. Core Data is not a relational database. It is actually a framework that lets developers store (or retrieve) data from a database in an object-oriented way.


1 Answers

Adding a row with a single attribute to the Indexes list is equivalent to selecting Indexed for that attribute: It creates an index for the attribute to speed up searches in query statements.

The Indexes list is meant for compound indexes. Compound indexes are useful when you know that you will be searching for values of these attributes combined in the WHERE clause of a query:

SELECT * FROM customer WHERE surname = "Doe" AND firstname = "Joe";

This statement could make use of a compound index surname, firstname. That index would also be useful if you just search for surname, but not if you only search for firstname. Think of the index as if it were a phone book: It is sorted by surname first, then by first name. So the order of attributes is important.

In your case you should go for the single indexes first (that is, select Indexed for the attributes you like to search for). The compound index you showed could never be used if you just search for babyId, for example.

like image 79
Dirk Avatar answered Oct 13 '22 10:10

Dirk