I have a script that has to look throught over 2.5 million records to find if a member that has an unread email. I want to know what can be done to improve its speed. Curr
As a thumb rule, every field on which you perform frequent filters (where
conditions) must be indexed.
Again, as a thumb rule, I follow these criteria:
date
field on which I have to perform frequent lookups must be indexedchar
or varchar
fields, I index them as wellNotice that it is easy to fall in the temptation of indexing everything. Don't do it. Be careful and design your indexes with the best cost - benefit relationship.
I'm a MySQL user, and I don't how to do it in SQL server, but there must be a way to show the execution plan of your query (in MySQL it is explain select...
). Try to show the execution plan, and then decide on that basis which are the fields you need to index.