0

Building on the query in this answer (please note/assume that the GROUP_CONCATs are now also held in user defined variables), when and what will InnoDB lock on table1?

I'd prefer that it only lock the table1 row that it's currently updating and release it upon starting on the next row.

I'd also prefer that when it locks table2 (or its' rows) that SELECTs will at least be able to read it.

The column being updated is not PK or even indexed.

How can this be achieved, or is it already doing that?

This is in a TRIGGER.

Many thanks in advance!

Community
  • 1
  • 1

1 Answers1

1

The lock is held for the entire transaction (as the operation is atomic, this means that either all of the rows are updated or no rows) and you can't change that (without changing the storage engine). However it does not block reads (unless you are in SEIALIZABLE isolation level), so SELECT queries will be executed, but they will read the old values. Only SELECT FOR UPDATE and SELECT...LOCK IN SHARE MODE will be blocked by an update.

Maxim Krizhanovsky
  • 26,265
  • 5
  • 59
  • 89
  • Thank-you for answering! So since I'm updating all of `table1` in one query, every row will be locked until the query is done? If I break this up as a `CURSOR` loop and since it's in a `TRIGGER`, will it release each `table1` as each query is finished? Thanks again! –  Jan 08 '13 at 19:22