Don't run a query if it can't return any results

Fixes #16506

Don't make a trip to the database if a query's WHERE clause ensures it would return zero results. For example:

```
```