sql执行顺序 [英] Sql execution order

查看:50
本文介绍了sql执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对简单的查询感到困惑:

SELECT * FROM table_name WHERE name = 'stack';

我的问题是这部分首先执行:

SELECT * FROM table_name

WHERE name = 'stack'

首先从表中选择所有记录,然后使用 WHERE 条件过滤首先过滤记录然后选择?

有关问题的更多详细信息,请参阅此链接:

SQL 中的 WHERE 条件问题

谢谢

解决方案

以下步骤显示了 SELECT 语句的逻辑处理顺序或绑定顺序.此顺序决定了在一个步骤中定义的对象何时可用于后续步骤中的子句.例如,如果查询处理器可以绑定(访问)在 FROM 子句中定义的表或视图,则这些对象及其列可用于所有后续步骤.相反,由于 SELECT 子句是第 8 步,因此该子句中定义的任何列别名或派生列都不能被前面的子句引用.但是,它们可以被后续子句引用,例如 ORDER BY 子句.请注意,语句的实际物理执行由查询处理器决定,顺序可能与此列表不同.

 FROM上加入在哪里通过...分组WITH CUBE 或 WITH ROLLUP有选择清楚的订购者最佳

I am confusing with simple query:

SELECT * FROM table_name WHERE name = 'stack';

My question is this which part first execute:

SELECT * FROM table_name

OR

WHERE name = 'stack'

First select all record from table then filter with WHERE condition or first filter records then SELECT?

For more details about question please see this link:

WHERE condition issue in SQL

Thanks

解决方案

The following steps show the logical processing order, or binding order, for a SELECT statement. This order determines when the objects defined in one step are made available to the clauses in subsequent steps. For example, if the query processor can bind to (access) the tables or views defined in the FROM clause, these objects and their columns are made available to all subsequent steps. Conversely, because the SELECT clause is step 8, any column aliases or derived columns defined in that clause cannot be referenced by preceding clauses. However, they can be referenced by subsequent clauses such as the ORDER BY clause. Note that the actual physical execution of the statement is determined by the query processor and the order may vary from this list.

    FROM
    ON
    JOIN
    WHERE
    GROUP BY
    WITH CUBE or WITH ROLLUP
    HAVING
    SELECT
    DISTINCT
    ORDER BY
    TOP

这篇关于sql执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆