在 'fantasy football' 数据库中更正结果 table 的数据库结构
Correct database structure for a results table in a 'fantasy football' database
在这种情况下,我有:球员、梦幻足球联赛(社区)和结果。
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)
我现在需要为每个社区创建一个结果 table。我在想:
create table results (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
我担心这个 table 最终会变得很大。因此,当我去 运行 查询统计数据时(即谁击败了谁、进球数、失球数等),它最终会非常慢。
我的想法是:
我应该为每个创建的社区创建一个结果 table 'on-the-fly' 吗?
create table results_community_name (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
数据库是为存储行而构建的。 很多行。通过适当的索引和维护,您永远不会真正遇到性能问题。另一方面,为每个社区创建一个 table 不仅会使您的代码复杂化,而且很快就会成为维护的噩梦。
如果性能确实成为问题,您应该查看 MySQL 的 partitions。本质上,它创建了 N 个物理 table 隐藏在一个逻辑 table 后面,这有点像您为每个社区创建一个 table 的想法,但管理起来要容易得多。
在这种情况下,我有:球员、梦幻足球联赛(社区)和结果。
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)
我现在需要为每个社区创建一个结果 table。我在想:
create table results (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
我担心这个 table 最终会变得很大。因此,当我去 运行 查询统计数据时(即谁击败了谁、进球数、失球数等),它最终会非常慢。
我的想法是:
我应该为每个创建的社区创建一个结果 table 'on-the-fly' 吗?
create table results_community_name (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
数据库是为存储行而构建的。 很多行。通过适当的索引和维护,您永远不会真正遇到性能问题。另一方面,为每个社区创建一个 table 不仅会使您的代码复杂化,而且很快就会成为维护的噩梦。
如果性能确实成为问题,您应该查看 MySQL 的 partitions。本质上,它创建了 N 个物理 table 隐藏在一个逻辑 table 后面,这有点像您为每个社区创建一个 table 的想法,但管理起来要容易得多。