私は2つのスキーマを使用しています。スケーラビリティの高いものを選択することはできません。スキーマはQ & A用で、MySQLで構築されています。人々は質問/回答と好き嫌い/好きな質問と回答を投稿します。質問には多くの回答/好き嫌いがありますので、答えがあります。 これらの2つのスキーマのどちらがスケーラビリティに優れていますか?
は、両方のスキーマが参加し、同じ数を必要とするユーザーに質問を読むには、しかし、異なる方法で処理された結合:スキーマ1
questions(id, title, body, userId)
questionLikes(id, questionId, userId)
questionDislikes(id, questionId, userId)
quetionComments(id, questionId, body, userId)
answers(id, questionId, body, userId)
answerLikes(id, answerId, userId)
answerDislikes(id, answerId, userId)
answerComments(id, answerId, userId, body)
favourites(id, questionId, userId)
これは、開発が容易に、より多くの正規化されているにのために、しかしスケーラブル?繰り返し情報がたくさんあるようです。質問をつかむためにシーケンスがユーザーにある参加(私たちは彼のような/嫌いの活動を含める)
select question
join answers
join questionLikes
join questionDislikes
join questionComments
join favouites
join answers to answerLikes
join answers to answerDislikes
join answers to answerComments (multiply answer joins by number of answers)
スキーマ2
posts(id, postTypeId, userId, title, body)
postTypeId(id, postType)
comments(id, postId, userId)
votes(id, voteTypeId, userId)
voteTypeId(id, voteType)
これは以下の正規化とコンパクトで、それのように思えます自己ジョイントやその他の開発問題(条件付き検証)を使用して首に痛みを改善します。質問を取り込むための結合シーケンスは
select question and its answers in the same read using where @id for question, and @questionId for answers; each row, join the following:
join votes on as likes on voteType 1
join votes as dislikes on votetype 2
join comments
join favouites (multiply joins by number of rows)
です。私は、カウントを格納するためのいくつかの追加のフィールドを追加できるので、結合は不要です。しかし、どちらも同じ数の結合を必要とし、私は私の心を構成しません。
私はあなたの質問を読むのは遠くに行っていませんでしたが、なぜquestionLikesとquestionDislikesの2つのテーブルがありますか?同じ発言をスキーマにさらに適用できると思います。 –
質問と回答は異なるオブジェクトであるため、同じIDを持つ可能性があります。 – Mohamad