6

What would be better in terms of memory efficiency or would have the best overall performance on Android and SQLite, getting a record count with cursor.getCount() or to execute a rawQuery with a COUNT on a normal SQL clause (and use cursor.getInt(0) later to get the count returned)?

Note: I'm not using the results, I just want the count.

1 Answer 1

6

If you are using the result of the query afterwards, then of course the best way would be to do cursor.getCount() This is faster than doing 2 queries one to get the count and one for the result

EDIT :

If you are not using the results, then a rawQuery is faster because you are gettting only one column from the database instead of many. Plus why would you waste resources to execute a query and not use its result?

2
  • Oh, no. I forgot to say that I'm not using the results, in this case I'm just interested on the count itself. I'll fix my question. Dec 21, 2011 at 16:11
  • Ok, thanks. The reason I just want the count is that I'm displaying the user's related records as a badge over a customized Tab on the App. Think about the badge on the Email Apps icons. So I'm getting count of favorites, or other records related to the current logged in user and I do not need the records, just the count. Dec 21, 2011 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.