一个大查询与许多小查询? [英] One big query vs. many small ones?

查看:175
本文介绍了一个大查询与许多小查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,在带宽和整体效率方面,哪个选项是最贵的。

I'd like to know, which option is the most expensive in terms of bandwith and overall efficiency.

假设我有一个类客户端在我的应用程序中,并且在我的数据库中有一个表客户端

Let's say I have a class Client in my application and a table client in my database.

更好地有一个静态函数 Client.getById ,它检索整个客户端记录或许多( Client.getNameById ,<$

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

如果单个记录有 lot

If a single record has a lot of fields and I end up using one or two in the current script, is it still better to retrieve everything and decide inside the application what to do with all the data?

我正在使用 PHP MySQL

推荐答案


有一个静态函数Client.getById检索整个客户端记录或检索单个字段的很多(Client.getNameById,Client.getMobileNumberById等)?

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

是的,它是。

网络延迟和延迟以及建立连接的开销意味着,可能是保持数据库饱和的最好方法。

Network latency and lag as well as the overheads of establishing a connection mean that making as small a number of database calls as possible is the best way to keep the database from saturation.

如果数据的大小真的太多,你看到一个效果,你可以考虑检索特定您需要在一个单一的查询(定制查询的数据)。

If the size of the data is really so much that you see an effect, you can consider retrieval of the specific fields you need in one single query (tailor the queries to the data).

这篇关于一个大查询与许多小查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆