I have two tables with point data.
Table 1 - No null Points.
Table 2 - About half of the points are null.
The query:
SELECT
*
FROM
Table1
INNER JOIN
Table2
ON
Table1.Point.STBuffer(2.5).STIntersects(Table2.Point) = 1
WHERE
Table1.Point IS NOT NULL
AND Table2.Point IS NOT NULL
Takes over 8 hours to complete.
If I copy the data to a temporary table like this:
INSERT INTO TempTable SELECT * FROM Table2 WHERE Point IS NOT NULL
The same query takes about 40 seconds.
If I add some null data back in.
INSERT INTO TempTable SELECT TOP 10000 * FROM Table2 WHERE Point IS NULL
It goes back to taking forever.
What is happening?