4 ms·
> 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
by curiousllama 4y ago
> 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
- atwebb 4y agoIt 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.
- mwigdahl 4y agoJust 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.