နားလည်ထားရမယ့် အချက်
Regular view က saved query ဖြစ်ပြီးဖတ်ချိန်တိုင်း underlying tables ကိုကြည့်ပါတယ်။ Materialized view က result ကို physical storage ထဲသိမ်းလို့ read မြန်နိုင်သော်လည်း refresh မလုပ်မချင်း stale ဖြစ်နိုင်ပါတယ်။ View ကို security boundary တစ်ခုတည်းအဖြစ် မယူဆဘဲ privileges နှင့် row-level security ကိုပါစဉ်းစားရပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Published catalog အတွက် stable column interface ကို view နဲ့ပေးပြီး daily analytics ကို materialized view နဲ့သိမ်းမယ်။ `REFRESH MATERIALIZED VIEW CONCURRENTLY` သုံးလိုလျှင် suitable unique index လိုအပ်ပါတယ်။
အတူတူ စမ်းရေးကြည့်မယ်
CREATE VIEW app.published_catalog AS
SELECT tutorial_id, title, slug, published_at
FROM app.tutorials
WHERE is_published = true;
CREATE MATERIALIZED VIEW app.tutorial_stats AS
SELECT t.tutorial_id, count(l.lesson_id) AS lesson_count
FROM app.tutorials t
LEFT JOIN app.lessons l USING (tutorial_id)
GROUP BY t.tutorial_id;
CREATE UNIQUE INDEX ON app.tutorial_stats (tutorial_id);
REFRESH MATERIALIZED VIEW CONCURRENTLY app.tutorial_stats;Live catalog view နှင့် refreshable statistics view ရမည်။၅ မိနစ် စမ်းကြည့်
Active user များအတွက် public profile columns သာပြသော view တစ်ခုရေးပါ။
သတိလေးတစ်ချက်
Materialized view ကို refresh schedule မရှိဘဲ report source လုပ်ရင် data freshness အလွဲဖြစ်နိုင်ပါတယ်။
PostgreSQL — Views — PostgreSQL Global Development Group