返回一个大查询还是几个小查询更好? [英] Is it better to return one big query or a few smaller ones?

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

问题描述

我正在使用MySQL存储视频游戏数据.我有用于标题,平台,标签,徽章,评论,开发人员,发布者等的表...

I'm using MySQL to store video game data. I have tables for titles, platforms, tags, badges, reviews, developers, publishers, etc...

当某人正在观看游戏时,最好是使用一个查询返回与游戏相关的所有数据,还是最好使用多个查询?直观地,由于我们具有评论,因此将它们包括在同一查询中似乎毫无意义,因为需要对它们进行分页.但是在其他情况下,我不确定是否要分解查询或使用两个查询...

When someone is viewing a game, is it best to have have one query that returns all the data associated with a game, or is it better to use several queries? Intuitively, since we have reviews, it seems pointless to include them in the same query since they'll need to be paginated. But there are other situations where I'm unsure if to break the query down or use two queries...

我有点担心性能,因为我现在加入游戏下表:开发人员,发行者,元标记,徽章,标题,类型,子类型,分类...,以获取游戏徽章(来自games_badges;对游戏表进行多对多,对徽章表进行多对多)我可以做另一个联接,也可以运行一个单独的查询....我不确定什么是最好的....

I'm a bit worried about performance since I'm now joining to games the following tables: developers, publishers, metatags, badges, titles, genres, subgenres, classifications... to grab game badges, (from games_badges; many-to-many to games table, and many to many to badges table) I can either do another join, or run a separate query.... and I'm unsure what is best....

推荐答案

没有万能药.

  1. 始终尝试仅获取必要的数据.
  2. 一个大查询还是几个小查询更好是没有答案的.每种情况都是唯一的,要回答这个问题,您应该分析应用程序并检查查询的EXPLAIN s
  1. Always try to get only necessary data.
  2. There is no answer whether one big or several small queries is better. Each case is unique and to answer this question you should profile your application and examine queries' EXPLAINs

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

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