dbTalk Databases Forums  

Consistent update of InnoDB tables

mailing.database.mysql-java mailing.database.mysql-java


Discuss Consistent update of InnoDB tables in the mailing.database.mysql-java forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Filip Rachunek
 
Posts: n/a

Default Consistent update of InnoDB tables - 07-07-2004 , 08:37 AM






Hello,
I am using Connector/J [latest stable version] with MySQL 4.0.18 and InnoDB
tables.
My application occasionally performs such sequence of commands:

Connection con = pool.getConnection();
con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.executeUpdate("update my_table set counter = counter + 1 where id = " +
id);
....
con.commit();

Is it possible that when this code snippet is performed by several threads
at once, the "counter" increment is not done correctly? Because it is what
happens to some rows of that table. Transaction isolation should be
repeatable_read, as it is default for InnoDB. Or do I have to execute
"select for update" first?

Thanks for all hints.
Filip

__________________________________________________ _______________
Ziskejte uzitecneho a rychleho pomocnika pro hledani na internetu – MSN
Toolbar. http://toolbar.msn.cz/?DI=393&XAPID=2170


--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Dennis T
 
Posts: n/a

Default Re: Consistent update of InnoDB tables - 07-12-2004 , 11:35 AM






hi filip,
"counter +1" code needs to be done under mutex/ sync_block in a multi
threaded app,
and has nothing to do with the database isolation type.
-dennis

On Jul 7, 2004, at 6:38 AM, Filip Rachunek wrote:

Quote:
Hello,
I am using Connector/J [latest stable version] with MySQL 4.0.18 and
InnoDB tables.
My application occasionally performs such sequence of commands:

Connection con = pool.getConnection();
con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.executeUpdate("update my_table set counter = counter + 1 where id
= " + id);
...
con.commit();

Is it possible that when this code snippet is performed by several
threads at once, the "counter" increment is not done correctly?
Because it is what happens to some rows of that table. Transaction
isolation should be repeatable_read, as it is default for InnoDB. Or
do I have to execute "select for update" first?

--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=my...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.