Well im working on an online game project where every player will get to have a house, the project was going great until u had to organize houses thinking that i will have a limit of 10.000 players on the server.
so here are some facts:
each player may have up to 10 houses (min 1).
that means i need 100.000 possible houses so that no matter how full the server gets, there will always be 10 possible houses for each player.
there will be 20 cities, each city will have 200 neighborhoods, and each neighborhood will have 25 houses
so thats when the problem shows up, how would the database work?
whenever i want to see any of the 100.000 houses, it will belong to a neighborhood on a city, and i need to be able to play with that, like if i want to see house #5 of the neighborhood #123 city#8, then i should be able to get the data.
i was thinking about having one table with all 100.000 houses, and having values on that table to tell what neighborhood it is on what city, but it feels like there must be a better way. (maybe using multiple tables? i dont know)
so any help would be appreciated.
thank you for your time.
It’s hard to answer, because your complete requirements aren’t known.
But I’d recommend that you normalize the database – 3rd normal form at minimum. If you don’t know what that is, I’d recommend learning about it ASAP.
My best guess is as follows:
You’ll do JOINS to associate a PLAYER with cities, neighborhoods, and houses. You should have surrogate primary keys on all tables and appropriate foreign keys. Add UNIQUE indexes on all other candidate key combinations.
Run EXPLAIN PLAN on all your queries to make sure that they don’t require TABLE SCAN and perform adequately.
10,000 players isn’t a big number for a database. You won’t have any problem.
Here’s what your query to select all the houses in a neighborhood might look like: