MARK
MARK

Reputation: 2362

sqlite insert vs update vs replace

I am a working on a project in which I retrieve data from facebook about friends of the user. Friends details vary some times while at the other times they are the same as the one stored in the db.

I can use the replace command to make sure that the db is consistent with whatever information I retrieve from the facebook.

My question is how efficient this technique will be? In other words, I can use two techniques:

Which of these approaches is going to be more efficient?

Upvotes: 0

Views: 700

Answers (1)

HalR
HalR

Reputation: 11083

I've found that queuing up a number of sqlite commands in a row is much more efficient than is doing anything else in between, even just comparing a few values.

I'd strongly recommend that you just do an update command. SQLite is fast.

My observation is that SQLite is always way faster than I am. So let it do the heavy lifting and just dump the data at it, and let it sort out your updates.

For example, I was searching through about 7,000 records. I pulled the records out into an array, did a quick check for one field, and separated it into two arrays. This was taking me about 5 seconds. I replaced it with two separate SQLite queries that each had to go through the entire data base. The revised dual query takes about a quarter second, near as I can tell, because its so crazy fast.

I've had similar speed luck with Updates in my big database.

Upvotes: 3

Related Questions