lundi 20 juillet 2015

Is it bad (performance) to get the sum from a database query instead of adding the results on Android?

I have an SQLite database in an Android app that stores basic transaction info (date, amount, category, comments). I know I can do a query to get all of the transactions of a specific category between two dates easily enough, but I want to add up the cost (stored as a real in SQLite) for each transaction of a particular category between two dates. I know there is a sum function in SQLite (thanks to this question), but the last answer in this other question makes me question the performance cost of doing so.

To my understanding, SQLite is written in native code, which is a win for mobile, where performance is key. So I've been told to do less in the java and let SQLite do what it does best in native code (and by native code I mean C / C++).

So in the case of Android, is it better to get a cursor to all the costs and loop through to get the total (in java code), or is it better to leave that lifting to SQLite? I'm just not sure what SQLite is optimized to do on Android.

Thanks!

Aucun commentaire:

Enregistrer un commentaire