SQLite - 预分配数据库大小
有没有办法将我的 SQLite 数据库预先分配到一定的大小? 目前,我正在添加和删除一些记录,并希望在创建时避免这种开销。
Is there a way to pre allocate my SQLite database to a certain size? Currently I'm adding and deleting a number of records and would like to avoid this over head at create time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最快的方法是使用 Zero_blob 函数:
示例:
Y:> sqlite3 Large.sqlite
SQLite版本3.7.4
输入“.help”以获取说明
输入以“;”结尾的 SQL 语句
sqlite> 创建大表(a);
sqlite> 插入大值(zeroblob(1024*1024));
sqlite> 拖放大桌子;
sqlite> .q
Y:> 目录large.sqlite
驱动器 Y 中的卷是个人的
卷序列号为 365D-6110
Y 目录:\
01/27/2011 12:10 PM 1,054,720 large.sqlite
Note: As Kyle properly indicates in his comment:
每个 blob 的大小是有限制的,因此如果您希望数据库大于 ~1GB,则可能需要插入多个 blob。
The fastest way to do this is with the zero_blob function:
Example:
Y:> sqlite3 large.sqlite
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table large (a);
sqlite> insert into large values (zeroblob(1024*1024));
sqlite> drop table large;
sqlite> .q
Y:> dir large.sqlite
Volume in drive Y is Personal
Volume Serial Number is 365D-6110
Directory of Y:\
01/27/2011 12:10 PM 1,054,720 large.sqlite
Note: As Kyle properly indicates in his comment:
There is a limit to how big each blob can be, so you may need to insert multiple blobs if you expect your database to be larger than ~1GB.
有一个 hack - 将一堆数据插入数据库,直到数据库大小达到您想要的大小,然后删除数据。 这是有效的,因为:
当然,这不是最可靠的方法。(此外,您需要确保禁用 auto_vacuum 才能使其工作)。您可以在此处了解更多信息 - http://www.sqlite.org/lang_vacuum.html
There is a hack - Insert a bunch of data into the database till the database size is what you want and then delete the data. This works because:
Naturally, this isn't the most reliable method. (Also, you will need to make sure that auto_vacuum is disabled for this to work). You can learn more here - http://www.sqlite.org/lang_vacuum.html