Subject | Re: [IBO] Optimizing TIBOTable inserts |
---|---|
Author | Svein Erling Tysvaer |
Post date | 2006-06-29T08:51:51Z |
For batch inserts, forget TIBOTable. Use TIB_Connection, TIB_Transaction
and TIB_DSQL and link them together (IB_Connection and IB_Transaction
properties). Try code like the following (I haven't written this in
Delphi, so it is likely to contain some syntax errors).
TIB_DSQL1.Sql.Clear;
TIB_DSQL1.Sql.Add('DROP TABLE MyTable');
TIB_DSQL1.Execute;
TIB_Transaction1.Commit;
TIB_DSQL1.Sql.Clear;
TIB_DSQL1.Sql.Add('CREATE TABLE MyTable (S1 CHAR(20), T1 DATETIME)');
TIB_DSQL1.Execute;
TIB_Transaction1.Commit;
TIB_DSQL1.Sql.Clear;
TIB_DSQL1.Sql.Add('INSERT INTO MyTable (S1, T1) VALUES (:P1, :P2);
TIB_DSQL1.Prepare;
startTime:=Now;
for i:=0 to 43000 do
begin
TIB_DSQL1.Params[0].AsString:=IntToStr(i);
TIB_DSQL1.Params[1].AsDateTime:=Now;
TIB_DSQL1.Execute;
end;
TIB_Transaction1.Commit;
Beep;
DateTimeToString(s, 'h:m:s', Now-startTime);
ShowMessage(s)
//Then you can open your table if you want.
I guess this should get the looping time down to about 6-7 seconds.
Though don't forget that Firebird is a client/server database, it can
never compete with Paradox (except in ACID terms) if used like a desktop
database (thinking tables rather than datasets).
HTH,
Set
kgdonn wrote:
and TIB_DSQL and link them together (IB_Connection and IB_Transaction
properties). Try code like the following (I haven't written this in
Delphi, so it is likely to contain some syntax errors).
TIB_DSQL1.Sql.Clear;
TIB_DSQL1.Sql.Add('DROP TABLE MyTable');
TIB_DSQL1.Execute;
TIB_Transaction1.Commit;
TIB_DSQL1.Sql.Clear;
TIB_DSQL1.Sql.Add('CREATE TABLE MyTable (S1 CHAR(20), T1 DATETIME)');
TIB_DSQL1.Execute;
TIB_Transaction1.Commit;
TIB_DSQL1.Sql.Clear;
TIB_DSQL1.Sql.Add('INSERT INTO MyTable (S1, T1) VALUES (:P1, :P2);
TIB_DSQL1.Prepare;
startTime:=Now;
for i:=0 to 43000 do
begin
TIB_DSQL1.Params[0].AsString:=IntToStr(i);
TIB_DSQL1.Params[1].AsDateTime:=Now;
TIB_DSQL1.Execute;
end;
TIB_Transaction1.Commit;
Beep;
DateTimeToString(s, 'h:m:s', Now-startTime);
ShowMessage(s)
//Then you can open your table if you want.
I guess this should get the looping time down to about 6-7 seconds.
Though don't forget that Firebird is a client/server database, it can
never compete with Paradox (except in ACID terms) if used like a desktop
database (thinking tables rather than datasets).
HTH,
Set
kgdonn wrote:
> I'd like to know what the right set of flags would be to make the
> following code go as fast as possible. The only real constraint
> that I have is that I must use a TIBOTable, although I would like to
> hear what alternatives could be made to run even faster.
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
> i: integer;
> startTime: TDateTime;
> s: string;
> begin
> IBODatabase1.Open;
> try IBOTable1.DeleteTable except end;
> IBOTable1.FieldDefs.Add('S1', ftString, 20);
> IBOTable1.FieldDefs.Add('T1', ftDateTime);
> IBOTable1.CreateTable;
> IBOTable1.Open;
> startTime:=Now;
> for i:=0 to 43000 do
> IBOTable1.InsertRecord([IntToStr(i), Now]);
> Beep;
> DateTimeToString(s, 'h:m:s', Now-startTime);
> ShowMessage(s)
> end;
>
> Thanks,
> Kevin Donn