← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Slow Query Log

Performance PHP 5.0+ Beginner
debt(d7/e3/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7), because slow queries are silent in production unless the slow query log is explicitly enabled. The common mistake is not enabling it at all, meaning degraded performance is invisible. Tools like mysql-slow-query-log, pt-query-digest, laravel-debugbar, and clockwork can surface the data once enabled, but they don't warn you that the log is disabled — a developer must proactively check. Not quite d9 because once enabled, the tooling is well-automated.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3), because the quick_fix involves enabling slow_query_log with long_query_time=0.1, running EXPLAIN on flagged queries, and adding a covering index. This is more than a single-line patch (it touches MySQL config, query analysis, and index creation) but is contained within a small focused workflow rather than spanning multiple application files — so e3 rather than e5.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3), because the slow query log is a MySQL-level configuration concern. Once properly configured it doesn't impose ongoing structural weight on the application codebase itself. The common mistakes (log not rotated, threshold too high) are operational rather than architectural burdens, and the impact is isolated to database operations rather than reaching across the whole system.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5), because the misconception is well-defined: developers assume the slow query log only captures queries exceeding long_query_time, but with log_queries_not_using_indexes=ON it also captures fast full-table-scan queries. Additionally, the common default of long_query_time=10s misses user-visible latency at 500ms. These are documented gotchas that experienced developers learn but that trip up beginners and intermediate users.

About DEBT scoring →

Also Known As

MySQL slow query log slow log long_query_time

TL;DR

A database log of queries exceeding a time threshold — the first place to look when diagnosing PHP application performance problems.

Explanation

MySQL's slow query log records queries taking longer than long_query_time (set to 1–2 seconds in production, 0 in development to catch all queries). Enable with slow_query_log=ON and log_queries_not_using_indexes=ON. Tools like mysqldumpslow, pt-query-digest (Percona Toolkit), or MySQL Workbench aggregate and rank slow queries by frequency and total time. In PHP applications, ORMs can hide expensive queries — the slow query log surfaces them regardless of abstraction layer. Pair with EXPLAIN to understand why a slow query is slow and what index would fix it.

Common Misconception

The slow query log only captures queries over the long_query_time threshold. With log_queries_not_using_indexes=ON, the slow log also captures fast queries that perform full table scans — often more valuable than catching slow queries that already have alerts.

Why It Matters

The slow query log captures every query exceeding a configurable threshold — it is the fastest way to find which queries are degrading production performance without any application code changes.

Common Mistakes

  • Not enabling the slow query log in production — slow queries are invisible without it.
  • Setting long_query_time too high (10s) — queries taking 500ms still cause user-visible latency.
  • Not enabling log_queries_not_using_indexes — catches missing index issues the time threshold misses.
  • Not rotating or monitoring the slow query log file — it grows indefinitely and can fill the disk.

Code Examples

✗ Vulnerable
# my.cnf — slow query log disabled:
[mysqld]
# slow_query_log = 1          ; Not set
# slow_query_time = 0.5       ; Not set — use 0.5s not 10s
# log_queries_not_using_indexes = 1 ; Not set

# Correct:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 0.5
log_queries_not_using_indexes = 1
✓ Fixed
; MySQL slow query log — log queries exceeding threshold
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1          ; seconds — log queries over 1s
log_queries_not_using_indexes = 1  ; also log full-table scans

; Analyse with pt-query-digest (Percona Toolkit)
$ pt-query-digest /var/log/mysql/slow.log
; Shows: call count, total time, average, worst offenders

; PostgreSQL equivalent:
; log_min_duration_statement = 1000   ; milliseconds
; log_destination = 'csvlog'

Added 15 Mar 2026
Edited 22 Mar 2026
Views 68
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 3 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T 3 pings F 0 pings S 2 pings S 5 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
ChatGPT 1
Scrapy 11 Amazonbot 10 Perplexity 9 ChatGPT 5 Ahrefs 4 Google 4 SEMrush 4 Unknown AI 3 Claude 2 Qwen 2 Meta AI 1 Bing 1 PetalBot 1
crawler 52 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Enable slow_query_log with long_query_time=0.1, run EXPLAIN on flagged queries, add covering index on WHERE + ORDER BY columns
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
MySQL slow_query_log entries; EXPLAIN showing type:ALL full table scan; Laravel Debugbar query times >100ms
Auto-detectable: ✓ Yes mysql-slow-query-log laravel-debugbar clockwork pt-query-digest
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Low ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant