gpt4 book ai didi

SQLite 清理/碎片和性能下降

转载 作者:行者123 更新时间:2023-12-03 18:35:20 40 4
gpt4 key购买 nike

假设我定期将数据插入 SQLite 数据库,然后清除前 50% 的数据,但我不清理。

我现在是否有类似文件前 50% 的清零页面之类的东西?如果我添加另一批数据,我是否正在填写那些清零的页面?

手册中提到了数据的碎片化:

Frequent inserts, updates, and deletes can cause the database file to become fragmented - where data for a single table or index is scattered around the database file.

VACUUM ensures that each table and index is largely stored contiguously within the database file. In some cases, VACUUM may also reduce the number of partially filled pages in the database, reducing the size of the database file further.

但这并不表示这必然会导致性能下降。它主要暗示可以通过吸尘节省的空间浪费。

严格连续页面中的数据是否有明显的性能提升?我是否可以期望具有大量零散数据的数据库具有“糟糕”的性能?

最佳答案

SQLite 自动重用空闲页面。

碎片化的页面只有在以下情况下才会导致性能下降

  • 数据量太大无法缓存,并且
  • 您的存储设备的寻道速度确实相对较慢(例如硬盘或便宜的闪存设备),并且
  • 您访问数据的频率足够高,因此差异很重要。

只有一种方法可以确定您的应用是否属于这种情况:测量它。

关于SQLite 清理/碎片和性能下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26812249/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com