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:
Or highlighting the attribute, then checking the indexed box as seen here:
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With