SQL查询的执行顺序 [英] Order of Execution of SQL Queries

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

问题描述

我很好奇SQL查询的执行顺序。我对此做了一些研究。我发现了这个:



http://stackoverflow.com/questions/4596467/order-of-execution-of-the-query



在该链接中,有人说以下:



SQL没有执行顺序。是一种声明性语言。优化器可以自由选择任何合适的顺序来产生最佳执行时间。任何SQL查询,基本上都不可能让任何人假装它知道执行顺序。如果你添加有关所涉及的模式的详细信息(确切的表和索引定义)和估计的基数(数据的大小和键的选择性),那么可以采取猜测可能的执行顺序。



真的吗?没有订单???



但是在以下链接中我得到了一个合理的处理订单。



http:// blog。 sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/





I am curious about the order of execution of SQL Queries. I did a bit of research on this. I found this:

http://stackoverflow.com/questions/4596467/order-of-execution-of-the-query

In that link, someone stated the following:

"SQL has no order of execution. Is a declarative language. The optimizer is free to choose any order it feels appropriate to produce the best execution time. Given any SQL query, is basically impossible to anybody to pretend it knows the execution order. If you add detailed information about the schema involved (exact tables and indexes definition) and the estimated cardinalities (size of data and selectivity of keys) then one can take a guess at the probable execution order."

Really? There is NO ORDER???

But in the following link i got a logical processing order.

http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/


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





所以我有点困惑,现在真的很好奇知道实际上有任何订单...... !!!!



So i am a bit confused and now really very curious to know that there is actually any order or not...!!!!

推荐答案

嗯,事情并非那么简单。它是一种声明性语言,但它当然有逻辑,算法。但不是那种意义上的。对于简单查询,它看起来可能相似,但通常有一个所谓的查询优化器任务,即为该特定查询计算查询计划。查询计划考虑了索引,设置大小和许多其他情况以获得特定的执行顺序。

在这里查看一些理论:http://infolab.stanford.edu/~hyunjung/cs346/ioannidis.pdf [ ^ ]

但如果你谷歌搜索查询优化,你会发现一些有趣的文章不同的RDBMS,因为这是每个人的关键特征,因此不同。
Well, it is not that simple. It is a declarative language, but of course it has a logic, an algorithm. But not in that sense. For a simple query it might look alike, but in general there is a so called query optimizer task, that is calculating a query plan for that specific query. A query plan is taking into account indexes, set sizes and many other circumstances to get a specific execution order.
Look here for some theory: http://infolab.stanford.edu/~hyunjung/cs346/ioannidis.pdf[^]
But if you google for "query optimizes" you will find several interesting articles about different RDBMS, since this is key feature of everyone, thus different.


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

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