M
M
Max Ba2015-12-04 14:30:38
MySQL
Max Ba, 2015-12-04 14:30:38

What database structure to choose for the rating?

Hello. A voting system is being developed (for rating). The project is considered for the future. The bottom line: there are about 100 events and there will be (for example) 10,000 visitors. Each visitor can give a certain score to each event. From -100 to 100. (INT)
So the question itself is: have I chosen the right database structure and will there be unpleasant surprises in the future?
Voting table: `id`, `user`, `item`, `val`. InnoDB table type, columns are all INTEGER
`id` primary key.
`user` foreign key to the "users" table
`item` foreign key to the "events" table
`val` Voting value TINYINT. from -100 to 100.
Will all this work without failures, provided that there are about 1,000,000 lines?
Selection: SELECT * FROM `tab` WHERE `item` = 1000... and further into the array.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
skyfortress, 2015-12-04
@skyfortress

Everything seems to be correct, but 1,000,000 with your structure is quite a bit.

N
nelson, 2015-12-04
@nelson

The structure is normal. I speak as someone who uses the same on over 10 million lines of voices.
The only thing I would do is to make a request for a selection of votes not select * , but select user,val because we don’t need the id of his vote, and the item is the same for all rows. Well, I would still recalculate the rating of the event with each vote, and not when viewing the results (although this depends on what happens more often).
And to check whether a given user has spoken for a given event, a composite index on (user, item) will not hurt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question