Definition
The Query Utilisation data model surfaces runtime and resource metrics for
queries submitted through the OpenSAFELY data platform. OpenSAFELY software
submits queries using a service user’s Cognito account, so usr records that
service user rather than the researcher who submitted the job. OpenSAFELY
provides the submitting user’s details in client_tags when the query is
submitted.
Information
Section titled “Information”Each record in the Query Utilisation model represents a single query execution
event. The view filters records to users associated with the same account as the
current user. This account-level filter is intentional: users with access to the
view who belong to the OpenSAFELY account can see metrics for queries submitted
by the OpenSAFELY service. These metrics help investigate query failures and
long-running queries. Because the service submits the queries, usr identifies
the service user rather than the researcher; use client_tags for the
submitting user’s details.
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 Cognito username associated with query execution. For OpenSAFELY, this is the service user used by the software, not the researcher who submitted the job.
- client_tags — Information about the OpenSAFELY user or researcher who submitted the query, supplied by OpenSAFELY software when the query is submitted.
- 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 Utilisation"]
n1["Identity & Classification"]
n2["Row Metrics"]
n3["Timing Metrics"]
n4["Resource Metrics"]
n5["Error Information"]
end
n6["Query Execution Event"] --> container
container --> n7["Query Utilisation Model"]
Examples
Section titled “Examples”View your most recent queries
Section titled “View your most recent queries”SELECT usr, client_tags, 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 explorer_open_safely.user_query_utilisationORDER BY create_time DESC;Find failed queries
Section titled “Find failed queries”SELECT usr, client_tags, query, query_state, failure_info, create_time, end_timeFROM explorer_open_safely.user_query_utilisationWHERE 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, client_tags, query, query_state, wall_time_ms, cpu_time_ms, cumulative_memory, total_rows, output_rows, create_timeFROM explorer_open_safely.user_query_utilisationWHERE query_state = 'FINISHED'ORDER BY wall_time_ms DESC;