oracle oracle是如何执行sql语句的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6055135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does oracle execute an sql statement?
提问by Robin
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?
解析后,哪个部分会先执行?
回答by Peter G.
It looks like you want to know the execution plan chosen by Oracle. You can get that ouput from Oracle itself:
看来你想知道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'));
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
有关如何阅读查询计划的说明,请参见此处: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.
但是请注意,查询计划的选择不是固定的。Oracle 尝试根据可用的统计数据找到当前最佳的查询计划。
回答by Damien_The_Unbeliever
There are plenty of places you can find the order in which SQL is executed:
有很多地方可以找到执行 SQL的顺序:
- FROM clause
- WHERE clause
- GROUP BY clause
- HAVING clause
- SELECT clause
- ORDER BY clause
- FROM 子句
- WHERE 子句
- GROUP BY 子句
- HAVING 子句
- SELECT 子句
- ORDER BY 子句
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.
但请注意,这是“理论上的”顺序 - 允许 SQL 引擎以其他顺序执行操作,前提是最终结果似乎是使用上述顺序生成的。
回答by Greg Reynolds
If you install the free tool SQL*Developer from Oracle, then you can click a button to get the explain plan.
如果您安装了 Oracle 的免费工具 SQL*Developer,那么您可以单击一个按钮来获取解释计划。
A quick explanation is at http://www.seeingwithc.org/sqltuning.html