我發出以下SQL:如何提高這種情況下的SQL性能?
Select * from myTable
where myID =123
and myDate >= (case when isnull(null,'')='' then myDate else null end)
的表現非常糟糕。
如果我修改它是這樣的:
Select * from myTable
where myID =123
and myDate >= myDate
的表現要好得多。
我真正的SQL可能是這樣的:
Select * from myTable
where myID =123
and myDate >= (case when isnull(@myDate,'')='' then myDate else null end)
myDate
是Datetime
列。
如何提高這種情況下的性能?
myTable上的索引是什麼? –
這是爲什麼? 'isnull(null,'')' – gbn
'性能要好得多。'那是因爲你有一個dud子句'mydate> = mydate',它總是爲100% – RichardTheKiwi