SQL引擎执行查询和子查询的顺序是什么? [英] In which sequence are queries and sub-queries executed by the SQL engine?

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

问题描述

你好,我做了一个 SQL 测试并且对一个问题感到怀疑/好奇:

Hello I made a SQL test and dubious/curious about one question:

SQL 引擎执行查询和子查询的顺序是什么?

答案是

  1. 主查询->子查询->子子查询等等
  2. 子子查询->子查询->主查询
  3. 一次解释整个查询
  4. 没有固定的解释顺序,查询解析器会即时做出决定

我选择了最后一个答案(只是假设它是最可靠的 w.r.t. 其他人).现在好奇心:

I choosed the last answer (just supposing that it is most reliable w.r.t. others). Now the curiosity:

我可以在哪里阅读有关此内容的信息,并简要介绍所有内容背后的机制是什么?

谢谢.

推荐答案

选项 4 已经结束.

SQL 是声明式:你告诉查询优化器你想要什么,它会得到最好的结果(取决于时间/成本"等)这样做的方式.根据统计数据、数据分布、行数、并行度和天知道还有什么,这对于外观相同的查询和表可能会有所不同.

SQL is declarative: you tell the query optimiser what you want and it works out the best (subject to time/"cost" etc) way of doing it. This may vary for outwardly identical queries and tables depending on statistics, data distribution, row counts, parallelism and god knows what else.

这意味着没有固定的顺序.但它并不完全即时"

This means there is no fixed order. But it's not quite "on the fly"

即使使用相同的服务器、架构、查询和数据,我也看到执行计划不同

Even with identical servers, schema, queries, and data I've seen execution plans differ

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

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