To exemplify my situation, think of a Question & Answer platform like stackoverflow. Basically there are questions and answers tables. What is the best practice for displaying the number of answers of a specific question?
-
Should there be a “count column” in the
questionstable? Every time new answer is added or deleted “count column” should be updated. -
Or just do count the rows of the answers using MySQL in the
answerstable? My concern in this option is the load to database but I am not sure.
I would not worry about load on the database unless you actually find it to be a problem. In fact, the option of keeping a count requires an additional update on every CRUD operation, so I would think that would be more overhead than an occasional count. Go with KISS first, and if you find a problem, then fix it 🙂