Foundationপ্রথম নীতি থেকে
LEVEL 8 · Database Systems

Cost Model

কস্ট মডেল

Planner-এর মুদ্রা — প্রতিটা সম্ভাব্য plan-এর খরচের অনুমান (I/O + CPU), যার তুলনাতেই একটা plan জেতে।

also: query-cost-model

PostgreSQL-এর সূত্রের গন্ধ:

seq_scan_cost  = pages * seq_page_cost + tuples * cpu_tuple_cost
index_scan_cost = index_pages * random_page_cost + rows * cpu costs
SHOW random_page_cost;      -- default 4.0, SSD-তে ~1.1 ন্যায্য
SELECT * FROM pg_class WHERE relname='orders';   -- relpages, reltuples
  • Constants arbitrary unit — absolute time নয়, plan-to-plan তুলনার ভাষা
  • Input দুটি: table/cardinality statistics + cost constants — দুই দিকেই ভুল সম্ভব
  • Misestimate-ই বাস্তব bug-এর ৯০%: model সঠিক, ইনপুট মিথ্যা

Tuning = constants বাস্তব hardware-এর ভাষায় আনা + statistics সৎ রাখা।