Slow Queries
The slow queries endpoint returns the most time-consuming queries executed within a given period, enabling performance engineers to identify and optimize bottlenecks.
Endpoint
GET /v1/analytics/slow-queriesQuery Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
days | int | 7 | Time period to analyze |
limit | int | 10 | Maximum number of slow queries to return |
curl Example
curl "http://query-engine:8080/v1/analytics/slow-queries?days=7&limit=5" \
-H "Authorization: Bearer $JWT_TOKEN"[
{
"executionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"queryText": "SELECT o.*, c.name FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.created_at > '2026-01-01' ORDER BY o.total DESC",
"engineType": "TRINO",
"executionTimeMs": 34200,
"bytesScanned": 2147483648,
"rowCount": 50000,
"userId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"submittedAt": "2026-02-10T14:30:00Z",
"status": "COMPLETED"
},
{
"executionId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"queryText": "SELECT product_category, region, SUM(revenue) FROM sales_facts GROUP BY CUBE(product_category, region)",
"engineType": "TRINO",
"executionTimeMs": 28500,
"bytesScanned": 5368709120,
"rowCount": 1200,
"submittedAt": "2026-02-11T09:15:00Z",
"status": "COMPLETED"
}
]Implementation
The controller retrieves slow queries from the analytics service and applies the limit:
@GetMapping("/slow-queries")
public ResponseEntity<List<QueryAnalytics.QueryInfo>> getSlowQueries(
@RequestParam(defaultValue = "7") int days,
@RequestParam(defaultValue = "10") int limit) {
UUID tenantId = SecurityUtils.getCurrentTenantId();
QueryAnalytics analytics = analyticsService.getAnalytics(tenantId, days, "day");
return ResponseEntity.ok(analytics.getTopSlowQueries().stream()
.limit(limit)
.toList());
}Failed Queries
A separate endpoint returns recent failed queries for debugging:
curl "http://query-engine:8080/v1/analytics/failed-queries?days=7&limit=10" \
-H "Authorization: Bearer $JWT_TOKEN"[
{
"executionId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
"queryText": "SELECT * FROM nonexistent_table",
"engineType": "TRINO",
"executionTimeMs": 120,
"errorMessage": "Table 'iceberg.analytics.nonexistent_table' does not exist",
"submittedAt": "2026-02-12T08:45:00Z",
"status": "FAILED"
}
]