Optimized event query