O
21

A senior dev told me I was overcomplicating my SQL queries and it changed everything

I used to write these massive JOINs with nested subqueries for our customer database at a marketing firm in Chicago. My lead showed me how using CTEs and window functions could cut my query time from 45 seconds to under 2. Has anyone else had a piece of feedback that totally shifted how you approach your work?
3 comments

Log in to join the discussion

Log In
3 Comments
hugo_schmidt
Buddy of mine from a dev shop in Austin had this exact thing happen. He was writing these crazy monster queries for their CRM and his senior was like "dude just use a single recursive CTE" and it cut his 90 second report down to like 4 seconds.
1
simons28
simons281mo agoTop Commenter
90 seconds down to 4 seconds? Thats insane, I would have been shocked too.
1
rubyschmidt
Actually, I'm gonna push back on this a bit. @simons28 might have been impressed, but faster queries aren't always better if you're sacrificing readability for future devs. CTEs and window functions can turn into a messy spaghetti mess real quick when someone needs to debug your code six months later. Sometimes a slower query that's easy for anyone to understand is worth the extra seconds. Plus, that old query might have been fine if you just added a few proper indexes. I've seen teams waste hours untangling fancy recursive CTEs that a simple join would have solved way cleaner.
1