← Back to Node.js performance mapquery
🐢
Node.js Performance
Slow Query Wrapper
Time every query and log slow SQL automatically.
Detailed Description
A query timing wrapper records how long each SQL call takes. It helps identify slow queries from real application traffic instead of guessing from code.
When a query crosses the threshold, log duration, route/request ID, and a safe query preview. Then use EXPLAIN ANALYZE to check indexes, joins, scans, and row counts.
Mental Model
wrap pool.query -> measure duration -> warn if slow -> run EXPLAIN
When To Use
- ->Find slow SQL in production
- ->Identify missing indexes
- ->Catch ORM-generated inefficient queries
Tools: pg query wrapper, EXPLAIN ANALYZE, Prisma middleware
query-timing.js
Live Editor
Loading...
Output
Run code to see output...