惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
B
Blog
小众软件
小众软件
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
I
InfoQ
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
H
Help Net Security
雷峰网
雷峰网
S
SegmentFault 最新的问题
V
Visual Studio Blog
爱范儿
爱范儿

SQLite

sqlite 性能是否够用?看上去并发似乎还是很强 - V2EX SQLite 开启 WAL 后,我的同步服务吞吐量提升了 3 倍 分享适合高并发场景的 SQLite 设置 在什么情况下一定要放弃 SQLite 采用 MySQL 呢? SQLite 背后的故事 macOS 上有什么好用的 SQLite GUI ? SQLite In-Memory 作为数据缓存代替 Java Object 什么时候调用 sqlite.close()呢 回复“什么场景下用 SQLite”的主题并分享一个年收入 60 万刀的技术栈 大家有用 Sqlite 的吗,都是什么场景下要用这个,能说一两点非要用它的理由最好啦 SQLite Viewer Web App 本地数据库 除了 SQLite 还有什么好用的. 请教一个方案,边缘设备的 sqlite 数据如何才能获取到 有人知道怎么在 termux 上编译 sqlcipher 吗? 求一个数据库设计问题! SQLite 被曝漏洞,影响范围很大 两个读写 SQLite 数据库的浏览器扩展 How SQLite is tested 如果需要寫入數據, 不僅數據文件要有寫入權限, 數據文件所在的目錄也要有寫入權限 用sqlite3作为论坛的数据库行不行? About Sqlite 之前的一篇笔记 如何把一个2G的sqlite数据库分割成小的? Base 2.0
应该怎么理解 rowid 在 sqlite 中的使用
youthfire · 2022-07-13 · via SQLite

S.O 上我记得有个贴
https://stackoverflow.com/questions/35876171/sqlite-rowid-after-deleting-rows
其中有段话我印象很深
The data for rowid tables is stored as a B-Tree structure containing one entry for each table row, using the rowid value as the key. This means that retrieving or sorting records by rowid is fast. Searching for a record with a specific rowid, or for all records with rowids within a specified range is around twice as fast as a similar search made by specifying any other PRIMARY KEY or indexed value.
总结起来:rowid - 也就是 true primary key 性能优势大
在 Sqlite 官网的 rowid table 中,又是这么阐述的:If the rowid is not aliased by INTEGER PRIMARY KEY then it is not persistent and might change. In particular the VACUUM command will change rowids for tables that do not declare an INTEGER PRIMARY KEY. Therefore, applications should not normally access the rowid directly, but instead use an INTEGER PRIMARY KEY.
总结起来:不应该直接使用 rowid
自己平时在操作 sqlite select row 的时候,一直都是直接用 rowid 来选取执行的,一开始是不知道 declare primary key as alias of rowid ,后来是发现没有使用场景用到。官网让不要 direct access 的原因是 rowid 有时候会变,比如 VACUUM 。我没有理解这句,我就是需要 rowid 重新 rebuild ,才会去用 VACUUM 的啊,否则当频繁操作添加,删除动作后,不进行 rebuild ,我再用语句操作 rowid ,可能就不是我真正需要操作的行。所以我才每次在这些动作后,都会进行 VACUUM 。主要是为了逻辑不出错,同时之后读取性能好,空间小。
但有时候 VACUUM 的时间会很长,可是不操作,此 rowid(true primary key )不是彼 rowid 啊,例如删除了第 6 行,如果不 VACUUM, 我想再操作新的第 6 行,这个时候 rowid 其实是 7 ,不是 6 ,就产生了逻辑问题啊。
阐述得略混乱,请见谅!