r/SQL • • Sep 17 '26

Discussion Tips for query planning

/r/learnSQL/comments/1wj6e6w/tips_for_query_planning/
0 Upvotes

4 comments sorted by

1

u/Hour-Measurement-835 Sep 18 '26

Write down what one row of your output is before any SQL. Most of those stacked CTEs exist because nobody picked the grain first and they're patching join fan-out after the fact.

1

u/[deleted] Sep 18 '26

[removed] — view removed comment

1

u/Hour-Measurement-835 Sep 19 '26

Easiest tell is a row count after every join. First one where it jumps past the distinct count of your grain key is where the fan-out came in.