Sorry for the vague question title, I'm not very experienced with db administration
Essentially I have a web application that allows polls to be created with any amount of options, then users can answer a poll and select their options and assign a priority to each answer (first choice, second choice, etc)
So there's a poll table, poll_options table, and a votes table. For each answer a user selects, a new row is added to the votes table
+------+---------+----------------+---------+----------+
| id | poll_id | poll_option_id | user_id | priority |
+------+---------+----------------+---------+----------+
| 1 | 7 | 4 | 16 | 1 |
| 2 | 7 | 1 | 20 | 1 |
| 3 | 7 | 3 | 20 | 2 |
| 4 | 8 | 1 | 16 | 1 |
| 5 | 8 | 2 | 16 | 2 |
| 6 | 8 | 3 | 16 | 3 |
| 7 | 8 | 4 | 16 | 4 |
| 8 | 8 | 3 | 2 | 1 |
| 9 | 8 | 1 | 2 | 2 |
+------+---------+----------------+---------+----------+
Now, assuming that table is acceptable, what comes to mind is that if there are 10 polls with 10 options each and 10 users, and they all vote for each thing on every poll... that's 1000 rows already - if I need to check if a user has voted in a poll already, I have to look up the current poll ID and user ID
SELECT COUNT(*) FROM votes WHERE user_id = 16 AND poll_id = 7
1
Is it bad design that it has to go through thousands of rows to find that? Would it be better to have a smaller table between the polls table and the votes, for checking if a user has voted in a poll, all the polls the user has voted in, etc.? Or would this have no performance benefit over my current design?
Would look something like this I guess
+------+---------+---------+
| id | poll_id | user_id |
+------+---------+---------+
| 1 | 7 | 16 |
| 2 | 7 | 20 |
| 3 | 8 | 16 |
| 4 | 8 | 2 |
Then I'd add the id from this new vote_item table to the votes table as a FK (?) so I can grab the vote_item id via the user_id and poll_id, and return all the rows in the votes table with that vote_item_id