Published on

March 24, 2009

Understanding the Logical Query Processing Phase in SQL Server

Recently, I received an intriguing comment on one of my articles about the ON clause in a LEFT JOIN operation. The comment sparked a question in my mind about the Logical Query Processing Phase in SQL Server. In this article, I will provide an introduction to this phase and discuss its significance in SQL Server.

What sets SQL Server apart from other programming languages is the way it processes its code. While most programming languages process statements from top to bottom, SQL Server follows a unique order known as the Logical Query Processing Phase. This phase involves a series of steps, where each step generates a virtual table that feeds into the next step. However, these virtual tables are not viewable to the user.

The Logical Query Processing Phase consists of the following steps:

  1. FROM
  2. ON
  3. OUTER
  4. WHERE
  5. GROUP BY
  6. CUBE | ROLLUP
  7. HAVING
  8. SELECT
  9. DISTINCT
  10. ORDER BY
  11. TOP

As mentioned in my previous article, the OUTER join is applied after the ON clause. This means that all rows eliminated by the ON clause will still be included by the OUTER join. However, there is some confusion regarding the last two steps, ORDER BY and TOP.

Some people believe that TOP comes first in the Logical Query Processing Phase, while others suggest that ORDER BY comes first. This raises the following questions:

  1. What is the correct order for the query processing phase – ORDER BY or TOP?
  2. How can we create an example to verify the query processing phase for ORDER BY and TOP?

I invite all my readers to ponder these questions and share their insights. I will soon publish the answers I receive, giving due credit to my readers.

Understanding the Logical Query Processing Phase is crucial for SQL Server developers and administrators. It helps in optimizing queries and gaining a deeper understanding of how SQL Server processes code. Stay tuned for the answers to the above questions, which will shed more light on this fascinating topic.

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.