r/SQL • • Sep 16 '26

Discussion What SQL query optimization trick made the biggest difference for you?

I've been working with SQL for a while and recently started paying more attention to query performance rather than just getting the correct result.

What's one SQL optimization technique that made a noticeable difference for you?

For example:

- Indexing

- Avoiding unnecessary joins

- Window functions

- EXISTS vs IN

- Reading execution plans

- CTEs/subqueries

- Partitioning

Would be interested in hearing some real-world examples where a query went from slow to significantly faster.

119 Upvotes

80 comments sorted by

View all comments

Show parent comment

3

u/theseyeahthese #TempTables ally Sep 17 '26

When it comes to using temp tables like this, I always think of that “beginner, intermediate, and expert on a graph” meme, where the beginner and expert come to the same conclusion and the guy in the middle is raging.

When you’re a beginner, chunking things out keeps things clear in your head. When you’re an intermediate, you want to flex those long-CTE-chain/ complex-join muscles and “just have the engine figure it out in one go”. And then you come all the way back around to chunking it out, once you realize that many times you’re asking way too much of the engine lol.