今天寫SQL的時(shí)候有個(gè)邏輯是要取2個(gè)時(shí)間窗口有交集的數(shù)據(jù)捌肴,過濾條件如下:
2個(gè)時(shí)間窗大小 [start_time1, end_time1]
和 [start_time2, end_time2]
where
not (
end_time1 < start_time2
or
end_time2 < start_time1
)
我用的是取反的邏輯來(lái)處理的殴俱。
然后我看了下生成的執(zhí)行計(jì)劃上述的條件優(yōu)化成了如下:
where
end_time1 >= start_time2
and
end_time2 >= start_time1
上述的優(yōu)化其實(shí)是用了德摩根律得到的:
即: :
end_time1 < start_time2
鸠删,則 :
end_time1 >= start_time2
认罩,也同理简软。