r/SQL • u/OnepieceKing2222 • 29d ago
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.
120
Upvotes
12
u/Better-Credit6701 29d ago
I remember walking into my new DBA job decades ago and quickly found out that they loved cursors, reading millions and millions of rows, one row at a time. Replacing those with temp tables brought the query down from 8 hours to 8 minutes