Mysql - 归档数据,使用哪种解决方案?

发布于 2024-10-20 11:59:33 字数 174 浏览 6 评论 0原文

我使用的是 MySQL 5.x,有一个主表包含所有客户的统计数据。我想对其运行报告,但不想在同一个表上运行它,因此我每天晚上都在考虑将数据移动到仅用于报告的不同表。我的问题是,为每个客户提供一个单独的表来存档是否有益,还是只为所有客户提供一个存档表?系统中可能有数千个客户,如果我决定按客户分解它,这可能意味着数千个存档表。你的想法?

I am using MySQL 5.x and there is one main table that has the stats combined for all customers. I would like to run reporting on it but dont want to run it on the same table so Im thinking of every night moving the data to a different table that will only be used for reporting. My question is would it be beneficial to have a seperate table for each customer to archive too or just have it just one archive table for all customers? There could be thousands of customers in the system which could mean thousands of archive tables if I decide to break it up by customer. Your thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥有 2024-10-27 11:59:33

如果您为每个客户使用单独的表,表的数量将会增加。

如果您有统计数据,那么我建议将其总结如下,

  1. 将最后 1 个月的数据保留在同一个主表中。
  2. maintable_quartely 表中的季度数据/半年数据根据报告要求保存平均或汇总数据,
  3. maintable_archieve 中保留旧数据,其中保存 > >根据报告要求平均或汇总的季度或半年数据

如果您希望将整个数据放在一起,则需要合并三个表格。

其他方式,使用 mysql 复制和 master 进行插入、更新、删除,使用 Slave 进行选择

If you use the individual for each customer, tables will grow in number.

If you have statistics data then i suggest to summarize it like below

  1. keep last 1 month data in the same main table.
  2. quartely data/half yearly data in maintable_quartely table that holds the averaged or summarized data based on the report requirements
  3. remaing old data in maintable_archieve which holds > quartely or half yearly data averaged or summarized based on the report requirements

If you want the whole thing together you need to combine three tables.

other way, use mysql replication and master for insert,update,delete and slave for select

-残月青衣踏尘吟 2024-10-27 11:59:33

我认为这都是组织数据的一种方式;如果您正在处理诸如客户和订单之类的事情,那么无论如何它们都应该是单独的表。

根据可用的资源,您可能可以执行类似的操作,

CREATE TEMPORARY TABLE `new_table` LIKE `old_table`;
INSERT INTO `new_table` SELECT * FROM `old_table`;

您将获得您想要处理报告的表格的完美副本。如果您的资源有限,您可能可以对其进行批处理,如下所示:

CREATE TEMPORARY TABLE `new_table` LIKE `old_table`;
INSERT INTO `new_table` SELECT * FROM `old_table` LIMIT 100;

...在下一次迭代中:

DROP TABLE `new_table`;
CREATE TEMPORARY TABLE `new_table` LIKE `old_table`;
INSERT INTO `new_table` SELECT * FROM `old_table` LIMIT 100 OFFSET 100;

就归档信息而言,这取决于您正在工作的环境。例如,在我的东西的环境中工作时间为 24/7,需求量极高。我有一个临时数据引擎,它将所有数据保存在 RAM 数据库中,当一条记录被视为“已关闭”时,它会被移至 MySQL 数据库中进行存档。这样,当需要时,我可以在 MySQL 数据库上运行任何报告,而不会影响实时数据的操作运行时间。

我可以提供一些有关如何归档数据的想法,但这需要您对正在处理的数据量和需求类型进行描述。

I see this as all as a way of organizing your data; if you're dealing with things like customers, and orders, they should be separate tables, anyways.

Depending on the resources available, you could probably do something like

CREATE TEMPORARY TABLE `new_table` LIKE `old_table`;
INSERT INTO `new_table` SELECT * FROM `old_table`;

Where you would have a perfect copy of the table you would like to get the report to work on. If your resources are limited, you could probably batch it, like so:

CREATE TEMPORARY TABLE `new_table` LIKE `old_table`;
INSERT INTO `new_table` SELECT * FROM `old_table` LIMIT 100;

...and on the next iteration:

DROP TABLE `new_table`;
CREATE TEMPORARY TABLE `new_table` LIKE `old_table`;
INSERT INTO `new_table` SELECT * FROM `old_table` LIMIT 100 OFFSET 100;

As far as archiving the information goes, it depends on the environment you are working in. For example, in the environment my stuff works in, it's 24/7 and extremely high-demand. I have an interim data engine which keeps all the data in an in-RAM database, and when a record is seen as "closed", it is moved into a MySQL database for archiving. This way, when the need be, I can run whatever reports on the MySQL database, without impacting the operational run-time of the live data.

I can offer some ideas on how to archive your data, but that would require you to put forth a description of the type of volume and demand you're dealing with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文