How to increase performance of query using filter?