MATIH Platform is in active MVP development. Documentation reflects current implementation status.
9. Query Engine & SQL
Query Analytics
Insights

Query Insights

The insights endpoint generates actionable recommendations based on query execution patterns, performance anomalies, and optimization opportunities.


Get Insights

GET /v1/analytics/insights
curl "http://query-engine:8080/v1/analytics/insights?days=7" \
  -H "Authorization: Bearer $JWT_TOKEN"
[
  {
    "id": "insight-001",
    "type": "SLOW_QUERY_PATTERN",
    "severity": "WARNING",
    "title": "Repeated slow query pattern detected",
    "description": "Query pattern 'SELECT * FROM orders JOIN...' has been executed 450 times with average latency of 8.5s",
    "recommendation": "Consider creating a materialized view for this join pattern",
    "affectedQueries": 450,
    "estimatedImpact": "Could reduce average latency to ~200ms",
    "createdAt": "2026-02-12T08:00:00Z",
    "acknowledged": false
  },
  {
    "id": "insight-002",
    "type": "LOW_CACHE_HIT_RATE",
    "severity": "INFO",
    "title": "Cache hit rate below threshold",
    "description": "Cache hit rate is 18% for the 'analytics' schema, below the target of 30%",
    "recommendation": "Enable cache warming for frequently-accessed analytics queries",
    "estimatedImpact": "Could increase hit rate to ~40% and save 2,000ms avg per query",
    "createdAt": "2026-02-12T08:00:00Z",
    "acknowledged": false
  }
]

Insight Types

TypeDescription
SLOW_QUERY_PATTERNRepeated execution of slow query patterns
LOW_CACHE_HIT_RATECache hit rate below target threshold
HIGH_FAILURE_RATEElevated query failure rate
RESOURCE_BOTTLENECKCPU, memory, or I/O constraints detected
QUERY_OPTIMIZATIONSpecific query can be optimized
ENGINE_MISMATCHQueries routed to suboptimal engine
QUOTA_WARNINGApproaching query quota limits

Acknowledge an Insight

Mark an insight as reviewed to remove it from active alerts:

curl -X POST http://query-engine:8080/v1/analytics/insights/insight-001/acknowledge \
  -H "Authorization: Bearer $JWT_TOKEN"
{
  "insightId": "insight-001",
  "acknowledged": true,
  "acknowledgedAt": "2026-02-12T10:30:00Z"
}