一条 UPDATE 锁了什么
UPDATE ... WHERE 一个没索引的列 —— 这时候「行锁」还是行锁吗?
Copy the prompt, then pick a model. It plays the interviewer and asks you through it scene by scene instead of handing you the answer.
On a phone with the app installed, the system opens the app directly. Links cannot open external apps inside WeChat — open it in a browser first.
The copied text ends with the answer key the model grades you against. Don't read it yourself first — working it out on your own is the point.
「InnoDB 是行锁」这句话缺了一个前提,而那个前提正是线上「一条 UPDATE 卡死全表」最常见的原因。这一份就是去把那个前提问出来。
第三幕会让你面对一件反直觉的事:一条不存在的记录,怎么锁? 你得先自己推出「不锁住它就挡不住别人插进来」,才轮到间隙这个词出场。
全程不接受「会锁住相关的行」这种说法 —— 它会打断你:把被锁住的记录一条条列出来,还有哪些区间。
What this one drills
This prompt in the repo (the answer key is at the end of that file — you'll see it)
Have you done this one?
Sign in to mark this one as practised — next time you come back you'll see when you did it.
Notes from people who did this one
How to use this
These are learning drills: the model guides, it does not corner you. When you get stuck it first asks which layer you are stuck at (never heard of it / know it but not why / know why but cannot apply it), then decides what to give. It only explains after guiding twice, and then asks you to say it back in your own words.
It assumes MySQL / InnoDB by default — half the traps here are implementation details, and clustered indexes, back-to-the-table lookups and gap locks work differently elsewhere. PostgreSQL or anything else is fine: say so in your first message and it will follow your engine, calling out where the conclusions differ.
How to start
- Pick one, open it, copy the prompt.
- Paste it into a fresh, empty chat, and say which engine and version you use first (say nothing and it assumes MySQL 8).
- Then say nothing else and wait for its first question.
Four commands you can call out any time
跳过Move on to the next scene换个说法Explain this bit from another angle直说吧Give the full answer, then make me say it back复盘Jump straight to the wrap-up card
Three traps
- Do not read the answer key at the end first — the "what people get wrong" section is the answer to every question in the drill.
- Expect to be pushed for numbers. "A bit faster", "saves IO" gets cut off on the spot: how many rows? how many times? how many times faster? A conclusion with no number behind it is memorised.
- The moment it starts praising you, point it back at the "do not praise me" rule. Guiding is not coddling.
Start with the composite index one — it is the foundation here; "locks sit on index records" and "why is it scanning so many rows" both lean on its one-line model. If concurrency is biting you in production, start with read-modify-write instead; if queries are slow, start with the execution plan one.
Sign in to write a note.