chengkai1853
V2EX  ›  iOS

50w 调数据插入 real 要大约一个小时?

  •  
  •   chengkai1853 · Jul 11, 2016 · 3166 views
    This topic created in 3623 days ago, the information mentioned may be changed or developed.

    sqlite3 的数据库中有大约 50w 条数据,我在 ios 项目中想用 realm 做数据库,于是用 FMDB 去读,然后循环插入 realm 数据库中,我在模拟器上跑,都半个小时了,大约跑了一半。我用 ruby 在电脑上跑的时候也是蛮久的。数据库有这么慢么?看文件总大小也才 20M 左右。第一次跑 50w 级别的数据库,没想到这么慢!说下大家的情况啊

    4 replies    2016-07-12 10:39:28 +08:00
    peter999
        1
    peter999  
       Jul 11, 2016   ❤️ 1
    有批量插入的事务吗,有的话不要一条条插入,应该可以提交速度
    chengkai1853
        2
    chengkai1853  
    OP
       Jul 11, 2016
    @peter999 没有用到事务,我试试
    billlee
        3
    billlee  
       Jul 11, 2016
    批量插入时可以用 wal 模式避免每个事务 fsync 一次
    chengkai1853
        4
    chengkai1853  
    OP
       Jul 12, 2016
    @peter999 @billlee 非常感谢,事务 10000 条提交一次,基本就四分钟左右就能跑完了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2914 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 04:55 · PVG 12:55 · LAX 21:55 · JFK 00:55
    ♥ Do have faith in what you're doing.