by stux · 3y ago · 0 comments
> Redundant conditions are nice because they require no changes to the database [...] This makes them useful for queries that are only sometimes run or where indexes can't be easily added to the main conditions
but where possible I typically prefer adding an index on the expression that the query is using (if your database supports it) since it expresses your intent more clearly. A redundant condition is more likely to get "optimized away" by other developers or changes in the query planner.
Of course if your database can't be changed then maybe you can use this trick if there is already a suitable indexed column.
If you're curious, here's a video I did on it: https://planetscale.com/courses/mysql-for-developers/indexes...