can sqlite load 10M data into the memory

前端 未结 2 1243
孤街浪徒
孤街浪徒 2021-02-05 06:35

If it\'s possible, how ?

I want to speed up the readings (not writings) in sqlite

Thanks

相关标签:
2条回答
  • 2021-02-05 07:04

    Note, that the page size had been increased to 4096 bytes starting from sqlite version 3.12.0

    https://www.sqlite.org/pragma.html#pragma_page_size

    0 讨论(0)
  • 2021-02-05 07:20

    Yes.

    SQLite loads data into memory in pages. The default page size is 1024 bytes. You can change the page size using this command.

    PRAGMA page_size = bytes;
    

    But you have to do this before you create the database (or in 3.5.8, you can change it by running a VACUUM after issuing the new page size pragma).

    The cache is based on number of pages. The default cache size is 2000 pages. You can change it using this command.

    PRAGMA cache_size = Number-of-pages;
    

    So to store 10MB of data in memory, either increase the page size to 5120 or increase the cache size to 10000.

    More info on pragmas is here.

    0 讨论(0)
提交回复
热议问题