在 SQLite 中读取固定宽度列是否更快?

发布于 2024-10-07 05:10:39 字数 77 浏览 0 评论 0原文

从没有存储 varchar 或其他可变长度数据的表中读取通常会更快吗?在 MySQL 中,这更快,因为它可以准确计算行将存储在磁盘上的位置。

Would it generally be faster to read from a table where there are no varchar or other variable length data stored? In MySQL, this is faster because it can calculate exactly where a row will be stored on the disk.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿挽旧人 2024-10-14 05:10:39

这个问题在 SQLite 上下文中没有意义,因为它仅支持单个 TEXT 字段类型。这里不存在“固定宽度”与“可变长度”的区别。

虽然 SQLite 允许您将字段定义为具有某种类型,但所做的一切(至多)只是设置该字段对存储不明确数据时要使用的类型的偏好(例如,“3”是否将存储为 INTEGER、REAL、或文本)。您仍然可以在任何 SQLite 字段中存储任何类型的数据,无论其类型如何。

具体到 CHAR 与 VARCHAR,http://www.sqlite.org/datatype3.html 告诉我们:

如果列的声明类型
包含任何字符串“CHAR”,
“CLOB”或“TEXT”则该列有
文本亲和力。请注意,类型
VARCHAR 包含字符串“CHAR”并且
因此分配了 TEXT 亲和力。

This question is not meaningful in the context of SQLite as it supports only a single TEXT field type. The distinction of "fixed-width" vs. "variable-length" doesn't exist here.

While SQLite will let you define a field as having a certain type, all this does is (at most) set that field's preference for the type to use when storing ambiguous data (e.g., whether "3" will be stored as INTEGER, REAL, or TEXT). You can still store any kind of data in any SQLite field regardless of its type.

Specifically relating to CHAR vs. VARCHAR, http://www.sqlite.org/datatype3.html tells us:

If the declared type of the column
contains any of the strings "CHAR",
"CLOB", or "TEXT" then that column has
TEXT affinity. Notice that the type
VARCHAR contains the string "CHAR" and
is thus assigned TEXT affinity.

单身狗的梦 2024-10-14 05:10:39

由于 SQLite 仅使用可变长度记录,我猜他们确实这么做了当行恰好具有相同长度时,不实现固定宽度查找优化。

正如 Dave 指出的那样,人们仍然可以在 INT 字段中存储文本。由于 SQLite 从不截断数据,这意味着 SQLite 允许像 INT 这样看似固定宽度的列来存储变量-长度数据也是如此。所以不可能实现定宽查找优化。

Since SQLite uses variable-length records only, I would guess they did not implement fix-width lookup optimization when rows happen to have the same length.

And as Dave pointed out, one can still store text in INT fields. Since SQLite never truncates data, this means SQLite permits seemingly fixed width column like INT to store variable-length data too. So it is impossible to implement fixed-width lookup optimization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文