Huge performance improvements

When using sickbeard with over 5000+ episodes in the database, it becomes very slow. This pull requests fixes this problem by adding indices and optimizing an sql query.