r/PostgreSQL • • Mar 20 '22

How-To Mastering SQL Query Optimization

https://tvkoushik.medium.com/mastering-sql-query-optimization-622cc6addef2?sk=8e8edbfd5cd370461aa25cfb8d667c12
12 Upvotes

15 comments sorted by

View all comments

3

u/swenty Mar 20 '22 edited Mar 20 '22

Avoid Calculated Fields in JOIN and WHERE clause

This seems like a big over-generalization. In some cases calculated fields can interfere with use of indexes. That doesn't mean that you shouldn't ever use calculations in WHERE – just be aware of what effect it's having on use of indexes.

Indeed several of these suggestions seem better as contextually interesting prompts than 'best practice' guidance for how to write queries. Don't just do all of these things blindly. Measure with actual data loads and see what is and isn't affecting performance in your particular situation.