开发者

TEXT values in sqlite databases

开发者 https://www.devze.com 2023-04-07 11:40 出处:网络
Do sqlite databases use anything like a flyweight pattern for TEXT values. If I\'m repeatedly using only a few different,开发者_如何学编程 short TEXT values in a column, would it be better to replace

Do sqlite databases use anything like a flyweight pattern for TEXT values. If I'm repeatedly using only a few different,开发者_如何学编程 short TEXT values in a column, would it be better to replace them with integers?


SQLite stores each copy of the text column individually:

$ sqlite3 pancakes.sqlt
sqlite> create table pancakes (s text);
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');
sqlite> insert into pancakes (s) values ('where is pancakes house?');

$ strings pancakes.sqlt
SQLite format 3
Itablepancakespancakes
CREATE TABLE pancakes (s text)
=where is pancakes house?
=where is pancakes house?
=where is pancakes house?
=where is pancakes house?
=where is pancakes house?
=where is pancakes house?
=where is pancakes house?
=where is pancakes house?

So if you want to avoid duplicating your strings you should use integers, set up a separate table to map your integers to strings, and then add a foreign key to this new table so that you can ensure referential integrity.

0

精彩评论

暂无评论...
验证码 换一张
取 消