#1 mORMot 1 » 2001 times faster inserts » 2012-11-06 23:39:08

richardmaley
Replies: 1

I wish to report a dramatic increase in performance inserting records into Sqlite3 tables.

I have 81 tables with more than 200 million records that I was attempting to insert.

I attempted to insert 263000 records last night for 9 hours and the process was less than half done.

I was using Conn.Synchronous:=smFull and I was not using transactions.

Additionally, I was suffering a significant memory leak from Query: TSQLDBStatement.

Changing Conn.Synchronous:=smFull to Conn.Synchronous:=smOff and using conn.StartTransaction; and Conn.Commit; every 10000 records dramatically improved performance.

However, the memory leak continued until the application crashed.

The source of the memory leak was the Query: TSQLDBStatement.

I modified my code so that every use of Query looked like this:
        Query := Conn.NewStatement;
        Try
          Query.Execute(sgSQL, False);
        Finally
          FreeAndNil(Query);
        End;
The memory leaks completely disappeared.

The net result was the new code was 2001 times faster and there were no memory leaks.

Dick Maley

#2 mORMot 1 » Fastest Import of tab delimited data into Sqlite3 Table » 2012-11-06 01:03:12

richardmaley
Replies: 1

Having analyzed the tab delimited data and created an appropriate Sqlite3 table what is the fastest way of populating the table?

I have been looping through the creation of insert statements, however it is slow.

What is the fastest.

Thank you.

Richard Maley

#3 Re: mORMot 1 » How to create an empty Sqlite3 DB » 2012-11-05 19:59:57

Modifying my original code as follows does create the empty table.

procedure TForm3.FormCreate(Sender: TObject);
Var
  aServerName: RawUTF8;
  aDatabaseName: RawUTF8;
  aUserID: RawUTF8;
  aPassWord: RawUTF8;
  Conn: TSQLDBSQLite3Connection;
begin
  aServerName:=DirDB+'Sqlite3201211051120.db3';
  ShowMessage(aServerName);
  aDatabaseName:='';
  aUserID:='';
  aPassWord:='';
  DB:=TSQLDBSQLite3ConnectionProperties.Create(aServerName,aDatabaseName,aUserID,aPassWord);
  DB.UseMormotCollations := False;
  Conn := DB.MainConnection as TSQLDBSQLite3Connection;
  Conn.Connect;
end;

Thank you for your reply.

Richard Maley

#4 mORMot 1 » How to create an empty Sqlite3 DB » 2012-11-05 19:14:43

richardmaley
Replies: 3

I am trying to create an empty Sqlite3 database by using TSQLDBSQLite3ConnectionProperties.  Not errors are thrown and no database is created.

How should I do this?

procedure TForm3.FormCreate(Sender: TObject);
Var
  aServerName: RawUTF8;
  aDatabaseName: RawUTF8;
  aUserID: RawUTF8;
  aPassWord: RawUTF8;
begin
  aServerName:=DirDB+'Sqlite3201211051120.db3';
  aDatabaseName:='';
  aUserID:='';
  aPassWord:='';
  DB:=TSQLDBSQLite3ConnectionProperties.Create(aServerName,aDatabaseName,aUserID,aPassWord);
end;

Thank you.

Richard Maley

Board footer

Powered by FluxBB