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

查看:14
本文介绍了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天全站免登陆