Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One to One database relation?

In my free time I started writing a small multiplayer game with a database backend. I was looking to separate player login information from other in game information (inventory, stats, and status) and a friend brought up this might not be the best idea.

Would it be better to lump everything together in one table?

like image 452
mjard Avatar asked Oct 04 '08 20:10

mjard


1 Answers

Start by ignoring performance, and just create the most logical and easy-to-understand database design that you can. If players and game objects (swords? chess pieces?) are separate things conceptually, then put them in separate tables. If a player can carry things, you put a foreign key in the "things" table that references the "players" table. And so on.

Then, when you have hundreds of players and thousands of things, and the players run around in the game and do things that require database searches, well, your design will still be fast enough, if you just add the appropriate indexes.

Of course, if you plan for thousands of simultaneous players, each of them inventorying his things every second, or perhaps some other enormous load of database searches (a search for each frame rendered by the graphics engine?) then you will need to think about performance. But in that case, a typical disk-based relational database will not be fast enough anyway, no matter how you design your tables.

like image 55
Thomas Padron-McCarthy Avatar answered Sep 24 '22 01:09

Thomas Padron-McCarthy