表A储存帖子,主键`ID`,字段`LAST_REPLIES`,字段`CONTENT`(`LAST_REPLIES`存储最近20条回复)
表B储存回复,主键`ID`,降序索引(`PARENT`,`TIME`),字段`CONTENT`(`PARENT`是被回复帖的ID)
LAST_REPLIES
,一共600个,然后SELECT * FROM `B` WHERE `ID` IN (####一共六百条ID####)
THREAD_ID
,一共30个,然后SELECT * FROM `B` WHERE `PARENT` = :ID01 ORDER BY `TIME` DESC LIMIT 0,20
UNION ALL
SELECT * FROM `B` WHERE `PARENT` = :ID02 ORDER BY `TIME` DESC LIMIT 0,20
UNION ALL
SELECT * FROM `B` WHERE `PARENT` = :ID03 ORDER BY `TIME` DESC LIMIT 0,20
UNION ALL
...... ......
SELECT * FROM `B` WHERE `PARENT` = :ID30 ORDER BY `TIME` DESC LIMIT 0,20
THREAD_ID
,语句是 [注意降序索引(PARENT
,TIME
)]SET @NUM := 0, @PARENT := 0;
SELECT * ,
@NUM := if(@PARENT = `PARENT`, @NUM + 1, 1) as "COUNT",
@PARENT = `PARENT` AS "DUMMY"
FROM `B` FORCE INDEX(`PARENT`)
GROUP BY `PARENT`
HAVING @NUM <= 20
WHERE `PARENT` IN (####一共三十条ID####)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.