We met a strange situation on SQL Server 2008 (SP1) - 10.0.2531.0 (X64) - Win2008 SP2 (X64).
Here is one heavy request:
select t1.id, t2.id
from t1, t2
where
t1.id = t2.ext_id
and isnull(t1.vchCol1, 'Null') = isnull(t2.vchCol1, 'Null')
and isnull(t1.vchCol2, 'Null') = isnull(t2.vchCol2, 'Null')
.... and about 10 more comparisons with Isnull
UPD : all comparison columns (except identifiers) varchar(~ 30 ... 200)
T1 is ~ 130 million rows, T2 is ~ 300 thousand rows.
These requests work on a rather large Dev server ~ 5 hours - this is slow, but what can we do?
And although we investigated possible optimization methods - we found that changing “isnull” to “coalescing in the query above gives a double performance gain - and the query now runs for ~ 2 hours
UPD . When we remove all tags ISNULLand use only t1.vchCol1 = t2.vchCol1, the request ends after 40 minutes .
Question: is this a known behavior and should we avoid using IsNull everywhere?
source
share