淺析Oracle 10gR2中最佳化器對錶關聯的最佳化(轉)

ba發表於2007-08-17
淺析Oracle 10gR2中最佳化器對錶關聯的最佳化(轉)[@more@]在以前的一篇文章中,介紹過額外的關聯對SQL的影響是很大的,所以在sql稽核的工作中,對於表關聯的關注是相當多的,如果冗餘能夠最佳化掉表關聯,偶都儘量在表設計上做些冗餘處理;在10gR2中,發現最佳化器可以最佳化掉一些不必要的關聯……

  9206:
  SQL> set autot on
  SQL> select count(*)
  2 from dept d, emp e
  3 where d.deptno = e.deptno;
  COUNT(*)
  ----------
  12
  Execution Plan
  ----------------------------------------------------------
  0 SELECT STATEMENT Optimizer=CHOOSE
  1 0 SORT (AGGREGATE)
  2 1 NESTED LOOPS
  3 2 TABLE ACCESS (FULL) OF 'EMP'
  4 2 INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)

  10202
  SQL> set autot on
  SQL> select count(*)
  2 from dept d, emp e
  3 where d.deptno = e.deptno;
  COUNT(*)
  ----------
  12
  ִѐ¼ƻ®
  ----------------------------------------------------------
  Plan hash value: 2083865914
  --------------------------------------------------------------------------
  | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
  --------------------------------------------------------------------------
  | 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
  | 1 | SORT AGGREGATE | | 1 | 13 | | |
  |* 2 | TABLE ACCESS FULL| EMP | 12 | 156 | 3 (0)| 00:00:01 |
  --------------------------------------------------------------------------
  Predicate Information (identified by operation id):
  ---------------------------------------------------
  2 - filter("E"."DEPTNO" IS NOT NULL)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10617731/viewspace-963585/,如需轉載,請註明出處,否則將追究法律責任。

相關文章