Question

Is it better to make two database calls or one database call with some java processing?

One database call gets only the relevant data which is to be separated into two different list which requires few lines of java.

Was it helpful?

Solution

Database dips are always an expensive operation. If you can manage with one db fetch and do some java processing, it should be a better and faster choice for you.

But you may have to analyze in your scenarion, which one is turning to be a more efficent choice. I assume singly DB fetch and java processing should be better.

OTHER TIPS

Testing is key. Some questions you may want to ask yourself:

  • How big is each database call
  • How much bigger/smaller would the calls be if I combined them
  • Should I push the procesing to the client?
  • Timing
    • How time critical is processing?
    • Do you need to swarm the DB or is it okay to piggy back on the client?
    • Is the difference negligible?

Java Processing is much faster than SQL Fetch, As I had the same problem so I recommend you to fetch single data with some processing, because maybe the time both options take has a minor difference but some Computers take a lot of time to fetch data from DB so I suggest you to just Get single data with some Java Processing.

Generally Javaprocessing is better if its not some simple DB query that you are doing.

I Would recomend you for trying them both, measure some time and load and see what fits your application the best.

It all depends on how intensive your processing is and how your database is setup. For instance an Oracle running on a native file system will most likely be more performant then doing the java processing code on your own for complex operations. Note that most build in operations on well known databases are highly optimized and usually very performant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top