One big request against many small ones?

I would like to know which option is the most expensive in terms of bandwidth and overall efficiency.

Say I have a Client class in my application and a Client table in my database.

Is it better to have one static function Client.getById that retrieves the entire client record or many ( Client.getNameById , Client.getMobileNumberById , etc.) that retrieve individual fields?

If there are many fields in one record, and I end up using one or two in the current script, it's still better to get everything and decide inside the application, what should I do with all the data?

I am using PHP and MySQL by the way.

+6
source share
1 answer

Is it better to have one static function Client.getById that retrieves the entire client record or many (Client.getNameById, Client.getMobileNumberById, etc.) that retrieve individual fields?

Yes it is.

Network latency and lag, as well as the overhead of establishing a connection, mean that creating as many database queries as possible is the best way to preserve database saturation.

If the data size is really so large that you see the effect, you might consider looking for specific fields in a single query (taking into account data queries).

+12
source

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


All Articles