Query processing phases

Query processing takes place in a number of phases. Understanding this helps to explain why some errors aren't reported until others have been fixed – e.g. why you don't find out about your column name typos until you've fixed all your SQL keywords!

  1. Parse. Parsing checks that your SQL query is syntactically valid (against the TSQL grammar, not against your database definition).
  2. Bind/algebrize. Binding associates table, view, column etc names with the underlying objects in your database, and transforms the query into an algebraic expression built from logical query operators. If you're referring to a non-existent column, you'll find out here.
  3. Optimize. Optimization transforms the logical query expression into an expression made from physical query operators – the query plan. Any number of logically-equivalent transformations may exist, and the optimizer selects one likely to provide the best performance.
  4. Execute. Run the query plan.