在MySQL中执行左连接与缓存数据的成本
因此,我有一个包含以下MySQL表的项目: 内容表在MySQL中执行左连接与缓存数据的成本,mysql,caching,redis,Mysql,Caching,Redis,因此,我有一个包含以下MySQL表的项目: 内容表 +------------+------------+ | content_id | some infos | +------------+------------+ | 1 | ... | | 2 | ... | +------------+------------+ +----+----------+---------+------------+--------------+
+------------+------------+
| content_id | some infos |
+------------+------------+
| 1 | ... |
| 2 | ... |
+------------+------------+
+----+----------+---------+------------+--------------+
| id | title | user_id | content_id | other things |
+----+----------+---------+------------+--------------+
| 1 | "blabla" | 1 | 1 | ... |
| 2 | "blabla" | 59 | 25 | ... |
+----+----------+---------+------------+--------------+
标题表
+------------+------------+
| content_id | some infos |
+------------+------------+
| 1 | ... |
| 2 | ... |
+------------+------------+
+----+----------+---------+------------+--------------+
| id | title | user_id | content_id | other things |
+----+----------+---------+------------+--------------+
| 1 | "blabla" | 1 | 1 | ... |
| 2 | "blabla" | 59 | 25 | ... |
+----+----------+---------+------------+--------------+
为了快速恢复系统,多个用户为内容提供一个标题。但是每次我选择一个内容时,我都需要找到合适的标题(我选择了最受关注的用户,他们已经为这个内容发布了一个标题)
因此,为了做到这一点,我看到了两种解决方案:
- 我可以在content表上进行选择,并在title表和我的user表上进行左连接,其中包含一些MAX(nb_订户)
- 我可以只在内容上进行选择,然后使用像Redis这样的缓存系统将标题缓存大约1天(在这种情况下,如果找不到标题,则需要调用新的MySQL)
主要问题是这些内容会被加载很多次,我想知道你的建议,如果左连接方法需要很多时间来处理。我认为在
内容
和标题
表之间进行左连接
没有什么错,假设后者在内容
列上有索引:
SELECT c.*, t.*
FROM content c
LEFT JOIN title t
ON c.content_id = t.content_id
-- can also join to user table if needed