Sqlite DB文件太大了......?

时间:2011-08-07 00:27:21

标签: c++ qt sqlite filesize

我一直在创建一个包含Sqlite和QT的85000条记录的字典文件。 sqlite的文件太大了,它是134MB,而另一个字典如MDic DB有相同的数据用sqlite创建,相同的记录是10 MB!

query.exec("PRAGMA journal_mode = MEMORY");
query.exec("PRAGMA synchronous = OFF");

Dic_entry DictionaryEntry = DictionaryInstance.readEntry();

QString definition, headword, displayedHeadWord;
query.exec("BEGIN Transaction");
int Count = 0;
while(!DictionaryEntry.headword.empty())
{
    definition = QString::fromStdString(DictionaryEntry.definition);
    definition.replace("'", "''");

    headword = QString::fromStdString(DictionaryEntry.headword);
    headword.replace("'", "''");

    displayedHeadWord = QString::fromStdString(DictionaryEntry.displayedHeadword);
    displayedHeadWord.replace("'", "''");

    string strQuery = "INSERT INTO Dictionary_Words([Definition], [HeadWord], [DisplayedHeadWord]) "
        "values('"
        + definition.toStdString() + "', '"
        + headword.toStdString() + "', '"
        + displayedHeadWord.toStdString()
        + "')";

    query.exec(QString::fromStdString(strQuery));
    if(Count == 200)
    {
        query.exec("COMMIT TRANSACTION");
        Count = 0;
    }
    Count++;

    DictionaryEntry = DictionaryInstance.readEntry();
}

query.exec("End Transaction");
query.exec("CREATE INDEX HW_idx ON [Dictionary_Words](HeadWord)");
query.exec("CREATE INDEX Def_idx ON [Dictionary_Words](Definition)");
query.exec("CREATE INDEX DHW_idx ON [Dictionary_Words](DisplayedHeadword)");
query.exec("PRAGMA auto_vacuum=FULL");
db.close();

请帮助我如何减少我的SQlite数据库文件

1 个答案:

答案 0 :(得分:0)

我无法证明这一点,但我怀疑索引是导致问题的原因。索引可以占用大量空间,而且你有三个。没有它们尝试它,看看访问是否仍然可以快速;数据库大小应该小得多。