Equivalent of TMyLoader for UPDATE

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Equivalent of TMyLoader for UPDATE

Post by GuzunNicolae » Thu 22 Nov 2007 11:47

Hello

Thank you very much for your previous help.
But I have a small question now.

As I know TMyLoader is used to insert very fast tables into mysql.
Is there any equivalent to speed up a lot of UPDATE statements? Now I am using a simple TMyCommand. So each time I need to do the update I say "UPDATE table SET fiel1=:value WHERE id = :primarykey". I tried to use TMyScript hoping that it will be very fast, but it is the same TMyCommand, it executes the queries one by one.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 22 Nov 2007 14:52

MySQL lets inserting several records with a single INSERT statement. TMyLoader uses this possibility.
But there is no possibility to do the same for UPDATE statements.

To increase performance you can try to use preparation or execute several statements at the same time with TMyCommand. Also take a look at he "Increasing performance" topic in MyDAC help.

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Re: Equivalent of TMyLoader for UPDATE

Post by eduardosic » Thu 22 Nov 2007 16:13

GuzunNicolae wrote:Hello

Thank you very much for your previous help.
But I have a small question now.

As I know TMyLoader is used to insert very fast tables into mysql.
Is there any equivalent to speed up a lot of UPDATE statements? Now I am using a simple TMyCommand. So each time I need to do the update I say "UPDATE table SET fiel1=:value WHERE id = :primarykey". I tried to use TMyScript hoping that it will be very fast, but it is the same TMyCommand, it executes the queries one by one.
Try this to increase Update/Insert with any Component

SET AUTOCOMMIT=0;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
COMMIT;

it's work very fast.

GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Re: Equivalent of TMyLoader for UPDATE

Post by GuzunNicolae » Thu 22 Nov 2007 17:29

eduardosic wrote:
GuzunNicolae wrote:Hello

Thank you very much for your previous help.
But I have a small question now.

As I know TMyLoader is used to insert very fast tables into mysql.
Is there any equivalent to speed up a lot of UPDATE statements? Now I am using a simple TMyCommand. So each time I need to do the update I say "UPDATE table SET fiel1=:value WHERE id = :primarykey". I tried to use TMyScript hoping that it will be very fast, but it is the same TMyCommand, it executes the queries one by one.
Try this to increase Update/Insert with any Component

SET AUTOCOMMIT=0;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
COMMIT;

it's work very fast.
Thank you.
But I found the following
START TRANSACTION;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
COMMIT;

It works 100 times faster :p. I am very happy :D

How is START TRANSACTION different than AUTOCOMIT =0 ?

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Re: Equivalent of TMyLoader for UPDATE

Post by eduardosic » Thu 22 Nov 2007 17:37

GuzunNicolae wrote:
eduardosic wrote:
GuzunNicolae wrote:Hello

Thank you very much for your previous help.
But I have a small question now.

As I know TMyLoader is used to insert very fast tables into mysql.
Is there any equivalent to speed up a lot of UPDATE statements? Now I am using a simple TMyCommand. So each time I need to do the update I say "UPDATE table SET fiel1=:value WHERE id = :primarykey". I tried to use TMyScript hoping that it will be very fast, but it is the same TMyCommand, it executes the queries one by one.
Try this to increase Update/Insert with any Component

SET AUTOCOMMIT=0;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
COMMIT;

it's work very fast.
Thank you.
But I found the following
START TRANSACTION;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
UPDATE TableName Set Field=value where Key=XX;
COMMIT;

It works 100 times faster :p. I am very happy :D

How is START TRANSACTION different than AUTOCOMIT =0 ?
Good notice!!

setting SET FOREIGN_KEY_CHECKS=0; increase a speed of Inser/Update

Post Reply