我知道(从this question的答案来看),Sqlite默认情况下不支持压缩。是否可以启用它,或者是否需要其他工具?情况如下:
我需要在Sqlite数据库中添加数百万行。该表包含一个description
列(平均约500个字符),每个description
平均由40行共享,如下所示:
id name othercolumn description
1 azefds ... This description will be the same for probably 40 rows
2 tsdyug ... This description will be the same for probably 40 rows
...
40 wxcqds ... This description will be the same for probably 40 rows
41 azeyui ... This one is unique
42 uiuotr ... This one will be shared by 60 rows
43 poipud ... This one will be shared by 60 rows
...
101 iuotyp ... This one will be shared by 60 rows
102 blaxwx ... Same description for the next 10 rows
103 sdhfjk ... Same description for the next 10 rows
...
问题:
或者
你要两张桌子吗?你知道吗
id name othercolumn descriptionid
1 azefds ... 1
2 tsdyug ... 1
...
40 wxcqds ... 1
41 azeyui ... 2
...
id description
1 This description will be the same for probably 40 rows
2 This one is unique
Con:与解决方案1中的简单select id, name, description from mytable
不同,我们必须使用一种复杂的方法来检索它,包括两个表,可能还有多个查询?或者可以不用复杂的查询,但是用union
或merge
之类的聪明查询来完成吗?
下面是一些用Python编写的示例代码,以说明ScottHunter的答案:
使用多个表不仅可以防止不一致,占用更少的空间,而且可能更快,即使涉及多个/更复杂的查询(正是因为它涉及移动更少的数据)。你应该使用哪一个取决于这些特征中哪一个对你最重要。你知道吗
当您有两个表时,用于检索结果的查询将如下所示(实际上只是两个表之间的连接):
相关问题 更多 >
编程相关推荐