Heuristic and cost-based query optimization

December 4, 2026 · Team EasyExamNotes · 3 min read (est.) · 0 comments

Share on WhatsApp

← RGPV CS-502 DBMS June 2026 solved question paper

← RGPV CS-502 DBMS December 2025 solved question paper

RGPV CS-502 (GS) | June 2026 | Q6(b) | 7 marks (inferred)

Question (restated): Discuss heuristic and cost-based optimization techniques in DBMS.

Answer

Logical query; Heuristic rewrites; Cost comparison; Selected plan
Heuristic and cost-based query optimization

Heuristic optimization applies equivalence rules expected to reduce work. Typical rules push selections toward base relations, push projections while retaining needed join attributes, replace Cartesian product followed by a matching selection with a join, and reorder inner joins when semantics permit. These rules reduce intermediate results and search complexity.

Consider Student joined with Department and filtered on DeptName. Applying the filter to Department before the join can reduce rows entering the join. Projection can discard unused columns but must retain DeptID for joining. Outer joins and null-sensitive predicates require special care; unrestricted predicate movement can change results.

Cost-based optimization estimates the cost of candidate physical plans using relation sizes, page counts, indexes, selectivity, memory and CPU. It compares access paths, join algorithms and join orders. For a table with 1000 pages, a full scan costs roughly 1000 page reads. An index with height 3 and 20 matching rows on separate pages may cost roughly 23 reads, ignoring caching and leaf traversal. If most rows match, scanning may be cheaper.

Dynamic programming can enumerate join orders for small queries; larger queries may use bounded or randomized search. Statistics and histograms improve estimates, but skew and correlations can produce errors. Heuristics are fast and do not need detailed statistics; cost-based approaches adapt to data and hardware but require planning effort.

Modern systems typically combine both: rewrite using safe rules, then estimate costs of alternative physical plans. The objective is not the smallest SQL text but efficient execution with equivalent results.


December 2025 – Q5(a)

Question (restated): Explain query optimization, its importance and heuristic and cost-based methods.

Query optimization chooses an efficient execution plan among equivalent ways of evaluating a query. It reduces disk I/O, CPU work, memory use and response time while preserving results. A heuristic optimizer uses rules such as pushing selections and projections down and replacing Cartesian products followed by matching predicates with joins. Such rewrites must preserve required join attributes and SQL semantics.

A cost-based optimizer estimates cardinalities, selectivities and operator costs using statistics. It compares table scans, index scans, join orders and algorithms such as nested-loop, hash and merge joins. For example, if only 1% of a million employees belong to Sales, filtering before joining may reduce the input to about 10,000 rows. An index may help if the qualifying rows are selective, but a scan may be cheaper for a large fraction of the table.

Heuristics reduce the search space quickly; cost-based search adapts to data distribution and hardware. Stale statistics and correlated predicates can produce poor estimates. Practical optimizers combine both techniques and expose estimated plans through EXPLAIN.

← RGPV CS-502 DBMS June 2026 solved question paper

← RGPV CS-502 DBMS December 2025 solved question paper

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion