2013年1月16日 星期三

Published 凌晨1:29 by with 0 comment

IN與NOT IN的效能問題

在in與not in,最終會轉換成where條件,記得。

有兩個關係:
一、Select出來的資料多少。
二、 Where帶的條件。

在1000筆資料裡,你是要使用in(包含)還是not in(排除)才會快?
in (10筆) / not in (90筆)?
in (90筆) / in (10筆)?

在100萬筆資料裡,你是要使用in(包含)還是not in(排除)才會快?
in (10萬筆) / not in (90萬筆)?
in (90萬筆) / not in (10萬筆)?

其 實兩題一模一樣,只是把資料量變大時,就看得出差異。
原則很簡單,選的那一個。

以第二題為例,
in (10萬筆) → 代表10萬條where條件
not in (90萬筆) → 代表90萬條where條件


      edit

0 意見:

張貼留言