Slow Query Log
Last updated
This page covers the slow query log built into query(): what it times, what it prints, and what it leaves out.
Behavior
Every SQL statement runs through query() (src/MySQLPool.ts:362-392). When a run takes more than 20ms, it prints one line through console.log:
[Slow Query: 37ms] [SELECT * FROM `users` WHERE `status` = ?]
| Item | Detail |
|---|---|
| Threshold | Fixed at 20ms (logged when above 20), not configurable |
| Timed span | From just before pool.getConnection() until the result returns, including time spent waiting for a free connection |
| Output | Duration and the SQL with ? placeholders, without bound values |
| Destination | console.log (stdout) |
| Failed queries | Not logged when the query throws |
Reading the Log
Because the timer includes connection checkout, fast SQL still gets logged when the pool is saturated. When slow entries pile up, check:
| Symptom | Likely cause |
|---|---|
| The same SQL is sometimes fast, and slow entries cluster under load | Pool queueing; consider raising connectionLimit (see Configuration) |
| One statement always crosses the threshold | The SQL itself is slow; inspect indexes with EXPLAIN |
Bound values are not logged; to reproduce a statement, enable MySQL's own slow query log or general log.