No Read or Write between INSERT and UPDATE



I am using mysql with the InnoDB engine. I wrote a perl script that
first selects something from a table, and then updates a second table
based on the select from the first table. I need to make sure that
there is no read or write to the tables while my script performs the
insert and update.

I looked at <http://dev.mysql.com/doc/refman/4.1/en/lock-tables.html>
and it says this:

-----------------------------------------------------------------------------------------------------------------------------------
If you are using a storage engine in MySQL that does not support
transactions, you must use LOCK TABLES if you want to ensure that no
other thread comes between a SELECT and an UPDATE. The example shown
here requires LOCK TABLES to execute safely:

LOCK TABLES trans READ, customer WRITE;
SELECT SUM(value) FROM trans WHERE customer_id=some_id;
UPDATE customer
SET total_value=sum_from_previous_statement
WHERE customer_id=some_id;
UNLOCK TABLES;

Without LOCK TABLES, it is possible that another thread might insert a
new row in the trans table between execution of the SELECT and UPDATE
statements.
-----------------------------------------------------------------------------------------------------------------------------------

However, I am using InnoDB and it DOES support transaction. So, does
that mean that even if I don't lock my table, will still work? If not,
what do I need to do?

.



Relevant Pages

  • Synchronization between 2 PHP threads?
    ... I am developping a web-based PHP application, ... Increment TableA counter ... MySQL to perform the locking, but am not quite sure what my syntax would be. ... Would a MySQL Write lock on Table A prevent another thread ...
    (comp.lang.php)
  • Re: Concurrency Question
    ... Use flock() in the code to lock a semaphore file. ... Use LOCK TABLES in mysql. ... type that does not support transactions, ...
    (comp.lang.php)
  • Re: Fine grain select locking.
    ... I don't know that I'd call mysql a micro-benchmark. ... contention on the proc lock. ... greater time spent doing other things than lock waits). ... We might be able to obtain some further improvement at higher loads by ...
    (freebsd-arch)
  • Re: [PHP] Re: Getting last record ID created from DB
    ... increment auto id fields (e.g. they could fill in the blanks from ... My own knowledge of mysql is about 5 years old and never really used. ... transferrable to other database engines. ... the lock once the Id is retrieved using any of these methods. ...
    (php.general)
  • Re: Mod python - mysql lock
    ... If you use MySQL 5, ... "LOCK" thing is becoming obsolete. ... table card in which unique cards are stored. ... "LOCK" command of mysql through python code, but it is not locking the ...
    (comp.lang.python)