`
aigo
  • 浏览: 2538788 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌
社区版块
存档分类
最新评论

SQLite优化建议

    博客分类:
  • DB
阅读更多

原文:http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite

Several tips:

  1. Put inserts/updates in a transaction
  2. Consider a less paranoid journal mode (pragma journal_mode). There is NORMAL, and then there OFF which can significantly increase insert speed if you're not too worried about the database possibly getting corrupted if the OS crashes. If your application crashes the data should be fine.
  3. Playing with page sizes makes a difference as well (PRAGMA page_size). Having larger page sizes can make reads and writes go a bit faster as larger pages are held in memory. Note that more memory will be used for your database.
  4. If you have indices, consider calling CREATE INDEX after doing all your inserts. This is significantly faster than creating the index and then doing your inserts.
  5. You have to be quite careful if you have concurrent access to SQLite, as the whole database is locked when writes are done, and although multiple readers are possible, writes will be locked out.
  6. Take advantage of saving space...smaller databases go faster. For instance, if you have key value pairs, try making the key an INTEGER PRIMARY KEY if possible, which will replace the implied unique row number column in the table.
  7. If you are using multiple threads, you can try using the shared page cache, which will allow loaded pages to be shared between threads, which can avoid expensive I/O calls.

I've also asked similar questions here and here.

 

 

原文:http://www.sqlite.org/faq.html#q19

(19) INSERT is really slow - I can only do few dozen INSERTs per second

Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer. But it will only do a few dozen transactions per second. Transaction speed is limited by the rotational speed of your disk drive. A transaction normally requires two complete rotations of the disk platter, which on a 7200RPM disk drive limits you to about 60 transactions per second.

Transaction speed is limited by disk drive speed because (by default) SQLite actually waits until the data really is safely stored on the disk surface before the transaction is complete. That way, if you suddenly lose power or if your OS crashes, your data is still safe. For details, read about atomic commit in SQLite..

By default, each INSERT statement is its own transaction. But if you surround multiple INSERT statements with BEGIN...COMMIT then all the inserts are grouped into a single transaction. The time needed to commit the transaction is amortized over all the enclosed insert statements and so the time per insert statement is greatly reduced.

Another option is to run PRAGMA synchronous=OFF. This command will cause SQLite to not wait on data to reach the disk surface, which will make write operations appear to be much faster. But if you lose power in the middle of a transaction, your database file might go corrupt.

分享到:
评论

相关推荐

    SQLiteManager sqlite

    SQLabs SQLiteManager 是一款图形化的SQL数据库管理工具,可打开,创建,连接,转换数据库,可远程管理数据库服务器.程序采用可视化操作界面,可让你方便的设计,管理,分析,校验,优化数据库,非常强大 附着破解,直接使用 ...

    一键增强浏览器加速工具 SpeedyFox 2.0.30.zip

    根据您的浏览活动,我们建议每1-2周对您的个人配置文件进行一次优化。 命令行用法 /<program_name>:<profile_name> – 优化某个配置文件(可以在 SpeedyFox 配置文件树中找到它的名称) /<program_name>:...

    HadSky轻论坛 v7.2.0.zip

    3、我们承诺永久为用户提供售后,若您需要帮助、提出建议或反馈问题,可将具体的内容发布到 用户帮助、建议及反馈区,我们会第一时间进行相关处理。 HadSky轻论坛 v7.2.0 更新日志 1.修复SQLite数据库下版本无法...

    编程狂人第九期(2014-1-20)

    常用CSS优化总结——网络性能与语法性能建议 编程语言 2013流行Python项目汇总 15款Django开发常用软件包 Rails 3 升级 Rails 4 中遇到的问题及解决方法 php性能优化 Java中的 equals() 和 hashCode() 契约 程序...

    SMAFLOW免费进销存管理软件

    SMAFLOW免费进销存管理软件,真对电子元器件经销行业特别优化,适合中小公司使用,协助完成订单、物流、票据、货款的统一平台管理。 其他行业用户可以自行试用以确定是否适合自己。 SMAFLOW的特点: 1、永久免费,...

    基于Java和CNN网络实现垃圾识别分类安卓APP源码+项目说明文档.zip

    模型优化包括 dropout 正则化、Adam优化器等。图像主要筛选整理于华为垃圾分类挑战赛数据集,并且进行了随机水平翻转、图像旋转等数据增强操作,其中 90%用于训练集,10%用于验证集。 图像识别运行流程为安卓客户端...

    HadSky轻论坛

    若您需要帮助、提出建议或反馈问题,可将具体的内容发布到 用户帮助、建议及反馈区,我们会第一时间进行相关处理。[7.2.0.20190625更新内容]1.修复SQLite数据库下版本无法显示的bug;2.修复SQLite数据库下后台数据库...

    c语言c++项目源代码_c&c++课程设计-学生成绩管理系统.rar

    开发者可以根据实际需求添加新功能、优化现有功能或修复潜在问题。 为了充分利用这个资源,建议开发者具备以下技能和知识: - 熟悉C和C++编程语言 - 了解基本的数据结构和算法 - 熟悉文件操作和数据库操作(如...

    unit-builder:构建,比较和共享“帝国时代”在线部队

    Celeste单位建造者建立,比较和分享您的《帝国时代》在线单元项目设置npm install生成数据库,元数据,图像和优化npm run generate编译和热重装以进行开发npm run serve编译和缩小以进行预生产(Robots.txt拒绝所有...

    python项目基于知识图谱的医疗问答系统(django).zip

    随着人工智能和大数据技术的不断进步,未来这个系统可能会集成更多先进的机器学习算法,提供更加深入的疾病诊断支持,实现个性化医疗建议,并通过不断的学习和优化,进一步提升系统的准确性和实用性。

    新秀企业网站系统PHP版 v1.1 beta5.rar

    系统安装时有Mysql、SQLite和Access三种数据库可供选择,SQLite和Access的数据库文件存储在网站目录中,十分方便网站迁移;后台功能齐全,操作简便,可开启伪静态和纯静态模式,有利于SEO优化;前台可设置成同时显示...

    pcr-guild-django:公主连接公会战排刀系统-实际上

    欢迎提出任何建议或意见 将编译后的前端文件添加到vue文件夹中 使用django自带的开发服务器并非最好的选择,推荐使用其他专业服务器 安装依赖 > pip install -r requirements.txt 迁移数据库 > python manage.py ...

    Android日程管理系统实训报告.doc

    安卓项目演习开发实训 —基于Android的日程管理系统设计与开发 (2016/6/6—2016/6/23) ... 1、优化小贴士:在主体中打开你的应用,点击小贴士,会得到这样的建议:为你的 应用开发平板电脑版本。 2、应用翻译服务:允

    python项目深度学习的web端多格式纠错系统.zip

    3. **实时纠错**:在用户输入时即时检测错误并提供修改建议。 4. **用户界面**:如果包含用户界面,则允许用户上传文件、查看纠错结果和编辑内容。 5. **API接口**:为其他应用或服务提供纠错功能的接口。 6. **自...

    sqltoy-orm框架系统-其他

    4、最强大的分页查询:很多人第一次了解到何为快速分页、分页优化这种极为巧妙的处理,还有在count语句上的极度优化。 5、跨数据库函数方言替换,如:isnull/ifnull/nvl、substr/substring 等不同数据库。 sqltoy-...

    labelmx条码标签设计软件3.6新版发布

    1.文本文件 2.EXCEL表格 3.Access数据库 4.Dbf数据库 5.Edb数据库 6.MySQL数据库 7.SQLServer数据库 8.Oracle数据库 9.Sqlite数据库 10.IBM DB2数据库 *专业用户还可以通过“自定义连接”连接任意数据库。 ★.支持...

    laravel5.3_source:laravel5.3源码分析

    该目录可能也会包含一个缓存目录,其中会包含框架为优化性能而生成的一些文件,如路由及服务的缓存文件 ###### Config目录 config目录,包含了应用所有的配置文件。阅读所有的这些文件并熟悉所有的配置项,对你来说...

Global site tag (gtag.js) - Google Analytics