views:

47

answers:

2

As an answer to a question I asked yesterday (http://stackoverflow.com/questions/3293832/new-core-data-entity-identical-to-existing-one-separate-entity-or-other-solution), someone recommended I index an attribute.

After much searching on Google for what an 'index' is in SQLite/Core Data, I'm afraid I'm not closer to knowing exactly what it is or how it speeds up fetching based on an attribute. Keep in mind I know nothing about SQLite/databases in general other than a vague idea based on reading way, way, way, too much about Core Data the past few months.

+2  A: 

Simplistically, indexing is a kind of presorting. If you have a numerical attribute index, the store maintains linked list in numerical order. If you have a text attribute, it maintains a linked list in alphabetical order. Depending on the algorithm, it can maintain other kinds of information about the attributes as well. It stores the data in the index attached to the persistent store file.

It makes fetches based on the indexed attribute go faster with the tradeoff of larger file size and slightly slower inserts.

TechZen
+1  A: 

Wikipedia has a great explanation of a database index:

"A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of slower writes and increased storage space."

Gerald Kaszuba