Connecting Tech Pros Worldwide Help | Site Map

InnoDB autocommit and locks

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:52 PM
Marcus
Guest
 
Posts: n/a
Default InnoDB autocommit and locks

Hello,

I have 2 questions regarding InnoDB tables:

1. In the MySQL manual, it states that
"MySQL begins each client connection with autocommit mode enabled by
default. When autocommit is enabled, MySQL does a commit after each SQL
statement if that statement did not return an error."

Does using BEGIN override this behavior? In other words, with
autocommit on, does BEGIN open up a new transaction and stop committing
until an explicit COMMIT command? Or do I need to turn autocommit off
before multi-query transactions?

2. I have been reading the examples for LOCK IN SHARE MODE and FOR
UPDATE in the manual, but I am still confused as to when I should use
one as opposed to the other. I have gone through tutorials but many
just use the same examples as the manual. I'm sure I'm just missing
something small, but if someone could give a simple example of the
difference between the two, that would be very helpful as the difference
to me seems very suttle.

Thanks in advance.

  #2  
Old July 17th, 2005, 12:53 PM
Bent Stigsen
Guest
 
Posts: n/a
Default Re: InnoDB autocommit and locks

Marcus wrote:[color=blue]
> Hello,
>
> I have 2 questions regarding InnoDB tables:
>
> 1. In the MySQL manual, it states that
> "MySQL begins each client connection with autocommit mode enabled by
> default. When autocommit is enabled, MySQL does a commit after each SQL
> statement if that statement did not return an error."
>
> Does using BEGIN override this behavior? In other words, with
> autocommit on, does BEGIN open up a new transaction and stop committing
> until an explicit COMMIT command? Or do I need to turn autocommit off
> before multi-query transactions?[/color]

Perhaps you are looking in another manual. The official online manual is
rather clear on that.
http://dev.mysql.com/doc/mysql/en/in...utocommit.html
[quote]
If the connection has autocommit enabled, the user can still perform a
multiple-statement transaction by starting it with an explicit START
TRANSACTION or BEGIN statement and ending it with COMMIT or ROLLBACK.
[end quote]

So, yes, yes and no.

[color=blue]
> 2. I have been reading the examples for LOCK IN SHARE MODE and FOR
> UPDATE in the manual, but I am still confused as to when I should use
> one as opposed to the other. I have gone through tutorials but many
> just use the same examples as the manual. I'm sure I'm just missing
> something small, but if someone could give a simple example of the
> difference between the two, that would be very helpful as the difference
> to me seems very suttle.[/color]

Not sure what examples would be better than the ones in the manual, they
are probably as good as they get. I assume you read this page:
http://dev.mysql.com/doc/mysql/en/in...ing-reads.html

It is not the real/whole story, but perhaps it is easier if you see it
like:..
"FOR UPDATE" is used when you have the intention of updating the rows in
the table you select from, and "LOCK IN SHARE MODE" is used when they
(the selected rows) just are needed for an update elsewhere, and reading
can be shared by many.


/Bent
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.