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:
  1. [Slow Query: 37ms] [SELECT * FROM `users` WHERE `status` = ?]

ItemDetail
Threshold20ms (logged when above 20)
Timed spanFrom just before pool.getConnection() until the result returns, including time spent waiting for a free connection
OutputDuration and the SQL with ? placeholders, without bound values
Destinationconsole.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:
SymptomLikely cause
The same SQL is sometimes fast, and slow entries cluster under loadPool queueing; consider raising connectionLimit (see Configuration)
One statement always crosses the thresholdThe SQL itself is slow; inspect indexes with EXPLAIN


中文