I have one table in which there would be millions of records. The requirement is to the records based on the condition and then total on one of the fields. Selectivity would be around approx 50.

Should I load 50 records in java and then filter and sum of on the field.

Or should I write an aggregate query and get the result.

This java processing can be scaled on multiple servers (Horizontal Scaling)

  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Dec 15 '18 at 11:30

If it's "just" 50 records, it won't matter much (unless your Java part is far away from the database and connected with a really low bandwidth).

But of course, for the general case, summing up values is something a database can do very well, so having the database do it will greatly reduce traffic and improve performance. And, thinking about transaction isolation, this way it's easier to get a consistent result.

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.