Get counter using cursor.getCount () or do rawQuery using COUNT in SQL statement?

Which would be better in terms of memory efficiency, or would have better overall performance for Android and SQLite, getting a record counter using cursor.getCount () or to execute rawQuery with COUNT in a regular SQL statement (and use cursor.getInt (0) later to return the counter?)

Note. I do not use the results, I just want to count.

+6
source share
1 answer

If you subsequently use the result of the query, then of course the best way would be to do cursor.getCount() This is faster than executing 2 queries to get a counter and one for the result

EDIT:

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

+5
source

Source: https://habr.com/ru/post/904255/


All Articles