ရိုးရိုးလေး ရှင်းပြမယ်
Index သည် table တစ်ခုလုံး scan မလုပ်ဘဲ row ကိုမြန်မြန်ရှာနိုင်စေသော data structure ဖြစ်သည်။ WHERE, JOIN နှင့် ORDER BY တွင်မကြာခဏသုံးသော selective column များအတွက်သင့်တော်သည်။ Index များလွန်းလျှင် write နှင့် storage cost တက်သည်။
sql
CREATE INDEX idx_orders_customer_created
ON orders (customer_id, created_at DESC);
EXPLAIN
SELECT id, total, created_at
FROM orders
WHERE customer_id = 42
ORDER BY created_at DESC
LIMIT 10;You should see
Index Scan using idx_orders_customer_created on ordersလက်တွေ့စမ်းကြည့်ရန်
users table တွင် unique email index တစ်ခုဖန်တီးပြီး duplicate email insert ဖြစ်သောအခါဘာဖြစ်သည်ကိုစမ်းပါ။
PostgreSQL Indexes — PostgreSQL