one table for comments only
id, caption, body, ...
one relationship table for storing the parent relation to the comment
comment_id (int), parent_id (int), parent_type (enum, set, or int BUT not varchar)
that you can easily tag a comment to multiple parents (if you want),
and can easily do an INNER JOIN
to get comments on the parent
another advantage
for example, if you want to get the most comments for all articles, questions, and posts,
in your method
you will need three INNER JOIN + GROUP BY,
with my suggestion, you only need one request
the most important thing,
relationship table can handle a huge number of records
because it stores an integer (smaller index)
source share