简体   繁体   English

sqlite3数据库加载到内存C ++并选择性能

[英]sqlite3 database load to memory c++ and select perfomance

Is there any method to load sqlite3 database file from disk into memory before make any SELECTS on it? 在对其进行任何SELECTS之前,是否有任何方法可以将sqlite3数据库文件从磁盘加载到内存中? sqlite3_step() work really slow... So I want to load database into the memory to load the data quickly. sqlite3_step()工作速度非常慢...因此,我想将数据库加载到内存中以快速加载数据。

Before sqlite3 I use simple binary data serialization and all members of stackoverflow suggested to me to use sqlite3 for serialization and now my program is really slow.. so slow that I can not unserialize all my data. 在sqlite3之前,我使用简单的二进制数据序列化,所有stackoverflow成员建议我使用sqlite3进行序列化,现在我的程序确实很慢..太慢了,无法对所有数据进行反序列化。 (Serialization work well with transactions) (序列化可以很好地与事务配合使用)

Maybe also this will help. 也许这也会有所帮助。 my SELECT : there are two selects and two sqlite3_step() on each unserialized object. 我的SELECT :每个未序列化的对象上都有两个select和两个sqlite3_step() queries looks like SELECT aaaa,bbb,ccc,ddd,eee,ggg,hhh,fff,jjj FROM table for two queries. 查询看起来像SELECT aaaa,bbb,ccc,ddd,eee,ggg,hhh,fff,jjj FROM table中的两个查询。 First table with unique aaaa key, but second one not unique (so seems its without indexes at all) 第一个表具有唯一的aaaa键,但第二个表则不是唯一的(因此似乎完全没有索引)

UPDATE: 更新:

    // Create SQL statement
    std::string sql_createtable = "CREATE TABLE IF NOT EXISTS ssssssss(" \
        "sid INTEGER PRIMARY KEY     NOT NULL," \
        "last_access_time       INT     ," \
        "last_c_time        INT     ," \
        "total_c           INT     ," \
        "last_viewed_lid INT ," \
        "last_viewed_ltid INT     );";  
//      "showed TEXT     );";

    std::string sql_showed = "CREATE TABLE IF NOT EXISTS showed(" \
        "sid              INT     NOT NULL," \
        "rid              INT     ," \
        "lid         INT     ," \
        "ltid           INT         );";    

Select 1: 选择1:

SELECT sid, last_access_time, last_c_time, total_c, last_viewed_lid, last_viewed_ltid FROM ssssss

Select 2: 选择2:

"SELECT rid, lid, ltid FROM showed WHERE sid= ?1"; // sid is from first table. can be more than 1 the same sid

Hmm, seems the problem that sid at the second table showed is not unique and no index? 嗯,似乎第二张桌子上的sid showed的问题不是唯一且没有索引? How to add index to this statement ? 如何在此语句中添加索引?

Maybe some other suggestions? 也许还有其他建议?

You want to add index. 您要添加索引。 Since the column is not unique, you need to add it with separate command: 由于该列不是唯一的,因此需要使用单独的命令添加它:

CREATE INDEX showed_sid ON showed (sid);

Just execute this right after creating the table. 只需在创建表后立即执行此操作即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM