News for hackers. Stuff that matters.
Re:SQL Anti-Patterns You Should Avoid by bts89 on Saturday October 18, 2025 @11:33AM (#45628145)
That’s almost always my experience too.

Though fairly recently I learned that even with all the correct joins in place, sometimes adding a DISTINCT within a CTE can dramatically increase performance. I assume there’s some optimizations the query planner can make when it’s been guaranteed record uniqueness.

Re:SQL Anti-Patterns You Should Avoid by yxhuvud on Sunday October 19, 2025 @04:06AM (#45632703)
I've seen similar effects when changing a bunch of left outer joins to lateral joins with a limit 1 tacked on. The limit do nothing to the end result, but speed up the query by a factor of 1000..
Re:SQL Anti-Patterns You Should Avoid by Breza on Monday October 27, 2025 @02:47PM (#45724789)
I agree with you. I also find that adding DISTINCT can sometimes make it easier for my colleagues to understand code, especially when I'm using multiple CTEs and it might be easy to miss a one-to-many join.