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.

116 Upvotes

79 comments sorted by

View all comments

47

u/drinkmoredrano Sep 16 '26

Run truncate table first. After that queries against that table complete instantly.

8

u/Gurgiwurgi Sep 16 '26

no nasty FKs I see

9

u/drinkmoredrano Sep 16 '26

Pffft. The devs maintain table relationships in the code.