News for hackers. Stuff that matters.
Re:Ask HN: How do you test SQL? by curiousllama on Tuesday January 31, 2023 @07:58PM (#34604813)
> Try and write any complex SQL as a series of semantically meaningful CTEs

I find this helps a heck of a lot with maintainability + debugging as well

Re:Ask HN: How do you test SQL? by atwebb on Tuesday January 31, 2023 @09:35PM (#34605609)
It can wind up with more of a procedural thought though than set-based. Not always, just something to pay attention to and pushing filters early / explicitly. It is asking more of the optimizer a lot of the times and that's were a bunch of the cautions come in to play.
Re:Ask HN: How do you test SQL? by mwigdahl on Thursday February 02, 2023 @05:43PM (#34634334)
Just tuned a query like this today. Many chained CTEs, joined together at each stage to do range checking logic within subgroups. There were so many self joins that the row estimates (and requested memory grant) were through the roof.

I love CTEs, but the query semantics matter too.