Last active
March 9, 2016 06:57
-
-
Save ilake/f163ccf349fdc288e009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When you use select * for update, other process only could touch the query when it be `committed` | |
# Query 1 | |
User.transaction do | |
User.find(1).groups.joins(:owner).lock.each(&:destroy) | |
end | |
User.transaction do | |
# If the groups has same owner, it will wait the query 1 | |
# If not, it will continue | |
User.find(2).groups.joins(:owner).lock.each(&:destroy) | |
end | |
# ----------------- | |
User.transaction do | |
# if the query could not find any record, it will lock whole table | |
User.where(credits: 1005).lock.first | |
sleep 60 | |
end | |
# It will hang over there | |
User.find(1653).update_columns(credits: 1003) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment