I have a simple select statement that is taking a very long time to run, but running count (*) on the same table with the same WHERE clause comes back in less than a second.
This query runs for a VERY long time (1 hour +):
SELECT col1
, col2
, col3
FROM Table
WHERE RowInsertDate >= @SomeStartDate
AND RowInsertDate < @SomeEndDate
But this query comes back in less than a second:
SELECT count(*)
FROM Table
WHERE RowInsertDate >= @SomeStartDate
AND RowInsertDate < @SomeEndDate
The table has 34 million rows, with an ID column and a geographical region (North, South, East, West) column used for the primary key. The column 'RowInsertDate' is the date the row was inserted into the table. The expected results for the queries above are 'no rows,' and '0' respectively.
The clustered index for this table is (ID, geoRegion) ASC. This table also has a non-clustered index on RowInsertDate ASC.
I'm not sure where to go from here. Has anyone run into this before?