LexisNexis Risk Solutions runs this query from an internal fraud-review dashboard to pull flagged risk reports for name-matched entities. It used to return in under a second; now, as the risk_reports table has grown past tens of millions of rows, analysts wait 20-30 seconds every time they load the dashboard.
-- entities(id INT PRIMARY KEY, full_name TEXT, ssn_last4 VARCHAR(4), state VARCHAR(2))
-- risk_reports(id INT PRIMARY KEY, entity_id INT, created_at TIMESTAMP, risk_score INT, status VARCHAR(20))
-- indexes: risk_reports(entity_id), risk_reports(created_at)
SELECT *
FROM risk_reports r
WHERE DATE(r.created_at) = '2026-09-01'
AND r.status = 7
AND r.entity_id IN (
SELECT e.id FROM entities e WHERE e.full_name LIKE '%smith%'
)
ORDER BY r.risk_score DESC;
How would you optimize this query? Walk through what's forcing a full scan today, table by table, and what you'd change so the existing indexes on risk_reports(entity_id) and risk_reports(created_at) can actually be used.
| Column | Type | Description |
|---|---|---|
| idPK | INT | Entity identifier |
| full_name | TEXT | Entity full name |
| ssn_last4 | VARCHAR(4) | Last four digits of the SSN |
| state | VARCHAR(2) | Two-letter state code |
| Column | Type | Description |
|---|---|---|
| idPK | INT | Risk report identifier |
| entity_id | INT | Referenced entity identifier |
| created_at | TIMESTAMP | Report creation timestamp |
| risk_score | INT | Calculated risk score |
| status | VARCHAR(20) | Report workflow status |