Query Processing and the Optimiser

Context: FIT2094_MOC Β· how Oracle turns SQL into an execution plan Β· explains why nested vs correlated subqueries differ in cost Β· conceptual only β€” not assessed

Quick Revision

  • 🎯 Objective: trace SQL through parse β†’ analyse β†’ optimise β†’ execute βž” understand relative query cost.
  • ⚑ Key Constraint: the Explain-Plan COST is a relative unit β€” meaningful only when comparing two versions of the same query.

πŸ“ Core

  • 1. SQL Parser βž” checks syntax (grammar) and semantics (do the tables/columns exist?).
  • 2. Query analysis βž” decomposes into relational-algebra ops (joins, selects, projects).
  • 3. Optimiser (CBO) βž” the Cost-Based Optimiser estimates each strategy’s cost, picks the cheapest, caches the plan.
  • 4. Execution engine βž” runs the plan, pulling data blocks into cache, returns the result set.
  • Cost depends on statistics βž” CBO estimates rely on gathered stats (user_tab_col_statistics, user_ind_statistics).

⚠️ Common Mistakes

  • πŸ’‘ COST has no absolute meaning βž” a plan cost of 9 vs 39 only says the second is ~4Γ— costlier for that query; it is not seconds or rows.
  • πŸ’‘ Correctness β‰  efficiency βž” a correlated subquery gives the same answer as a nested one but re-scans per row; you are not penalised for it in this unit.

🧠 Active Recall