Server
Slow query
Slow query is a database statement that runs longer than the limit you set for it. The limit is a number you choose, not a built-in property.
How it is measured
Turn on the slow query log with a threshold, such as `long_query_time = 1` in MySQL or `log_min_duration_statement = 500` in Postgres, and collect the statements. Aggregate by normalized query so you see total time, count and worst case.
Rank by total time, not worst case. A 120 ms query run 40,000 times a day costs more than a 9 second query run once.
Worked example
A WordPress site's slow log for one day lists a `wp_options` autoload query: 180 ms, run 31,000 times, 93 minutes in total. Next is a nightly report at 14 seconds, run once.
The options table has 6 MB of autoloaded transients from an old plugin. Clearing them cuts the query to 6 ms and removes about 90 minutes of daily database work, far more than tuning the report would have.
How it differs
A slow query is one statement over the time limit. An N+1 query is many fast statements that add up. A slow query excludes the repetition, and an N+1 excludes the single long statement. The slow log finds the first and rarely shows the second, so check query counts per request too.
Common errors
Setting the threshold so high that nothing is logged. Ranking by worst time instead of total. Tuning the query without reading the plan. Running EXPLAIN on a tiny dev database. Adding an index for every slow statement without checking write cost.
In practice
Turn on the slow log this week with a 500 ms threshold, summarise it after 24 hours, and take the top three by total time. Look at each plan and fix the cheapest first.