技术开发 频道

数据库性能调优技术之嵌套循环执行计划

  举例说明explain plan for命令:

SQL> explain plan for select c1 from t1 where c1=1;
Explained.
SQL
> select * from table(DBMS_XPLAN.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2624316456
--------------------------------------------------------------------------
| Id  | Operation        | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT |       |     1 |    13 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| IT1C1 |     1 |    13 |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
   1 - access("C1"=1)
Note
-----
   - dynamic sampling used for this statement
17 rows selected.
SQL
>

  用“explain plan for 查询语句;”生成执行计划,然后使用“select * from table(DBMS_XPLAN.display);”语句显示执行计划。

  下面的内容,将通过一些例子来理解嵌套理解执行计划:

  1.不带索引的嵌套连接的执行计划该如何理解?

  构造处测试场景:

  查询语句为:

select /*+ USE_NL(t2) */ c1,c2 from t1 inner join t2 on c1=d2;

  该语句中“/*+ USE_NL(t2) */”是我们常说的hint提示,这里的USE_NL告诉优化程序使用嵌套连接对表进行连接,t2为内部表。此查询语句的执行计划为:

0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=2 Bytes=78)
  
1    0   NESTED LOOPS (Cost=4 Card=2 Bytes=78)
  
2    1     TABLE ACCESS (FULL) OF 'T1' (TABLE) (Cost=2 Card=2 Bytes
          
=52)
  
3    1     TABLE ACCESS (FULL) OF 'T2' (TABLE) (Cost=1 Card=1 Bytes
          
=13)
0
相关文章