加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何提升sqlite中blob数据的查询性能

发布时间:2020-12-12 19:35:30 所属栏目:百科 来源:网络整理
导读:关于sqlite的blob数据存储,由于暂时没有时间深入到代码内部去进行详细分析。 看到sqlite官网上有类似的测试数据和对比。 结论是:正常情况下,如果blob的数据量超过100kB,那么最好使用分开单独的文件来存储blob数据性能会好一点。如果非要讲Blob数据存储在
1024 1.535 1.020 0.608 0.456 0.330 0.247 0.233 2048 2.004 1.437 0.870 0.636 0.483 0.372 0.340 4096 2.261 1.886 1.173 0.890 0.701 0.526 0.487 8192 2.240 1.866 1.334 1.035 0.830 0.625 0.720 16384 2.439 1.757 1.292 1.023 0.829 0.820 0.598 32768 1.878 1.843 1.296 0.981 0.976 0.675 0.613 65536 1.256 1.255 1.339 0.983 0.769 0.687 0.609

We deduce the following rules of thumb from the matrix above:

  • A database page size of 8192 or 16384 gives the best performance for large BLOB I/O.

  • For BLOBs smaller than 100KB,reads are faster when the BLOBs are stored directly in the database file. For BLOBs larger than 100KB,reads from a separate file are faster.

Of course,your mileage may vary depending on hardware,filesystem,and operating system. Double-check these figures on target hardware before committing to a particular design.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

关于sqlite的blob数据存储,由于暂时没有时间深入到代码内部去进行详细分析。

看到sqlite官网上有类似的测试数据和对比。


结论是:正常情况下,如果blob的数据量超过100kB,那么最好使用分开单独的文件来存储blob数据性能会好一点。如果非要讲Blob数据存储在一个数据库文件中,那么增加Page Size可以在一般情况下提升性能。当然文章了说了,具体还是与硬件、文件系统、操作系统有关系。

Internal Versus External BLOBs in SQLite


If you have a database of large BLOBs,do you get better read performance when you store the complete BLOB content directly in the database or is it faster to store each BLOB in a separate file and store just the corresponding filename in the database?

To try to answer this,we ran 49 test cases with various BLOB sizes and SQLite page sizes on a Linux workstation (Ubuntu circa 2011 with the Ext4 filesystem on a fast SATA disk). For each test case,a database was created that contains 100MB of BLOB content. The sizes of the BLOBs ranged from 10KB to 1MB. The number of BLOBs varied in order to keep the total BLOB content at about 100MB. (Hence,100 BLOBs for the 1MB size and 10000 BLOBs for the 10K size and so forth.) SQLite version 3.7.8 was used.

The matrix below shows the time needed to read BLOBs stored in separate files divided by the time needed to read BLOBs stored entirely in the database. Hence,for numbers larger than 1.0,it is faster to store the BLOBs directly in the database. For numbers smaller than 1.0,it is faster to store the BLOBs in separate files.

In every case,the pager cache size was adjusted to keep the amount of cache memory at about 2MB. For example,a 2000 page cache was used for 1024 byte pages and a 31 page cache was used for 65536 byte pages. The BLOB values were read in a random order.

Database Page Size BLOB size 10k 20k 50k 100k 200k 500k 1m
    推荐文章
      热点阅读