improved write performance of SQLite db
This commit is contained in:
parent
5d8d81a237
commit
efced9bb87
|
@ -103,7 +103,12 @@ static void dbCb(const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason,
|
||||||
fName+=".txdb";
|
fName+=".txdb";
|
||||||
remove(fName.c_str());
|
remove(fName.c_str());
|
||||||
db.open(fName.c_str());
|
db.open(fName.c_str());
|
||||||
// scv_out << "TB Transaction Recording has started, file = " << my_sqlite_file_name << endl;
|
// performance related according to http://blog.quibb.org/2010/08/fast-bulk-inserts-into-sqlite/
|
||||||
|
db.exec("PRAGMA synchronous=OFF");
|
||||||
|
db.exec("PRAGMA count_changes=OFF");
|
||||||
|
db.exec("PRAGMA journal_mode=MEMORY");
|
||||||
|
db.exec("PRAGMA temp_store=MEMORY");
|
||||||
|
// scv_out << "TB Transaction Recording has started, file = " << my_sqlite_file_name << endl;
|
||||||
db.exec("CREATE TABLE IF NOT EXISTS " STREAM_TABLE "(id INTEGER NOT NULL PRIMARY KEY, name TEXT, kind TEXT);");
|
db.exec("CREATE TABLE IF NOT EXISTS " STREAM_TABLE "(id INTEGER NOT NULL PRIMARY KEY, name TEXT, kind TEXT);");
|
||||||
db.exec("CREATE TABLE IF NOT EXISTS " GENERATOR_TABLE "(id INTEGER NOT NULL PRIMARY KEY, stream INTEGER REFERENCES " STREAM_TABLE "(id), name TEXT, begin_attr INTEGER, end_attr INTEGER);");
|
db.exec("CREATE TABLE IF NOT EXISTS " GENERATOR_TABLE "(id INTEGER NOT NULL PRIMARY KEY, stream INTEGER REFERENCES " STREAM_TABLE "(id), name TEXT, begin_attr INTEGER, end_attr INTEGER);");
|
||||||
db.exec("CREATE TABLE IF NOT EXISTS " TX_TABLE "(id INTEGER NOT NULL PRIMARY KEY, generator INTEGER REFERENCES " GENERATOR_TABLE "(id), stream INTEGER REFERENCES " STREAM_TABLE "(id), concurrencyLevel INTEGER);");
|
db.exec("CREATE TABLE IF NOT EXISTS " TX_TABLE "(id INTEGER NOT NULL PRIMARY KEY, generator INTEGER REFERENCES " GENERATOR_TABLE "(id), stream INTEGER REFERENCES " STREAM_TABLE "(id), concurrencyLevel INTEGER);");
|
||||||
|
@ -111,6 +116,7 @@ static void dbCb(const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason,
|
||||||
db.exec("CREATE TABLE IF NOT EXISTS " TX_ATTRIBUTE_TABLE "(tx INTEGER REFERENCES " TX_TABLE "(id), type INTEGER, name TEXT, data_type INTEGER, data_value TEXT);");
|
db.exec("CREATE TABLE IF NOT EXISTS " TX_ATTRIBUTE_TABLE "(tx INTEGER REFERENCES " TX_TABLE "(id), type INTEGER, name TEXT, data_type INTEGER, data_value TEXT);");
|
||||||
db.exec("CREATE TABLE IF NOT EXISTS " TX_RELATION_TABLE "(name TEXT, src INTEGER REFERENCES " TX_TABLE "(id), sink INTEGER REFERENCES " TX_TABLE "(id));");
|
db.exec("CREATE TABLE IF NOT EXISTS " TX_RELATION_TABLE "(name TEXT, src INTEGER REFERENCES " TX_TABLE "(id), sink INTEGER REFERENCES " TX_TABLE "(id));");
|
||||||
db.exec("CREATE TABLE IF NOT EXISTS " SIM_PROPS "(time_resolution INTEGER);");
|
db.exec("CREATE TABLE IF NOT EXISTS " SIM_PROPS "(time_resolution INTEGER);");
|
||||||
|
db.exec("BEGIN TRANSACTION");
|
||||||
queryBuilder.str("");
|
queryBuilder.str("");
|
||||||
queryBuilder << "INSERT INTO " SIM_PROPS " (time_resolution) values ("
|
queryBuilder << "INSERT INTO " SIM_PROPS " (time_resolution) values ("
|
||||||
<< (long)(sc_get_time_resolution().to_seconds()*1e15) << ");";
|
<< (long)(sc_get_time_resolution().to_seconds()*1e15) << ");";
|
||||||
|
@ -121,7 +127,8 @@ static void dbCb(const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason,
|
||||||
break;
|
break;
|
||||||
case scv_tr_db::DELETE:
|
case scv_tr_db::DELETE:
|
||||||
try {
|
try {
|
||||||
// scv_out << "Transaction Recording is closing file: " << my_sqlite_file_name << endl;
|
// scv_out << "Transaction Recording is closing file: " << my_sqlite_file_name << endl;
|
||||||
|
db.exec("COMMIT TRANSACTION");
|
||||||
db.close();
|
db.close();
|
||||||
} catch (SQLiteDB::SQLiteException& e) {
|
} catch (SQLiteDB::SQLiteException& e) {
|
||||||
_scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL, "Can't close recording file");
|
_scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL, "Can't close recording file");
|
||||||
|
@ -365,4 +372,3 @@ void scv_tr_sqlite_init() {
|
||||||
scv_tr_handle::register_relation_cb(relationCb);
|
scv_tr_handle::register_relation_cb(relationCb);
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue