SQLProcessor slow when handle thousand record

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

Moderators: gto, EgonHugeist

Post Reply
bgzretry
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 02.03.2012, 17:24

SQLProcessor slow when handle thousand record

Post by bgzretry »

Dear Master,

Need help, I have table in mysql which has 978.828 records. When I try this script, the process is very slow (the application like hang up)

zsqlprocessor1.Clear;
zsqlprocessor1.Script.Text := 'update tbharga Set HARGA="' + inttostr(Harga) + '" where NamaRs="' + RS + '" && KODEPRODUK="' + KodeProduk + '"';
zsqlprocessor1.Execute;

How to resolve this case? because when I try to reduce the record, the process running smoothly and faster. Waiting for your reply

Regards
Bagus
jpnuage
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 02.03.2012, 11:03

Post by jpnuage »

Just a little question : why don't you use a ZQuery ? Try this perhaps

ZQuery := TZQuery;
Zquery := TZQuery.create(nil);
Zquery.SQL.Clear;
ZQuery.SQL.Add('update tbharga Set HARGA= :Harga where NamaRs=' + RS + ' && KODEPRODUK=' + KodeProduk );
ZQuery.OaralNyName ('Harga').AsInteger := Harga;
ZQuery.Active := true;
bgzretry
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 02.03.2012, 17:24

Post by bgzretry »

Hi jpnuage,

I've tried before using ZQuery, but I got error "Can not open a ResultSet"
bgzretry
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 02.03.2012, 17:24

Post by bgzretry »

Zquery1.SQL.Clear;
Zquery1.SQL.Add('update tbharga Set HARGA= :Harga where NamaRs="' + RS + '" && KODEPRODUK="' + KodeProduk + '"');
zquery1.ParamByName('Harga').AsInteger := Harga;
zquery1.ExecSQL;

I've tried above script, but still the process is very slow. Need advise
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

bgzretry,

did you tried a prepared Statement too?
Var
PrepStatement: IZPreparedStatement;
begin

PrepStatement := ZConnection.DbcConnection.PrepareStatement('update tbharga Set HARGA= :Harga where NamaRs=' + RS + ' && KODEPRODUK=' + KodeProduk ');
PrepStatement.Prepare;
PrepStatement.SetInt(0, Harga);

for I := 1 to Your.Count-1 do
begin
PrepStatement.SetInt(0, Harga);
....
end;

You can also use Batch-scripts with a TIntegerDynArray.

You can find all definitions in the ZDbcIntfs.pas

best regards
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

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

Post by mdaems »

bgzretry,
The only way to improve the performance is checking if the update statements use indexes.
Also, when NamaRs is a number field you shouldn't use quotes around the parameter in your query as they may make it impossible for the database server to use indexes.

Mark
Image
Post Reply