select country
from table1
inner join table2 on table1.id=table2.id
where table1.name='a' and table2.name='b'
group by country
解析后
,这部分将被首先执行?
select country
from table1
inner join table2 on table1.id=table2.id
where table1.name='a' and table2.name='b'
group by country
解析后
,这部分将被首先执行?
看起来您想知道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会根据可用的统计数据尝试查找当前最佳的查询计划。
有很多地方,你可以在其中找到SQL is executed顺序:
- FROM子句
- WHERE子句
- GROUP BY子句
- HAVING子句
- SELECT子句
- ORDER BY子句
但请注意,这是“理论”顺序 - 只要最终结果看起来是通过使用上述顺序生成的,则允许SQL引擎以其他顺序执行操作。
如果您从Oracle安装免费工具SQL * Developer,则可以单击按钮以获取解释计划。
有用的信息,你需要添加提示/ * + * gather_plan_statistics /您的查询,或设置参数STATISTICS_LEVEL为ALL。 – 2011-05-19 09:06:54
@Rob谢谢,我知道我忘了东西 – 2011-05-19 09:15:45
感谢您的回答,我还有一个问题,oracle如何选择查询计划,以及如何生成查询计划,谢谢。 – Robin 2011-05-19 11:39:33