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

Index အခြေခံ

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

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

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

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

Index က table အားလုံးမဖတ်ဘဲ row ကိုရှာနိုင်စေသော်လည်း insert/update/delete တိုင်း index ကိုပါပြင်ရပါတယ်။ Primary key နှင့် unique constraint များက index ဖန်တီးပေးပေမယ့် foreign key referencing column ကို PostgreSQL ကအလိုအလျောက် index မလုပ်ပါဘူး။ Composite index column order ကို query predicates နဲ့ sort order အလိုက်ရွေးရပါတယ်။

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

Published tutorial feed က `is_published` true rows ကို date/id descending ဖြင့်ဖတ်လို့ partial composite index သုံးမယ်။ Lessons lookup အတွက် foreign key column နှင့် lesson number ကို index လုပ်ပါ။ Index တစ်ခုထည့်တိုင်း EXPLAIN နှင့် write overhead ဖြင့်အတည်ပြုရပါတယ်။

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

sql
CREATE INDEX lessons_tutorial_number_idx
  ON app.lessons (tutorial_id, lesson_number);

CREATE INDEX tutorials_published_feed_idx
  ON app.tutorials (published_at DESC, tutorial_id DESC)
  WHERE is_published = true;

SELECT indexname, indexdef
FROM pg_indexes
WHERE schemaname = 'app';
You should see
Lesson lookup နှင့် published feed အတွက် workload-specific indexes နှစ်ခုရမည်။

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

User email lookup၊ enrollment by user နှင့် incomplete progress query တို့အတွက် index candidates ရေးပြီး column order ကိုရှင်းပါ။

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

Column တိုင်း index ထည့်ခြင်းက write နှေး၊ disk ကြီးနှင့် planner choice ရှုပ်စေပါတယ်။

PostgreSQL — IndexesPostgreSQL Global Development Group

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

  • Column တိုင်း index ထည့်ခြင်းက write နှေး၊ disk ကြီးနှင့် planner choice ရှုပ်စေပါတယ်။
  • နမူနာ code ကို production data ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test database နှင့် recoverable backup ပေါ်တွင် အရင်အတည်ပြုပါ။

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

User email lookup၊ enrollment by user နှင့် incomplete progress query တို့အတွက် index candidates ရေးပြီး column order ကိုရှင်းပါ။

You'll know it worked when: Lesson lookup နှင့် published feed အတွက် workload-specific indexes နှစ်ခုရမည်။

Index အခြေခံ | Thuta Learning