How to optimize this codding

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
andresayang
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.01.2009, 09:20

How to optimize this codding

Post by andresayang »

Hi

With delphi 2007, i have lot of Insert commands to execute
I do something like this:

var
Connection: IZConnection;
Statement: IZStatement;

...

Statement:= Connection.CreateStatement;
Statement.ExecuteQuery(sqltosend.Text);
Statement.Close;

...

sqltosend is a StringList containing more or less 80 000 Insert query !

How to configure the Connection and the Statement to have this command the fastest as possible ?
(I mean autocommit, and all other parameters)

Thanks a lot
WorldWalker
Junior Boarder
Junior Boarder
Posts: 25
Joined: 10.10.2009, 18:57

Post by WorldWalker »

Hi,
Did you try ZSQLProcessor?
andresayang
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.01.2009, 09:20

Post by andresayang »

Hi, I will have a look !

The thing is that my code was quite simple at the beginning: Backup one database and restore the backup inside another one.

But now, the app is doing more and more and I only adapted the fisrt codding and would like to preserve it (to do not rebuild all from 0).

Thanks
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

andresayang,

I'm afraid you have the most optimal setting when sending the sql stringlist as one statement. Normally, even with autocommit, there's only one commit in your case.
You could consider splitting the script into smaller blocks with a commit in between if too big transactions slow down your database server, but I think that depends on the server you're using.

Mark
Image
andresayang
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.01.2009, 09:20

Post by andresayang »

Thanks mdaems

I have notice that if I send a sql stringlist containing 2 files at the same time (ie 160 000 inserts), it is faster than sending them separately. That was why I was asking if there was any parameters to change to increase the speed.
manz
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 02.06.2008, 03:58
Location: Cilegon
Contact:

Post by manz »

dear andresayang

you may optimize your mysql server configuration to handling it with the good chosen engine ... such as InnoDB.

Manz
andresayang
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.01.2009, 09:20

Post by andresayang »

manz wrote:dear andresayang

you may optimize your mysql server configuration to handling it with the good chosen engine ... such as InnoDB.

Manz
Sorry, I am working with Postgres !

But I started with Zeoslib, my small soft is working perfectly for what i want to do with it.
The normal way of working is with Stringlist containing around 500 insert queries, so It is not "so slow". I have the soft and a database on my laptop for development and what I do with it is not exactly the "normal way" of working, so I have bigger file to Import / Exports (much more easy to optimize the code for speed when working on huge files).

I only wanted to have a small explanation on what effect of the connection parameters on the speed of the transactions.

Rgds
niztor
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 04.11.2005, 19:05

Post by niztor »

I think the most important parameter for speed is Autocommit. if you set Autocommit := True every insert statement you execute starts its own transaction, so the database need to setup a transaction enviroment for every statement. Setting Autocommit:= False before the bulk insert implies just one transaction for the database.
Using triggers on tables is another source of delay on bulk inserts.
if you didn't do yet, please check postgres manual for transactions and triggers topics.

sorry my poor english X)
andresayang
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.01.2009, 09:20

Post by andresayang »

Thanks,

I will check if i can disable some triggers. For Autocommit, I have found this already and it is set to false.

I have to read Postgres doc (I already read lot of it to learn SQL language).

Rgds
Post Reply