开发者

TEXT values in sqlite databases

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜