I have been learning Ruby on Rails in the last few months without any prior programming experience. Recently, I have been thinking about database optimization and table organization. I know there are great books on this subject, but I usually participate in this example / along the way.
Here's a hypothetical situation:
Let's say I'm creating a social network for a niche community with 250,000 members (users). Users can attend events. Say 50,000 past / present / future events. Like Facebook events, a user can attend any number of events, and an event can have any number of participants.
The database will have a table for users and an event table. Somehow I would have to create a connection between users and events. I could create an “events” column in the user table so that each user row contains a hash of event identifiers, or I could create a “visitors” column in the event table so that each event row contains a hash of user identifiers,
None of these solutions seem perfect. On the user profile page, I want to display a list of events with which they are associated, which will require scanning of 50,000 event lines for the user ID of the specified user if I include the "Participants" column in the event table. Similarly, on the events page, I want to display a list of participants for the event, which will require scanning 250,000 user lines for the event identifier of the specified event, if I include the "events" column in the users table.
Option 3 will be to create a third table containing the participant information for each event, but I don’t see how this can solve any problems.
? Rails , , . , // .. , 250 000 - 10 ? 100? 1,000ms? , . ?