Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a StackOverflow clone, is it acceptable for Questions and Answers to be separate tables?

Based on the StackOverflow data dump, it seems that S.O. represents questions and answers as a single table - Posts.

However, a question has a title, a body and tags associated with while an answer only has a body. To me, at least, this indicates that they are distinct enough that they should be separate tables.

Besides, I don't like having to write "and type='question'" in my SQL.

Are these valid reasons?

Or is there a good reason for putting questions and answers into the same table?

like image 567
Charlie K Avatar asked Jun 12 '09 05:06

Charlie K


2 Answers

Questions and answers have a lot in common -- author, date, comments, &c. Separating the table (since SQL schemas typically don't support inheritance) means a lot of duplication (the comments table will likely also have to be split, or have a goofy design with two foreign keys, one to the Q table and one to the A table, of which exactly one is to be non-NULL).

Yes, there are distinctions too between Q & A, and advantages the other 'way round, too, as you point out. "You pays your money, you takes your choices"!-)

like image 180
Alex Martelli Avatar answered Oct 17 '22 21:10

Alex Martelli


I would separate them on principle, just because they are different beasts. Question have titles (as you said), tags, favorite markers and (presumably) are subject to searches for attempted duplicate detection.

That would seem to me to make them different enough to warrant a separate table.

However, we don't know how SO stores them in the database, you've only seen the export into the data dump - it may be that the export functionality combines questions and answers into posts.

It may also be that the information common to questions and answers are stored in a single table and the question-specific extras stored in another table. Short of asking the SO developers, I can't think of any way to confirm this.

like image 30
paxdiablo Avatar answered Oct 17 '22 19:10

paxdiablo