mysql> desc posts_posts;
+------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| body | text | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| is_deleted | tinyint(1) | NO | | 0 | |
+------------+------------+------+-----+---------+----------------+
6 rows in set (0.06 sec)
mysql> desc posts_personas_assc;
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| post_id | int(11) | NO | MUL | NULL | |
| persona_id | int(11) | NO | MUL | NULL | |
+------------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
基本上,用户创建帖子。每个帖子都可以附加“角色”。换句话说,这是一种多对多的关系。 (这里没有显示另一个人物表)
假设我有<000>个文件左右。我想运行此查询:
SELECT pp.id FROM posts_posts pp
INNER JOIN posts_persona_assc ppa ON pp.id = ppa.post_id
WHERE ppa.persona_id IN(id1, id2, id3)
AND start_time > pp.created_at
ORDER BY created_at DESC LIMIT num;
运行此查询对我来说是否足够高效?它会足够快吗?
每次有人点击用户个人资料页面时都会运行此查询。