I have a table with ~3M rows. The rows are date, time, msec, and some other columns with int data. Some unknown fraction of these rows are considered ‘invalid’ based on their existence in a separate table outages (based on date ranges).
Currently the query does a select * and then uses a huge WHERE to remove the invalid date ranges ( lots of ‘and not ( RecordDate >’2008-08-05’ and RecordDate < ‘2008-08-10′ )’) and so on. This blows away any chance of using an index.
Im looking for a better way to limit the results. As it stands now the query takes several minutes to run.
Make sure you have an index on all fields involved in the query.