• <small id='wH45w'></small><noframes id='wH45w'>

  • <legend id='wH45w'><style id='wH45w'><dir id='wH45w'><q id='wH45w'></q></dir></style></legend>

    1. <tfoot id='wH45w'></tfoot>
        <i id='wH45w'><tr id='wH45w'><dt id='wH45w'><q id='wH45w'><span id='wH45w'><b id='wH45w'><form id='wH45w'><ins id='wH45w'></ins><ul id='wH45w'></ul><sub id='wH45w'></sub></form><legend id='wH45w'></legend><bdo id='wH45w'><pre id='wH45w'><center id='wH45w'></center></pre></bdo></b><th id='wH45w'></th></span></q></dt></tr></i><div id='wH45w'><tfoot id='wH45w'></tfoot><dl id='wH45w'><fieldset id='wH45w'></fieldset></dl></div>
        • <bdo id='wH45w'></bdo><ul id='wH45w'></ul>

        从 MySQL 滚动删除旧行的最佳方法是什么?

        时间:2023-06-01
        • <legend id='FpTIx'><style id='FpTIx'><dir id='FpTIx'><q id='FpTIx'></q></dir></style></legend>

            <bdo id='FpTIx'></bdo><ul id='FpTIx'></ul>
              <tbody id='FpTIx'></tbody>

                1. <tfoot id='FpTIx'></tfoot>

                2. <small id='FpTIx'></small><noframes id='FpTIx'>

                  <i id='FpTIx'><tr id='FpTIx'><dt id='FpTIx'><q id='FpTIx'><span id='FpTIx'><b id='FpTIx'><form id='FpTIx'><ins id='FpTIx'></ins><ul id='FpTIx'></ul><sub id='FpTIx'></sub></form><legend id='FpTIx'></legend><bdo id='FpTIx'><pre id='FpTIx'><center id='FpTIx'></center></pre></bdo></b><th id='FpTIx'></th></span></q></dt></tr></i><div id='FpTIx'><tfoot id='FpTIx'></tfoot><dl id='FpTIx'><fieldset id='FpTIx'></fieldset></dl></div>
                3. 本文介绍了从 MySQL 滚动删除旧行的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我发现自己想在许多应用程序中滚动删除早于 (x) 天的行.在高流量表上最有效地执行此操作的最佳方法是什么?

                  I find myself wanting to delete rows older than (x)-days on a rolling basis in a lot of applications. What is the best way to do this most efficiently on a high-traffic table?

                  例如,如果我有一个存储通知的表,而我只想将这些通知保留 7 天.或者我只想保留31天的高分.

                  For instance, if I have a table that stores notifications and I only want to keep these for 7 days. Or high scores that I only want to keep for 31 days.

                  现在我保留一行存储发布的纪元时间并运行一个每小时运行一次的 cron 作业,并以这样的增量删除它们:

                  Right now I keep a row storing the epoch time posted and run a cron job that runs once per hour and deletes them in increments like this:

                  DELETE FROM my_table WHERE time_stored < 1234567890 LIMIT 100
                  

                  我一直这样做,直到 mysql_affected_rows 返回 0.

                  I do that until mysql_affected_rows returns 0.

                  我曾经一次性完成所有操作,但这导致应用程序中的所有内容在 INSERTS 堆积时挂起 30 秒左右.添加 LIMIT 可以缓解这种情况,但我想知道是否有更好的方法来做到这一点.

                  I used to do it all at once but that caused everything in the application to hang for 30 seconds or so while INSERTS piled up. Adding the LIMIT worked to alleviate this but I'm wondering if there is a better way to do this.

                  推荐答案

                  查看 MySQL 分区:

                  通过删除仅包含该数据的分区(或多个分区),通常可以轻松地从分区表中删除失去其用处的数据.相反,在某些情况下,通过添加一个或多个新分区来专门存储该数据,可以极大地促进添加新数据的过程.

                  Data that loses its usefulness can often be easily removed from a partitioned table by dropping the partition (or partitions) containing only that data. Conversely, the process of adding new data can in some cases be greatly facilitated by adding one or more new partitions for storing specifically that data.

                  参见例如本节以获取有关如何应用它的一些想法:

                  See e.g. this section to get some ideas on how to apply it:

                  MySQL 分区修剪

                  还有这个:

                  按日期分区:快速操作方法

                  这篇关于从 MySQL 滚动删除旧行的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将root密码设置为空 下一篇:在关系数据库中存储树结构的已知方法有哪些?

                  相关文章

                  1. <legend id='JVCBy'><style id='JVCBy'><dir id='JVCBy'><q id='JVCBy'></q></dir></style></legend>
                      <bdo id='JVCBy'></bdo><ul id='JVCBy'></ul>

                  2. <small id='JVCBy'></small><noframes id='JVCBy'>

                  3. <tfoot id='JVCBy'></tfoot>

                    1. <i id='JVCBy'><tr id='JVCBy'><dt id='JVCBy'><q id='JVCBy'><span id='JVCBy'><b id='JVCBy'><form id='JVCBy'><ins id='JVCBy'></ins><ul id='JVCBy'></ul><sub id='JVCBy'></sub></form><legend id='JVCBy'></legend><bdo id='JVCBy'><pre id='JVCBy'><center id='JVCBy'></center></pre></bdo></b><th id='JVCBy'></th></span></q></dt></tr></i><div id='JVCBy'><tfoot id='JVCBy'></tfoot><dl id='JVCBy'><fieldset id='JVCBy'></fieldset></dl></div>