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

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

SQLite

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

阐述得略混乱,请见谅!