SO やその他の質問応答システムは、高度な TSQL 手法の完璧な例だと思います。SO およびその他の質問/回答システムが DB テーブルでどのように機能するのか疑問に思っています。投票数と回答数も表示したい質問のリストのTSQL選択に特に興味があります。
テーブルquestion
は次のように指定されます
id int
title varchar
id_user int
votes
特定の質問に対するユーザーの投票を監視できるテーブル
id_user int
id_question int
vote int
質問への回答を含むテーブル「回答」
id int
id_parent int
次のような結果を得るには、次のように選択しますquestion
。
id int
title varchar
votes_count int
answers_count int
2つの方法を考えていました
- テーブル
question
は、投票または回答ごとに再計算され、テーブル フィールドが更新され、テーブル内votes_count
でanswers_count
直接更新されquestion
ます。つまり、テーブルquestion
にもvotes_count int, answers_count int
- 結合する選択を作成し、またはテーブルで
count
直接計算し、結果をテーブルに表示するだけです。投票と回答のすべてのレコードを選択するたびにカウントすると、どれくらいの速度が失われるでしょうか?votes
answers
question
ありがとう。