Produce a slow-query report for the seeded dataset in both PostgreSQL and MongoDB that a colleague could act on without talking to you. It must rank candidates by recoverable database time rather than by duration, name the single highest-value fix in each engine, and identify at least one query whose recoverable time is near zero despite consuming significant total time — with an explanation of where its real fix lives.
Reset pg_stat_statements and drop system.profile immediately before your measurement window, so the report describes a known period rather than the whole history of the container. Generate load with a short script that mixes the query shapes you care about at realistic ratios — a single hand-run query will not produce a leaderboard worth ranking. If a MongoDB shape appears twice with different planSummary values, that is not a bug in your aggregation: it means the same query sometimes uses an index and sometimes does not, and it belongs in the report.
$ docker compose up -d && ./seed.sh
pg: users 200000, orders 2000000, events 5000000
mongo: users 200000, orders 2000000, events 5000000
$ ./generate-load.sh --duration 300
generated 412,004 operations across 6 shapes
$ psql -f prioritise.sql qp
query | calls | mean_ms | total_sec | pct | rows/call | blocks/call
----------------------------------+---------+---------+-----------+------+-----------+------------
SELECT * FROM users WHERE id = $1| 312004 | 0.48 | 150 | 41.2 | 1.0 | 0.1
SELECT * FROM orders WHERE use...| 62011 | 71.90 | 446 | 38.1 | 0.6 | 3120.0
SELECT count(*) FROM events WH...| 12 | 4102.30 | 49 | 4.2 | 1.0 | 88400.0
top candidate: orders by (user_id, status)
446s of 1170s total, 3120 disk blocks per call to return 0.6 rows
headroom ~99%, synchronous (order history page) -> fix first
near-zero headroom: users by id
41.2% of database time, 1 row per call, 0.1 blocks per call
already optimal; 312k calls in 300s is an N+1 in the order-list
endpoint. Fix belongs in the application, not the database.