Definition
The Query Utilization data model surfaces runtime and resource metrics for queries executed by authenticated users against the OpenSafely data platform. It is automatically scoped to the currently authenticated user, providing self-service visibility into query performance, resource consumption, and execution history.
Information
Section titled “Information”Each record in the Query Utilization model represents a single query execution event. Records are automatically filtered to the current authenticated user, ensuring users only observe their own query history.
Results are ordered by create_time descending so the most recently submitted
queries appear first.
Key Data Fields
Section titled “Key Data Fields”Identity & Classification
Section titled “Identity & Classification”- usr — The username of the user who submitted the query.
- query — The full SQL text of the executed query.
- query_state — Lifecycle state of the query (e.g.
FINISHED,FAILED,RUNNING). - query_type — Category of the query (e.g.
SELECT,INSERT). - query_plan — The internal execution plan produced by the query engine.
Row Metrics
Section titled “Row Metrics”- total_rows — Total number of rows read or processed during execution.
- output_rows — Number of rows returned to the caller.
Timing Metrics
Section titled “Timing Metrics”- cpu_time_ms — Total CPU time consumed across all workers, in milliseconds.
- wall_time_ms — End-to-end elapsed (wall-clock) time, in milliseconds.
- queued_time_ms — Time the query spent waiting in the scheduler queue before execution started, in milliseconds.
- analysis_time — Duration of the query analysis (planning) phase.
- execution_time — Duration of the actual execution phase.
- create_time — Timestamp when the query was submitted to the engine.
- end_time — Timestamp when the query completed (successfully or otherwise).
Resource Metrics
Section titled “Resource Metrics”- cumulative_memory — Peak cumulative memory allocated across all query stages, in bytes.
Error Information
Section titled “Error Information”- failure_info — Structured details about the failure if
query_stateisFAILED;NULLfor successful queries.
Overview
Section titled “Overview”flowchart TB
subgraph container["Query Utilization"]
n1["Identity & Classification"]
n2["Row Metrics"]
n3["Timing Metrics"]
n4["Resource Metrics"]
n5["Error Information"]
end
n6["Query Execution Event"] --> container
container --> n7["Query Utilization Model"]
Examples
Section titled “Examples”View your most recent queries
Section titled “View your most recent queries”SELECT usr, query, query_state, query_type, total_rows, output_rows, cpu_time_ms, wall_time_ms, queued_time_ms, cumulative_memory, analysis_time, execution_time, create_time, end_time, failure_infoFROM user_query_utilizationORDER BY create_time DESC;Find failed queries
Section titled “Find failed queries”SELECT usr, query, query_state, failure_info, create_time, end_timeFROM user_query_utilizationWHERE query_state = 'FAILED'ORDER BY create_time DESC;Identify long-running or resource-intensive queries
Section titled “Identify long-running or resource-intensive queries”SELECT usr, query, query_state, wall_time_ms, cpu_time_ms, cumulative_memory, total_rows, output_rows, create_timeFROM user_query_utilizationWHERE query_state = 'FINISHED'ORDER BY wall_time_ms DESC;
