Skip to content
Partner Developer Portal

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.

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.

  • 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.
  • total_rows — Total number of rows read or processed during execution.
  • output_rows — Number of rows returned to the caller.
  • 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).
  • cumulative_memory — Peak cumulative memory allocated across all query stages, in bytes.
  • failure_info — Structured details about the failure if query_state is FAILED; NULL for successful queries.
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"]
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_info
FROM explorer_open_safely.user_query_utilisation
ORDER BY create_time DESC;
SELECT
usr,
client_tags,
query,
query_state,
failure_info,
create_time,
end_time
FROM explorer_open_safely.user_query_utilisation
WHERE 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_time
FROM explorer_open_safely.user_query_utilisation
WHERE query_state = 'FINISHED'
ORDER BY wall_time_ms DESC;