|
|
|
|
|
by BeefWellington
505 days ago
|
|
I've seen many devs extrapolate this thinking too far into sending only the most simple queries and doing all of the record filtering on the application end. This isn't what I think you're saying -- just piggybacking to try and explain further. The key thing here is to understand that you want the minimal correct query for what you need, not to avoid "making the database work". The given example is silly because there's additional parameters that must be either NULL or have a value before the query is sent to the DB.
You shouldn't send queries like: SELECT \* FROM users
WHERE id = 1234
AND (NULL IS NULL OR username = NULL)
AND (NULL IS NULL OR age > NULL)
AND (NULL IS NULL OR age < NULL)
But you should absolutely send: SELECT \* FROM users
WHERE id = 1234
AND age > 18
AND age < 35
|
|
What you shouldn't send is queries like:
because now the database (probably) doesn't know the value of the parameters during planning and needs to consider all possibilities.