I have a very slow running query, and I've isolated the problem down to the following SQL.
SELECT
...
FROM
TableA a(nolock)
inner join TableB b with(nolock) on (b.Id = a.Id AND b.Date>= isnull(@timestamp_start, '17530101') AND b.Date < isnull(@timestamp_end, '99991231'))
a = 2million+ rows
b = 2million+ rows
b.Id => Index, unique, non-clustered
a.Id => Index, unique, non-clustered
b.Date => Index, non-unique, non-clustered
This takes several minutes without returning a result even for a single day date range. On my local machine here's what the execution plans looks like:
Why would this query be slow and how can I fix it?