是否真的考虑了每个页面加载20个SQL查询? [英] Is 20 SQL Queries per page load really considered a lot?

查看:66
本文介绍了是否真的考虑了每个页面加载20个SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看到WordPress,CPU的破坏者上阅读了Jeff Atwood的博客.看到那里的很多人认为每页加载20个SQL查询很多.对于具有自动建议,自动刷新数据,自定义页面和厨房水槽的高度动态页面,如今每页平均查询量是多少?

I was reading Jeff Atwood's blog on Behold WordPress, Destroyer of CPUs and saw that many people there considered 20 SQL Queries per page load to be a lot. What is the average amount of queries per page nowadays for a highly dynamic page with auto suggest, auto refreshing of data, customized pages, and the kitchen sink?

举一个简单的例子,A​​mazon.com实际上使用他们认为会购买的东西自定义我的主页.对我来说,这看起来并不对首页使用5个或更少的查询.

For a simple example, Amazon.com practically customizes my homepage with stuff they think I will buy. To me, that doesn't look it just uses 5 or less queries for the front page.

我仍然是数据库的新手,所以请告诉我是否缺少明显的内容.

I'm still a newbie with databases so please tell me if I'm missing something obvious.

推荐答案

通常,您可以将所有数据放在两个或三个大查询中,而不是放在二十个小查询中.最小化查询数量与编写最佳查询以最大化性能一样重要,即使不是最重要.

You can usually bring all the data in two or three big queries instead of on twenty small ones. Minimizing the amount of queries is as important as, if not most important than, writing optimal queries to maximize performace.

当然,您应该始终分析查询计划,并针对最佳查询(无论大小)进行优化.

Of course you should always analyze the query plans and aim towards optimal queries, be them small or big.

问题是设计不当的网页会执行很多查询,每个微小的任务只能执行一个查询,而这些查询可以很容易地组合到一个查询中.

The thing is that badly designed webpages do many queries, one per each tiny little task, which could easily be grouped in a single query.

例如,设计欠佳的stackoverflow 可能会执行查询以获取将显示在主页上的所有问题ID,然后对每个问题进行一次查询以获取摘要和投票.然后,您很容易就有20个无用的查询.一个设计精良的查询将执行单个查询,以获取有关将显示的所有问题的所有信息.

For example, a badly designed stackoverflow could do a query to get all the question ids it will show on the main page, then do one query per each question to get the summary and the votes. Then you have easily 20 useless queries. A well designed will do a single query getting all the information about all the questions it'll display.

当然,通过良好的缓存可以降低所有这些因素的影响,而这正是所有大型网站所做的事情,这样,您实际上可以执行很多查询,而且仍然可以得到不错的性能.

Of course the impact of this all is reduced with good caching, which is what all big sites do, that way you actually can do a lot of queries and still get decent performance.

这篇关于是否真的考虑了每个页面加载20个SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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