如何在Android中使用sqlite VACUUM [英] How to use sqlite VACUUM in android

查看:80
本文介绍了如何在Android中使用sqlite VACUUM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个涉及登录应用程序的Android应用程序,它执行许多CRUD操作.用户首次登录时,如果有可供该用户下载的任何数据,它将快速记录他/她. 但是稍后再次登录时,该过程非常缓慢,有时大约需要20到30分钟.因此,我读到有关使用VACUUM避免删除记录时创建的可用空间的信息.

I have an android app which involves login to the app and it performs many CRUD operations. When user logins first time, it logs him/her quickly if there is any data available for that user that will be downloaded. But later on when re-login again, theprocess is very slow, sometimes it takes around 20 to 30mins. So, I read about using VACUUM to avoid free space created when the record is deleted.

我什么时候以及如何使用VACUUM感到有些困惑,是在打开数据库时才是用户登录时?或其他时间.

I am bit confused when and how to use VACUUM, is it while opening the database that is when user login ? or some other time.

关于此的任何建议都将有所帮助. 谢谢

Any suggestions on this would be helpful. Thanks

推荐答案

来自: https://sqlite.org/lang_vacuum.html

运行VACUUM可确保大量存储每个表和索引
在数据库文件中连续

Running VACUUM ensures that each table and index is largely stored contiguously
within the database file

关于许多CRUD操作:db文件通常会变得碎片化,特别是
当这些操作涉及删除大量数据时.
使用Java代码,这非常简单:

About many CRUD operations: the db file usually becomes fragmented,
especially when these operations involve say deleting large amount of data.
With Java code it's fairly simple:

db.execSQL("VACUUM");

尽管该过程可能需要一段时间,并且无法监视其进度.
当然,您不需要在每次运行应用程序时都执行此语句,而是定期执行.
或者,如果您在确认数据操作(就像任何重构操作都不是100%安全的)之后就经历了加载数据甚至登录的延迟,则可以让用户执行此过程.备份.

although the process can take a while and it is not possible to monitor its progress.
Of course you don't need to execute this statement every time you run the app, but periodically.
Or you may let the user execute this process, if he/she experiences delays on loading the data, or even logging in, after you make clear that such an operation, just like any reconstructing operation is not 100% safe, so propose first a backup.

这篇关于如何在Android中使用sqlite VACUUM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆