Skip to content
About
Main content

A pipeline of one-way steps

Which planning stages are certain and which are risky, and how late can the uncertain decisions be put off?

Planning is a pipeline. Each stage fixes something the next stage needs and cannot reconsider: you cannot rewrite a query until names are resolved to real tables, you cannot match rules until the expression has a standard form, you cannot compute costs until a physical alternative exists, and you cannot choose a join order until you can compute costs. Every stage narrows the options.

Now sort the stages by the information they demand. The stages need nothing but the schema, and they are always right. The late stages need statistics, and they are often wrong. The whole design problem is how late the uncertain decisions can be put off without making the search impossible. For most of the the answer is "not at all", which is why adaptive execution exists (Execution decisions).

StageWhat it fixesInformation neededCan it be wrong?Typical failure
ParseSyntaxNoneNo—
Analyze / bindNames become objects; typesThe NoPlans invalidated by schema changes (DDL)
NormalizeA canonical formSchemaNoExponential blowup; structure lost
Rewrite (rules)Algebraic shapeSchema and constraintsOnly in corner casesAn illegal rewrite when are present
EnumerateThe set of candidate plansSchemaSilentlySpace too big, so a heuristic is used
CostThe chosen planStatisticsWithout boundWrong operator or wrong order

Note where the boundary sits. Everything above "enumerate" is certain, cheap and unconditional. Everything at or below it is the risky part. Most of what practitioners call " tuning" is aimed at the bottom row, and most of the real leverage is in the middle three rows.