- cross-posted to:
- hackernews@lemmy.bestiver.se
- cross-posted to:
- hackernews@lemmy.bestiver.se
You must log in or # to comment.
Here’s my quick guide to fixing slow queries:
- grab your query.
- run
EXPLAIN ANALYZE <query> - If there’s a
Parallel Seq Scan, check theFiltervalue (which column are we checking) - you should likely try adding an index. - run
CREATE INDEX ON <table>(<column>); - run
EXPLAIN ANALYZE <query>again to check for improvements
Note that
EXPLAIN <query>will only do a rough analysis, whileEXPLAIN ANALYZE <query>will run your actual query, and analyse it.If you want to
ANALYSE EXPLAINanINSERTquery, do this:BEGIN; EXPLAIN ANALYZE INSERT ...; ROLLBACK;A simple
ROLLBACKwill help you here.Rewriting the query will typically not do much - it might, but the chance it relatively small vs slapping an index on it.


