I am working on a Project in which i have Voting Options Up and Down similar to StackOverFlow. I am not much experienced in DB Designing and thus i got up with the following issue,
First of all, here is my table structure for voting :
- voteId—–AUTO_INCREMENT with PRIMARY KEY.
- mediaId—-The Media for which user gives an up/down vote.
- userId—–The User who Voted.
- voteMode—1 for Up Vote and 0 for Down Vote. This is an Integer Field.
In this case if i have 100 users and 100 medias, then i will have 100×100 records all total in this table.
The Problem arises here is the DB is getting up with a lot of records and the vote button is dead slow to react now. This is making my client unhappy and me in trouble.
Can anyone suggest me a better model to avoid this Huge Table?
I am using jQuery.ajax to post my vote to server. Also, the project is based on PHP and Zend Framework 1.11. So when i click on UP Icon, it will take some time to respond. Mozilla used to Crash certain times. I tested with inserting via a loop with lots of junk records (around 15000).
You can try these up gradation of your table schema:
Go through Mysql Index to know more about indexing.
If you are using MyISAM Storage Engine , then i will suggest you to go for InnoDB Storage Engine. It may help you to decide about which engine you should use.
And some other hacks that may help you are:
Some resources about MySql Database optimizations :