When to LOCK TABLES in MySQL (MyISAM tables)?
Is the internal locking of MySQL sufficient for a small to medium sized website? My tables are MyISAM. There might be a few hundred people concurrently hitting a specific table with SELECT'S and INSERT's. None of the INSERT/开发者_如何学编程UPDATE queries would overlap. That is, no two users will be updating the same comment ID. INSERT's/UPDATE's would be one-off operations---there would be no reading of data and performing additional operations within the same query.
Specifically, I am setting up a comment/chat system for my website. At worst, there might be a couple of hundred people performing a SELECT statement on the comment/chat tables in order to read new posts. With respect to INSERT's, there might be 100(?) different people trying to INSERT a new comment at any time.
I found this article in another question on SO, and it states that LOCK TABLES is "never required for self-contained insert, update, or delete operations." Is this good practice for the amount of DB traffic that I might have? TIA for any advice.
The only form of locking MyISAM tables is table locks. The idea is that they designed it to be way-fast enough that no one else should need access while it works. Right - YMM definitely V. But for most small-to-medium-size websites, it's fine. For intance, that's what WordPress uses.
Locking is probably only something you need to worry about if rows are being viewed and edited at the same time. Don't worry about locking for what you're doing - it's not only good practice to do so, using locks here would hurt performance.
精彩评论