Fix slow query