Thuta Learning
ရှာဖွေရန်
AdvancedData & Databasesbeginner

MVCC နှင့် Isolation Levels

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • MVCC နှင့် Isolation Levels concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ SQL/command ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် အသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

MVCC ကြောင့် reader နဲ့ writer အများစုက တစ်ယောက်ကိုတစ်ယောက်ပိတ်မထားဘဲ snapshot များဖြင့်အလုပ်လုပ်နိုင်ပါတယ်။ Read Committed က statement တစ်ခုစီအတွက် snapshot အသစ်ယူပြီး Repeatable Read က transaction အတွင်း stable snapshot ပေးပါတယ်။ Serializable က anomaly မဖြစ်စေရန် transaction ကို abort/retry ခိုင်းနိုင်ပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Terminal နှစ်ခုဖြင့် transaction တစ်ခုက row update မcommit သေးချိန်မှာ တစ်ခုက old version ကိုဖတ်နိုင်တာစမ်းမယ်။ Isolation level ကို “ပိုမြင့်တာအမြဲကောင်း” လို့မရွေးဘဲ invariant၊ contention နဲ့ retry handling ကိုအတူသတ်မှတ်ပါ။

အတူတူ စမ်းရေးကြည့်မယ်

sql
-- Session A
BEGIN;
UPDATE app.users SET display_name = 'Uncommitted' WHERE user_id = 1;

-- Session B (still sees the committed version)
SELECT display_name FROM app.users WHERE user_id = 1;

-- Session A
COMMIT;

-- For stronger semantics:
BEGIN ISOLATION LEVEL SERIALIZABLE;
You should see
Uncommitted change ကို တခြား session မမြင်သေးကြောင်း စမ်းသပ်နိုင်မည်။

၅ မိနစ် စမ်းကြည့်

Read Committed နဲ့ Repeatable Read အောက်တွင် query တစ်ခုကိုနှစ်ခါ run ပြီး concurrent update နောက် result ကွာခြားမှုစစ်ပါ။

သတိလေးတစ်ချက်

Serializable သုံးရုံနဲ့ application logic ပြီးပြည့်စုံမလာပါ—serialization failure retry loop မရှိရင် request fail ပါမယ်။

PostgreSQL — Concurrency ControlPostgreSQL Global Development Group

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Serializable သုံးရုံနဲ့ application logic ပြီးပြည့်စုံမလာပါ—serialization failure retry loop မရှိရင် request fail ပါမယ်။
  • နမူနာ code ကို production data ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test database နှင့် recoverable backup ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

Read Committed နဲ့ Repeatable Read အောက်တွင် query တစ်ခုကိုနှစ်ခါ run ပြီး concurrent update နောက် result ကွာခြားမှုစစ်ပါ။

You'll know it worked when: Uncommitted change ကို တခြား session မမြင်သေးကြောင်း စမ်းသပ်နိုင်မည်။

MVCC နှင့် Isolation Levels | Thuta Learning