简体   繁体   English

数据库设计

[英]Database Design

I'm trying to build out a mysql database design for a project. 我试图建立一个项目的mysql数据库设计。 The problem is coming up with the best solution. 问题是提出最佳解决方案。 Basically in my application, I will have to insert approximately 10-30 rows per user. 基本上在我的应用程序中,我将必须为每个用户插入大约10-30行。 The primary key will be a random CHAR(16) string. 主键将是随机的CHAR(16)字符串。 There will also be an datetime index, and an additional row (with an index) called "data". 还将有一个日期时间索引,以及另外一个称为“数据”的行(带有索引)。

Day to day, there will only be a heavy amount of inserts and lookups on the table. 每天,桌上只会有大量的插入和查找。 The lookups will always joined based on the primary key (so joining those 10-30 rows per user). 查找将始终基于主键进行联接(因此,将每个用户联接10-30行)。

I will at times need to be able to look at a few specific months (or a full year even) and use mysql GROUP BY functions on the "data" index as well. 有时,我将需要能够查看一些特定的月份(甚至全年),并在“数据”索引上使用mysql GROUP BY函数。

At its current volume and estimates, I would expect the table to grow 9.3m rows/month. 根据当前的数量和估计,我希望该表每月增长930万行。 I do expect this to increase. 我希望这个数字会增加。

So my question comes down to this: mysql partitions, programmatic table separation, or another solution? 所以我的问题归结为:mysql分区,程序化表分离或其他解决方案? and are things best separated by month or year? 事情最好按月或年分开吗? We are running on RHEL, so getting mysql 5.1 may be a bit of work, but if that's a better solution it may be worth going for. 我们正在RHEL上运行,因此获取mysql 5.1可能需要一些工作,但是如果这是一个更好的解决方案,那么它可能是值得的。

innoDB has already been selected for this project. 已经为该项目选择了innoDB。 Day to day performance is the primary concern. 日常性能是最主要的问题。

This doesn't answer your question, but it needs to be mentioned... 这不能回答您的问题,但需要提及...

The primary key will be a random CHAR(16) string. 主键将是随机的CHAR(16)字符串。

This is a Bad Idea. 这是一个坏主意。 Use an UNSIGNED BIGINT column with AUTO_INCREMENT. 将UNSIGNED BIGINT列与AUTO_INCREMENT一起使用。 No need to reinvent the wheel: you won't have to worry about key management or collisions that way. 无需重新发明轮子:您不必担心密钥管理或那样的冲突。

Partition the data on the dates (and maybe additionally the user it is per-user data and you have lots of users). 按日期对数据进行分区(也许用户是按用户数据,并且您有很多用户)。

Then create a monthly table with the SUM , COUNT , AVG , etc that you need and the appropriate group by. 然后创建一个每月表,其中包含所需的SUMCOUNTAVG等,并根据分组依据。 You can partition that table as well (but dates probably won't be a meaningful partition) 您也可以对该表进行分区(但日期可能不会成为有意义的分区)

Then create a yearly table like the monthly table. 然后创建一个年度表,如每月表。

Populate the monthly and yearly tables with REPLACE INTO ... SELECT ... statements. REPLACE INTO ... SELECT ...语句填充月度和年度表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM