ECS on its own doesn't always help - it's not a magic bullet for every situation: sometimes you need to use spatially-aware data structures / acceleration structures for those type of "queries", and vanilla ECS (i.e. similar to a DB in terms of queries) doesn't always help you in these type of situations.