user1096447
user1096447

Reputation: 429

Objective C. SQL Query or NSPREDICTATE

I have a what I deem a large database (500K records) My users would query the database fairly often. Would it be better (faster) to load all 500k worth of records into an array upon load and then use nspredicate on the array to get a subset of records when required or would be it better to just use an SQL query on the database to get the required records as and when needed?

Any advice much appreciated.

Upvotes: 0

Views: 90

Answers (1)

rmaddy
rmaddy

Reputation: 318774

Unless each record is only 100 bytes or less, you are not going to load all 500k records into memory. The whole point of a database is not needing to load all of the data in memory. Doing a SQL query is much better.

But keep in mind that running a SQL query in your SQLite database on an iOS device with that many records is going to take time. Make sure the query is done in the background and be prepared for it to take many seconds to complete.

Upvotes: 1

Related Questions