如何改进这个嵌套的选择语句,因为我认为它的性能很差,因为我认为它需要很长时间才能执行并且服务器负载很高
SELECT user_tagtag,
user_lastcontentid,
(SELECT COUNT( content_id )
FROM contents
WHERE contents.content_id > user_lastcontentid AND
contents.content_id IN (
SELECT contenttag_contentid
FROM contents_vs_tags
WHERE contenttag_tagtag = user_tagtag
)
) AS tag_newnews_no
FROM users_interests_tags
WHERE user_userid = 1
ORDER BY user_tagsorder ASC
users_interests_tags 表结构为:
+--------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+-------+
| user_userid | bigint(20) | NO | PRI | NULL | |
| user_tagtag | varchar(255) | NO | PRI | NULL | |
| user_lastcontentid | bigint(20) | YES | MUL | NULL | |
+--------------------+--------------+------+-----+---------+-------+
内容表结构为:
+---------------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+----------------+------+-----+---------+----------------+
| content_id | bigint(20) | NO | PRI | NULL | auto_increment |
| content_title | varchar(255) | NO | MUL | NULL | |
+---------------------+----------------+------+-----+---------+----------------+
contents_vs_tags 表结构为:
+----------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+-------+
| contenttag_contentid | bigint(20) | NO | PRI | NULL | |
| contenttag_tagtag | varchar(255) | NO | PRI | NULL | |
+----------------------+--------------+------+-----+---------+-------+
contents_vs_tags.contenttag_contentid
content.content_id的索引和外键在哪里
任何帮助将非常感激。