I have a site like SO, WordPress, etc, where you make a post and u can have (optional) tags against it.
What is a common database schema to handle this? I’m assuming it’s a many<->many structure, with three tables.
Anyone have any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A three table many to many structure should be fine.
Eg.
Posts, PostsToTags(post_id,tag_id), TagsThe key is indexing. Make sure you PostsToTags table is indexed both ways (
post_id,tag_idandtag_id,post_id) also if read performance is ultra critical you could introduce an indexed view (which could give you post_name, tag_name)You will of course need indexes on Posts and Tags as well.