Event contract
Fields the query expects
| Field | Type | Why it exists |
|---|---|---|
| timestamp_utc | Timestamp | Query completion time. |
| database_system | Utf8 | Database system name. |
| operation_name | Utf8 | SELECT, INSERT, or another controlled operation. |
| query_fingerprint | Utf8 | Normalized statement shape without values. |
| duration_ms | Float64 | Application-observed query duration. |
| request_id | Utf8 | Safe parent request identifier. |
Copy the query
SELECT
database_system,
operation_name,
query_fingerprint,
COUNT(*) AS calls,
SUM(duration_ms) AS total_time_ms,
approx_percentile_cont(duration_ms, 0.95) AS p95_duration_ms,
COUNT(DISTINCT request_id) AS affected_requests
FROM database_query_events
WHERE timestamp_utc >= now() - INTERVAL '24 hours'
GROUP BY database_system, operation_name, query_fingerprint
ORDER BY total_time_ms DESC
LIMIT 20;This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions against your own data. Read the testing methodology.
Query result
Total query time by fingerprint
The project list has lower tail latency but consumes more aggregate request time.
| database_system | operation_name | query_fingerprint | calls | total_time_ms | p95_duration_ms | affected_requests |
|---|---|---|---|---|---|---|
| postgresql | SELECT | project-list-v4 | 18,400 | 1,288,000 | 142 | 9,200 |
| postgresql | SELECT | monthly-report-v2 | 420 | 924,000 | 4,180 | 410 |
Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.
Reproduce the example
Download the public fixture
The JSON bundle includes the typed event contract, illustrative input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.
How the SQL works
- 1Total time combines volume and latency into an impact ranking.
- 2p95 keeps a low-volume pathological query visible.
- 3Affected requests distinguishes repeated calls such as N+1 behavior.
Edge cases to decide
- Application duration includes pool and network effects unless separately instrumented.
- Never log bound SQL values.
- Sampling needs weighted counts before comparing total impact.
Recommended dashboard
- Bars: total_time_ms by fingerprint
- Table: calls, p95, and affected requests
- Trend: total query time by release
Alert guidance
Review sustained total-time growth; page only when it drives a customer-facing reliability objective.
Read alert setupPut the recipe to work
Related instrumentation and guides
Continue the analysis
Find Slow Database Queries by Fingerprint
Rank normalized database operations by slow-query rate, average duration, and worst observed duration without storing raw SQL or parameters.
Open recipeMeasure Database Connection-Pool Saturation
Measure average pool utilization, queued acquisition waits, timeouts, and idle capacity by application service.
Open recipeCalculate Database Transaction Rollback Rate
Compare committed and rolled-back transactions by service while preserving error categories, duration, and affected accounts.
Open recipeRun it on real events
Create a table, adapt the fields, and save the result
Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.