Welcome Guest, Not a member yet? Register   Sign In
Best way to count the number of rows
#1

[eluser]Cro_Crx[/eluser]
Hey everyone

I'm creating a web page application where users can submit answers to questions that are posted. At the moment i'm still in the development stages.

In my application I need to count the number of answers to each question. I'm using MySQL with the MyISAM storage engine (as users will be viewing records a lot more than writing to the datbase so i'm told MyISAM is a better choice).

I've denormalized the database by adding a total_answers in the questions table (so i don't have to count the number of answers for each question on every page load.

I was planning on using transactions to make sure that the count numbers were accurate so for example

Code:
Start transaction
Insert an answer
add 1 to the total_answers column in the questions table
stop transacation.

Although I've just realized that MyISAM doesn't actually support transactions, although apparently running count(*) statements are quick quite on MyISAM.

So my question is, would it be better to use InnoDB on all my database tables and use the total_column along with transactions to make sure they are accurate.

OR

Would it be best to just stick with MyISAM and use statements something like this:
Code:
SELECT Count(*) FROM 'answers' WHERE question_id = '5';

If you need some more information to be helpful just let me know... but yeah i'm unsure of which method to choose!


Messages In This Thread
Best way to count the number of rows - by El Forum - 04-24-2009, 01:24 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 05:26 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 05:35 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 05:49 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 05:54 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 06:02 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 06:21 AM
Best way to count the number of rows - by El Forum - 04-24-2009, 08:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB