Today, we chatted with each other about the InnoDB engine. They asked me for a lot of things I don't know, but they even got the lock. I still know this, so I just said: if indexes are used in the MyISAM engine, row locks are applied and the obtained results are index tables. If indexes are not used, table locks are applied. I thought it was awesome, but I also asked how I knew it. I said I care about what I saw on the blog. Just now, I feel that it is not convincing. Then I said: I seem to have read it in the MySQL help document (but I have never seen it ). The boss said: The help document is not necessarily correct. The version may be modified if it is different. It is better to try it.
Indeed, I thought about what I learned, but it is estimated that 80% of them are from the Internet blog. Even official documents may have version problems and slight changes. Except for some code, I do not have time for this kind of knowledge. Buy it first and I will try it out for you.
First, you need to open two MySQL windows.
Create a table with two fields, one of which is set as index and the other is not:
Then add the data:
Now let's start things and update them to understand:
Then update in another window
But it's already deadlocked. We don't know what we can do in the first window of commit.
Then we try to update other options:
No problem, so it is a row lock, not a table lock. Then, we don't need to use ID for conditions.
It can be seen that this is a table lock without an index. Haha, although it is very simple, I would like to say: it is estimated that this is the first practical knowledge except code.