Mysql – Which design to choose in this case

database-designMySQL

I am designing a database for a video game. I have some data structures like {x, y, z, dimension} used across multiple tables.

For instance :

Table player_death

id: int
player_id: int
death_x: int
death_y: int
death_z: int
death_dimension: int

Since {x, y, z, dimension} represents a geographic vector in the video game, a lot of table contain those columns. My question is : should I create a table named vector containing a pool of all the vectors used in my tables (and then use reference to them) or should I keep adding {x, y, z, dimension} columns to each table using a vector ? What is the best practice ? I am a beginner in database design, sorry if the question sounds stupid.

Best Answer

should I create a table named vector containing a pool of all the vectors used in my tables?

No

Creating such a table and referencing to it would only be helpful If you know that many, many players are going to die in the same spot. Assuming that death of players will be in random locations, creating another table will not help, and your select queries will have to carry an unnecessary overhead of joins. If your queries will mainly look like this, then this option is best for you :

SELECT * FROM player_death WHERE player_id = <playerid> 

On the other hand, if your game largely depended on coordinates of places rather than death places of players, creating another table would have been relevant. For example, if you want to spawn monsters only where players have died , or if you have to paint the death place red, and some other place yellow and rest all green, these all are relevant to on position in the map, not death place of players, and it'd be better to have a separate table.