Kacam.net

Databases

隔离级别各挡住了什么

RR 下读到余额 100,然后 UPDATE balance = balance - 10 —— 扣完是多少?

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.

它不会给你那张「四个级别 × 三种异常」的表,而是让你自己造三条时间线,把三种异常各造一次出来。造得出来,那张表就不用背了。

第三幕是主战场,也是这一份存在的理由:一个事务里的 SELECT 和 UPDATE 看到的不是同一份数据。这一条不知道的人,写出来的「先查再改」在任何隔离级别下都是错的。

另外它会认真对待一件常被含糊过去的事:同一个级别的名字,在 MySQL 和 PostgreSQL 上的保证并不一样。

★★★★☆ · about 40 min · Tests: 三种异常的区别、快照什么时候拍、快照读 vs 当前读、幻读靠什么挡

What this one drills

Versions and visibility Locking

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

Nobody has written yet. After you run it, say what came out of the conversation — which scene stumped you, which conclusion you changed afterwards.

Sign in to write a note.

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

  1. Pick one, open it, copy the prompt.
  2. Paste it into a fresh, empty chat, and say which engine and version you use first (say nothing and it assumes MySQL 8).
  3. 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.