mysql-通过删除SQL数据库中的行提高查询性能?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql-通过删除SQL数据库中的行提高查询性能?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1878字,纯文字阅读大概需要3分钟。
内容图文
我有一个带有单个表的数据库,用于跟踪用户状态.处理完该行后,不再需要将其保留在数据库中,可以将其删除.
现在假设我想跟踪该行而不是删除该行(出于历史目的,分析等).这样做会更好吗?
>将数据保留在同一表中,并将该行标记为“已使用”(带有额外的列或类似内容)
>从表中删除行,并将其插入到单独的表中,该表仅用于历史目的
对于选择#1,我想知道是否将不必要的行留在数据库中会开始影响查询性能. (我所有的查询都在索引列上,所以也许没关系吗?)
对于选择#2,我想知道是否不断删除行会导致诸如碎片之类的问题?
解决方法:
从长远来看,查询性能会更好:
永久插入会发生什么:
The table grows, indexes grow, index performance (lookup) is decreases with the size of the table, especially insert performance is hurt.
删除发生了什么:
Table pages get fragmented, so the deleted space is not re-used 100% as expected, more near 50% in MySQL. So the table still grows to about twice the size you might expect for your amount of data. The index gets fragmented and becomes lob sided: It contains your new data but also the structure for your old data. It depends on the structure of your data on how bad this gets. This situation however stabilizes at a certain performance. This performance point has 2 benefits:
1) The table is more limited in size, so potential full table scans are faster
2) Your performance is predictable.
Due to the fragmentation however this performance point is not equal to about twice your data amount, it tends to be a bit worse (benchmark it to see yourself). The benefit of the delete scenario is however since you have a smaller data set, that you might be able to rebuild your index once every reasonable period, thus improving your performance.
备择方案
您可以查看两种替代方法来提高性能:
>切换到MariaDB:这在大型数据集上可获得约8%的性能(我的观察,数据集压缩后的数据仅为200GB)
>查看分区:如果您有方便的分区参数,则可以为您创建一系列“小表”,并防止进行删除,重建和历史数据管理的逻辑.这可能会为您提供最佳性能.
内容总结
以上是互联网集市为您收集整理的mysql-通过删除SQL数据库中的行提高查询性能?全部内容,希望文章能够帮你解决mysql-通过删除SQL数据库中的行提高查询性能?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。