避免不必要的排序(二)

LuiseDalian發表於2014-01-17

 案例2

確認可以使用union all取代union,從而可以避免排序操作。

 案例3

點選(此處)摺疊或開啟

  1. DROP TABLE t;
  2. CREATE TABLE t AS SELECT * FROM dba_objects;
  3. CREATE INDEX idx_t ON t(owner, object_id);

  4. SET AUTOTRACE TRACEONLY EXPLAIN
  5. ALTER TABLE t MODIFY owner NOT NULL;

  6. --執行語句
  7. SELECT /*+ index(a, idx_t) */ * FROM t a ORDER BY owner DESC, object_type ASC;

  8. Elapsed: 00:00:00.01

  9. Execution Plan
  10. ----------------------------------------------------------
  11. Plan hash value: 332749522


點選(此處)摺疊或開啟

  1. --重新定義索引
  2. DROP INDEX idx_t;
  3. CREATE INDEX idx_t ON t(owner DESC, object_type ASC);

  4. --再次執行語句,排序操作消失
  5. SELECT /*+ index(a, idx_t) */ * FROM t a ORDER BY owner DESC, object_type ASC;

  6. Elapsed: 00:00:00.02

  7. Execution Plan
  8. ----------------------------------------------------------
  9. Plan hash value: 112249094



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

相關文章