Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does one do table locking? #287

Closed
charl opened this issue Nov 12, 2014 · 5 comments
Closed

How does one do table locking? #287

charl opened this issue Nov 12, 2014 · 5 comments
Labels

Comments

@charl
Copy link

charl commented Nov 12, 2014

This example illustrates what looks like the driver stalling when one uses locking on tables.

If one manually executes the SQL in the mysql client there are no issues.

Is there some special way table locking is handled in the driver that I am not using int he example?

@charl
Copy link
Author

charl commented Nov 12, 2014

When you run the example the code seems to lock when trying to execute:

INSERT INTO bar SELECT * FROM foo

Which was right after tables foor/bar were locked with:

LOCK TABLE foo WRITE, bar WRITE

@xaprb
Copy link

xaprb commented Nov 12, 2014

The issue here is that you are running those queries on different
connections. One connection locks, another one tries to insert. Use a
transaction to bind everything to a single connection. Better yet, don't
use LOCK TABLES :-P

@arnehormann
Copy link
Member

@charls it's exactly as @xaprb says 😀 ... I think everyone hits this once.
Thanks for opening an issue in go-database-sql-tutorial!

@hokadiri
Copy link

hokadiri commented Nov 5, 2021

Using a transaction poses its own challenges see:
#1280

TLDR: Using a transaction, one should end it with a commit or rollback.
Doing locking, one has to Lock table then Unlock table. Unlock table implicitly does a commit which conflicts with Tx.commit

@ghost
Copy link

ghost commented Jan 19, 2023

@hokadiri have you found any solution to the challenge you mentioned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants