14 | 存储优化(下):数据库SQLite的使用和优化
该思维导图由 AI 生成,仅供参考
SQLite 的那些事儿
- 深入了解
- 翻译
- 解释
- 总结
移动开发中数据库SQLite的使用和优化对于移动应用的稳定性、性能和可扩展性至关重要。SQLite作为一种轻量级的关系型数据库管理系统,适用于移动设备的存储需求,具有小巧、高效、易集成等特点。本文介绍了SQLite在大数据存储场景下的重要性,并提供了优化经验和技术指导。通过引入ORM框架、WAL模式、连接池以及正确建立索引等方法,可以提升SQLite的性能和稳定性。此外,文章还分享了微信在SQLite损坏与恢复、加密与安全、全文搜索等方面的经验,并强调了正确使用索引和事务的重要性。总之,本文为移动开发者提供了重要的技术指导,帮助他们了解SQLite在移动应用开发中的关键作用,以及如何处理大数据存储场景下的稳定性、性能和可扩展性问题。
《Android 开发高手课》,新⼈⾸单¥59
全部留言(16)
- 最新
- 精选
- HI大致的看了Matrix SQLiteLint的源码实现,由于Androd N hook sqlite3_profile 会出现问题,SQLiteLint 并不能实时的获取到sql语句,而是采用java层主动的告知SQLiteLint 要分析的sql,比如分析 select *,PrepareStatement, 而对于检测 Autoincrement,冗余索引,Without RowId 而是通过native层告知java层要查询的内容,java层将查询之后的内容再通知native层,这个检测的时间间隔为4秒,这4秒是有什么依据的吗
作者回复: 这些都是一些拍脑袋的经验值而已,也可以在GitHub上面提issue
2019-03-113 - 黄小木🐵张老师好,提个问题,我们项目当前用的是ormlite关系型数据库框架,已经利用里面的api写了大量sql语句,请问如何最低成本的替换成wcdb呢?
作者回复: ormlite应该是ORM框架,跟底层的wcdb应该是不冲突的。
2019-02-152 - 满大大老师客户端怎么开启WAL模式
作者回复: SQLite有接口的
2019-12-101 - 嘿,抬头张老师,请教个问题: 启动一个Activity,可以查出数据库中数据,但切换下系统语言,Activity重启,却查不出数据库中的数据!!!(debug看到两次都执行了查询数据库的代码) 希望您指点一二,谢谢~
作者回复: 输入信息太少,如果是必现可以比较好搞,这个可以直接通过sql命令行查询一下
2019-01-151 - Lsqlite wal mode w模式sync mode 可以直接修改成OFF?若不行,怎么论证?谢谢!因为修改成OFF可以减少 DB fdatasync call
作者回复: 可以看看:https://www.sqlite.org/pragma.html#pragma_journal_mode PRAGMA schema.synchronous; PRAGMA schema.synchronous = 0 | OFF | 1 | NORMAL | 2 | FULL | 3 | EXTRA; Query or change the setting of the "synchronous" flag. The first (query) form will return the synchronous setting as an integer. The second form changes the synchronous setting. The meanings of the various synchronous settings are as follows: EXTRA (3) EXTRA synchronous is like FULL with the addition that the directory containing a rollback journal is synced after that journal is unlinked to commit a transaction in DELETE mode. EXTRA provides additional durability if the commit is followed closely by a power loss. FULL (2) When synchronous is FULL (2), the SQLite database engine will use the xSync method of the VFS to ensure that all content is safely written to the disk surface prior to continuing. This ensures that an operating system crash or power failure will not corrupt the database. FULL synchronous is very safe, but it is also slower. FULL is the most commonly used synchronous setting when not in WAL mode. NORMAL (1) When synchronous is NORMAL (1), the SQLite database engine will still sync at the most critical moments, but less often than in FULL mode. There is a very small (though non-zero) chance that a power failure at just the wrong time could corrupt the database in journal_mode=DELETE on an older filesystem. WAL mode is safe from corruption with synchronous=NORMAL, and probably DELETE mode is safe too on modern filesystems. WAL mode is always consistent with synchronous=NORMAL, but WAL mode does lose durability. A transaction committed in WAL mode with synchronous=NORMAL might roll back following a power loss or system crash. Transactions are durable across application crashes regardless of the synchronous setting or journal mode. The synchronous=NORMAL setting is a good choice for most applications running in WAL mode. OFF (0) With synchronous OFF (0), SQLite continues without syncing as s
2019-02-17 - 大土豆我有一个想法,老师看下是否合理,把MySQL(innodb)这套全部放到移动端来,唯一区别是MySQL是C/S模型,访问方式(连接层)改造下,改成移动端类似sqlite的db文件类型。这样,innodb的行级锁可强多了,然后MySQL总体是多线程读写并发的,不是能更好地榨干移动端的性能吗?微信有这么想过吗?2022-02-03
- JavanRhinoPRAGMA SQLITE_THREADSAFE = 2 这个是用java代码设置吗?看源码好像没有提供java api呀2021-07-07
- JavanRhino对于 iOS 来说可能没有多进程访问数据库的场景,可以把 locking_mode 的默认值改为 EXCLUSIVE。 ——>应该是对于Android来说吧?2021-07-061
- hs老师想问一下这句话的意思 “还有需要说明的是,同一个句柄同一时间只有一个线程在操作,这个时候我们需要打开连接池 Connection Pool” 为什么同一个句柄同一时间只有一个线程在操作,就需要开启线程池2020-11-10
- JeffMony这篇文章太深了2020-03-10