Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Datetime Indexing Problem?

$
0
0
Hi guys,

I have a table with over a million rows in it. Lately I've noticed some slowness even on some simple queries. Maybe I'm not understanding something obvious about indexes so I'm hoping some one can enlighten me.

Each record has a datetime field to keep up with when that record was created. If I run the following query:

select * from table where datetime > '2012-01-01'

It won't use the index that I have placed on the datetime field.

If I run this next query, however:

select 1 from table where datetime > '2012-01-01'

It uses the index fine. Does the index only apply to itself? If I want to reference multiple columns, do I need to create an index on multiple fields?

This is where things get weird. If I run this query:

select * from table where datetime > '2012-06-01'

It uses the index fine. Is whether or not it uses the index some how dependent on the number of rows returned? Why does the index work when selecting just the last couple of months, but not since the beginning of the year?

Any help would be appreciated.

Viewing all articles
Browse latest Browse all 13329

Trending Articles