I am building a comment system, where a comment can have many replies.
If I were to implement this in mysql, I would build a comments
table, and have the columns:
comment_id
,parent_comment_id
.
Where parent comment id is 0 for a comment, and is the parent comment id for a reply. So if I was looking for replies for a certain comment, I would look for comments that have parent_comment_id
to match the comment I am looking for.
This seems redundant to me as it will require me to go through the whole comments
table just to find whether a comment has replies or not (especially for large data), Where if I have a key-store database, I would have a key for the comment id, and inside it would be a list of the replies ordered by date.
So which approach do you think is better for this problem?
Also, I would like to generalize the problem to any one-to-many relationship to be stored as a list in a key-store database. And if you recommend using a key-store database, which one would you recommend for large data? ( I do not want to use redis for that since it is in-memory, and I doubt that replies for comments need to be access frequently).
Thanks for replies.
select main.*, child.* comments main join comments child on main.id = child.parent_id where main.id = 1;
– Leicester