設計開發時慎重決定列是否為空(二)

LuiseDalian發表於2014-01-18

 案例2

NOT IN的典型查詢中NULL值會限制unnest轉換,導致優化器無法選擇ANTI演算法,而走了低效的filter

(11g中,二者選擇的執行計劃是一樣的)

點選(此處)摺疊或開啟

  1. DROP TABLE t1;
  2. CREATE TABLE t1 as SELECT * FROM user_objects;
  3. DROP TABLE t2;
  4. CREATE TABLE t2 AS SELECT * FROM user_objects;
  5. SET timing ON
  6. SET autotrace traceonly
  7. SELECT * FROM t1 WHERE object_id NOT IN (SELECT object_id FROM t2 group by object_id, object_name having count(*) > 1);

  8. 15 rows selected.

  9. Elapsed: 00:00:00.06

  10. Execution Plan
  11. ----------------------------------------------------------
  12. Plan hash value: 2948349348


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

相關文章