Is it better to make a large request to the database or several small ones?

Asked

Viewed 317 times

1

What is more recommended? I have a web system that on load of the ASPX page it feeds multiple controls with data from various tables of the database. It is better to do a search with a request (post) in each database table on the remote server or in a query only already return all data from all tables feeding a DataSet alone? That is, it is better to make more requests to the server and carry less data in the band or fewer requests and carry more data in the band?

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

4

We always say to these things that it depends, but in general to make a request that returns a large volume of data is better since the cost of each request in its various parts of transportation and processing is usually quite considerable. What is better to leave the living room and go in the kitchen to pick up one cookie at a time or bring the whole package?

But of course, if you bring a lot of stuff and you don’t need it, it doesn’t pay. There is a case that to decide what you will bring, you need to bring something earlier. It may be that in some cases the database system can do better with a smaller volume and optimize. And there are cases where you need to start showing some data to the user before receiving everything to give a better experience, even if the whole has a higher cost.Do you realize that there are cases that it is better to bring gradually? But this is more rare. Understand that there are a huge amount of things to observe to define what pays.

The worse the transport the easier it is to decide by a single request, in a remote network a request has a huge advantage.

That is why I always say that learning the cake recipe of what you should do is for nothing, what matters is to deeply understand the whole functioning of the technologies that are involved in what you do and make the decision according to need. Yeah, I know, everyone wants a magic rule that makes everything easy, but this doesn’t exist, and because many believe it exists, it’s because there’s so much bad software.

The question is ambiguous, well, transporting less data is always better, always! But you have to consider the whole operation not individual, it seems to me that you are talking about making a transaction with a volume of data or several others with little volume but adding up gives the same amount, so then it does not make sense for the additional cost, including volume of transport data because in each transport has a overhead.

  • I understood Maniero. Maybe I didn’t express myself in detail, but what I wanted to know, you already clarified. In case I need to bring a lot of data already on the page upload, because it needs to open with this information. And as these data came from several different tables, I was in doubt to make a request by table or already search everything in one request. in this case as this information is part of the page without user interaction and is not much, it is better in a request only. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.