开发者

Most Efficient Way to Get a Query of Posts based upon if a User Follows Them

Right now I have two tables for getting a timeline of posts that a user follows in MySQL, timeline and follows.

In the 'follows' table开发者_开发知识库, there is the 'follows.follow_From' column, the 'follows.follow_To' columns to show where the follows are from.

In the timeline table, there is a 'timeline.post_From' column containing the author's user ID of the post.

What is the most efficient method of selecting all posts from 'timeline' only where the current user has a "follow" in the 'follows' table? I am currently using a MySQL array, but I don't see it as efficient. Thank you for reading this and your help!


I'm not an expert and it might not be the most efficient but I'd guess:

  1. SELECT follow_To FROM follows WHERE follow_From = 'user-id'
  2. SELECT * FROM timeline WHERE timeline.post_From = (the results above)

e.g. SELECT * FROM timeline WHERE timeline.post_From IN (SELECT follow_To FROM follows WHERE follow_From = 'user-id')

Doing the other way round would definitely be slower because your processing more data then cutting it down. Cutting the data down first then look up is better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜