oracle是如何执行sql语句的?

发布于 2024-11-07 20:57:54 字数 198 浏览 1 评论 0原文

比如:

select country 
  from table1 
 inner join table2 on table1.id=table2.id
 where table1.name='a' and table2.name='b'
 group by country 

parse之后,会先执行哪一部分?

such as:

select country 
  from table1 
 inner join table2 on table1.id=table2.id
 where table1.name='a' and table2.name='b'
 group by country 

after the parse, which part will be executed first?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陪你到最终 2024-11-14 20:57:54

看起来您想知道Oracle选择的执行计划。您可以从 Oracle 本身获取该输出:

set serveroutput off
< your query with hint "/*+ gather_plan_statistics */" inserted after SELECT >
select * from table(dbms_xplan.display_cursor(null, null, 'last allstats'));

请参阅此处了解如何读取查询计划的说明:http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/ex_plan.htm#i16971

但请注意,查询计划的选择不是固定的。 Oracle 尝试根据可用的统计数据找到当前最佳的查询计划。

It looks like you want to know the execution plan chosen by Oracle. You can get that ouput from Oracle itself:

set serveroutput off
< your query with hint "/*+ gather_plan_statistics */" inserted after SELECT >
select * from table(dbms_xplan.display_cursor(null, null, 'last allstats'));

See here for an explanation how to read a query plan: http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/ex_plan.htm#i16971

Be aware however that the choice of a query plan is not fixed. Oracle tries to find the currently best query plan, based on available statistics data.

浊酒尽余欢 2024-11-14 20:57:54

您可以在很多地方找到 SQL 的顺序执行

  1. FROM 子句
  2. WHERE 子句
  3. GROUP BY 子句
  4. HAVING 子句
  5. SELECT 子句
  6. ORDER BY 子句

但请注意,这是“理论”顺序 - SQL 引擎允许以其他顺序执行操作,前提是最终结果似乎是通过使用以上订单。

There are plenty of places you can find the order in which SQL is executed:

  1. FROM clause
  2. WHERE clause
  3. GROUP BY clause
  4. HAVING clause
  5. SELECT clause
  6. ORDER BY clause

But note that this is the "theoretical" order - SQL engines are allowed to perform the operations in other orders, provided that the end result appears to have been produced by using the above order.

萌吟 2024-11-14 20:57:54

如果您安装了 Oracle 的免费工具 SQL*Developer,那么您可以单击按钮来获取解释计划。

快速解释位于 http://www.seeingwithc.org/sqltuning.html

If you install the free tool SQL*Developer from Oracle, then you can click a button to get the explain plan.

A quick explanation is at http://www.seeingwithc.org/sqltuning.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文