How does SO calculates number of votes, answers and views in database?
===

I think SO and other question/answer systems are perfect example for advanced TSQL techniques. I am wondering how SO and other questions/answers systems work with DB tables. I am particulary interested what is the TSQL select for list of questions where you also want to show number of votes and answers. 

Table `question` would be specified as this

    id       int 
    title    varchar
    id_user  int

table `votes` so you can monitor users votes for particular question

    id_user       int
    id_question   int
    vote          int

table 'answer' with replies to question

    id           int
    id_parent    int

What would select look like to get result from `question` like this:

    id                 int
    title              varchar
    votes_count        int
    answers_count      int

I was thinking about two methods

1. Table `question` would recalculate with every vote or answer and update table fields `votes_count` and `answers_count` directly in `question` table. That means table `question` would have also `votes_count int, answers_count int`
2. Create select which would join, calculate `count` directly in `votes` or `answers` tables and just show results in `question` table. How much speed would be lost by counting with every select all the records for votes and answers?

Thanks.