Comment by sgarland
4 days ago
The thought process can be the same in SQL. You can start by writing SELECT * FROM Account; then add your JOIN to User, then add your predicates. Then you can refine it – here, if I’m understanding the code correctly, you’re using User for a JOIN but never return anything from that table, so you could turn it into a semi-join (WHERE EXISTS) and likely get a speed-up.
> then add your predicates
How are you canonically storing these predicates in code to reuse over 5-10 queries?
Why would you want to?
The fundamentals of software design. DRY
If you have a complex predicate that defines a set of rows, and you use that set in many different queries, are you rewriting it each time?
2 replies →