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

时间:2022-11-10 15:10:51

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.

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

2 个解决方案

#1


13  

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.

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

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.

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

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

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

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.

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

#2


5  

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.

由于SQLite仅使用可变长度记录,我猜他们在行恰好具有相同长度时没有实现修复宽度查找优化。

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.

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

#1


13  

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.

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

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.

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

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

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

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.

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

#2


5  

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.

由于SQLite仅使用可变长度记录,我猜他们在行恰好具有相同长度时没有实现修复宽度查找优化。

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.

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