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 | 20ms (logged when above 20) |
| 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) |
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 |