對於exists和in,當exists裡面巢狀in的時候,如果in語句裡面只有乙個元素的情況下,這時候索引是有效的.如果多於乙個元素,這種情況下索引會失效.下面寫乙個簡單的例子來驗證以上說法.
sql1:
select 1 from pm_measurement_recalculation reca
where
exists (
select
operating_date
from
pm_measurement_reading reading
where
reading.measurement_id in(
-- 10000828, 10000670, 10000671,215001368
10000828,10000670,10000671) )
執行計畫圖:(索引失效)
執行計畫圖:
準備優化的原sql:
update
pm_measurement_recalculation reca
setreca.from_operating_date=( select
min(temptable.operating_date) as operating_date
from
( select
min(r.operating_date) as operating_date
from
pm_measurement_reading r
where
r.measurement_id in (
10000828, 10000670, 10000671, 215001368
) group by
r.operating_date ) as temptable )
where
reca.measurement_id in (
10000828, 10000670, 10000671,215001368
) and
exists (
select operating_date from pm_measurement_reading reading
where reading.measurement_id in(
10000828, 10000670, 10000671,215001368 ) )
執行計畫圖
優化後的sql:
update
pm_measurement_recalculation reca
setreca.from_operating_date=( select
min(temptable.operating_date) as operating_date
from
( select
min(r.operating_date) as operating_date
from
pm_measurement_reading r
where
r.measurement_id in (
10000828, 10000670, 10000671, 215001368
) group by
r.operating_date ) as temptable )
where
reca.measurement_id in (
10000828, 10000670, 10000671,215001368
) and
exists (
select operating_date from pm_measurement_reading reading
where reading.measurement_id in(
select
reading.measurement_id
from
pm_measurement_reading reading
where
reading.measurement_id in(
10000828, 10000670, 10000671,215001368
)group by reading.measurement_id
fetch first 1 rows only
) )
執行計畫圖:
DB2 exists子句會過濾掉所用的本條記錄
select m.personnelid from yorgpersonnel m where m.organizationid sap zhuxj20120409091538000007 查詢某部門的所有成員 and exists select 1from ypersonnel a where m...
DB2的db2look和db2move的使用
我工作時碰到了乙個需要把乙個老的db2資料庫給拆分,並資料也得移植,我首先想到的是將資料庫進行備份,並重定向恢復成另乙個資料庫,但是嘗試了多次也為成功,於是就只能想想最簡單的方法了export匯出import匯入。一 root localhost su db2inst1 在當前使用者目錄下建立bac...
2db多少功率 db換算 db和功率的換算
db是乙個比值,是乙個數值,是乙個純計數方法,沒有任何單位標註。和瓦 w 是是不能換算的,1 在實際日常生活中,住宅小區告知牌上面標示噪音要低於60分.以功率為例 訊號功率為x 100000w 10 5 基準功率為y 1w db的值 lx db 10 lg 10 5w 1w db 10 lg 10 ...