Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it faster to read from fixed-width columns in SQLite?

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.

like image 989
David Avatar asked Dec 14 '10 10:12

David


2 Answers

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.

like image 91
Dave Sherohman Avatar answered Sep 21 '22 12:09

Dave Sherohman


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.

like image 27
lulalala Avatar answered Sep 21 '22 12:09

lulalala