“Fantasy Football”数据库中结果表的正确数据库结构

RDo*_*wns 2 mysql database ddl database-design

在这个场景中,我有:球员、梦幻足球联赛(社区)和结果。

1 个用户可以加入多个幻想联盟。

我当前的结构为:

create table players (id int, email, display_name)
create table communities (id int, name, password, admin_email)
create table community_players (community_id, player_id)
Run Code Online (Sandbox Code Playgroud)

我现在需要为每个社区创建一个结果表。我刚在想:

create table results (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
Run Code Online (Sandbox Code Playgroud)

我担心这张桌子最终会变得很大。因此,当我去查询它的统计数据(即谁击败了谁、进球数、失球数等)时,它最终会变得非常慢。

我的想法是:

我是否应该为创建的每个社区“即时”创建一个结果表?

create table results_community_name (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
Run Code Online (Sandbox Code Playgroud)

Mur*_*nik 5

数据库是为存储行而构建的。很多行。通过正确的索引和维护,您永远不会真正遇到性能问题。另一方面,为每个社区创建一个表不仅会使您的代码变得复杂,而且很快就会成为维护的噩梦。

如果性能确实成为一个问题,您应该查看 MySQL 的分区。本质上,它创建了 N 个隐藏在一个逻辑表后面的物理表,这有点像为每个社区创建一个表的想法,但管理方式更容易。