sqlite数据库是否对TEXT值使用类似flyweight模式的内容。如果我在列中重复使用几个不同的短TEXT值,用整数替换它们会更好吗?
答案 0 :(得分:3)
SQLite分别存储文本列的每个副本:
$ 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?
因此,如果要避免重复字符串,则应使用整数,设置单独的表以将整数映射到字符串,然后将foreign key添加到此新表中,以便确保参照完整性。