-1

I'm making a site where users can make posts and comments, where number of comments made by a single user could get over 1000 comments. On their profile, it would show a list of all comments (by latest, splitting them into pages with 20 comments per page) made by that user.

Considering the database used to store comments would get extremely large, I'm wondering what would be the best way to go about this, since people with more comments would likely be more popular and running a query searching for the user's id through a list of all comments would be the best way to go about it.

Was thinking an alternative could be making a separate column on the user database, which would store all comment ids, and whenever someone were to visit their page, it would go through the comments looking for those ids (limiting to 20 at a time or so).

Unsure which method would be faster, and if the second method is practical. Also if there's any other better method to go about it. First time doing something like this and would appreciate any guidance.

Alex
  • 91
  • 7
  • I don't think this case is as specific as not to go for the standard `users` table, `comments` table, and then `user_comments` table with id to user and comment, in a many to many fashion. – Óscar Gómez Alcañiz Jul 20 '16 at 07:40

1 Answers1

0

If you are using SQL 2012 new syntax was added to make this really easy. See Implement paging (skip / take) functionality with this query

Skip 20 * page depending on the page you're looking for.

jeanj
  • 2,106
  • 13
  • 22