Skip to main content

Query History

Gnok records every query with its full execution lifecycle and performance metrics. Query history is available for debugging slow queries, cost attribution across users and workloads, compliance auditing, and capacity planning.

Query Lifecycle​

Every query passes through a series of status transitions:

StatusDescription
queuedQuery has been received and is waiting for resources (admission control)
runningQuery is actively executing across coordinator and workers
completedQuery finished successfully and returned results
failedQuery terminated with an error (parse failure, execution error, OOM, etc.)
cancelledQuery was cancelled by the user, a timeout, or the query killer

Record Schema​

Each query history record contains the following fields:

FieldTypeDescription
query_idstringUnique identifier for the query
statusstringCurrent lifecycle status
sqlstringThe SQL text that was submitted
user_idstringAuthenticated user who submitted the query
tenant_idstringOrganization the query belongs to
query_typestringStatement type: select, insert, update, delete, ddl, etc.
resource_groupstringResource group path the query was admitted to (e.g., /root/interactive)
priorityintegerExecution priority (higher = more important)
queued_attimestampWhen the query was received
started_attimestampWhen execution began (null if cancelled before running)
ended_attimestampWhen the query reached a terminal status
duration_msintegerWall-clock execution time in milliseconds
rows_producedintegerNumber of result rows returned
bytes_scannedintegerTotal bytes read from storage
fragmentsintegerNumber of distributed fragments executed
error_messagestringError details (for failed queries)
cu_consumedfloatCompute units consumed (warehouse size CU rate * execution time)

Querying History​

REST API​

In Studio, use History. Calling the HTTP API from outside Studio isn't self-service yet; email support@gnok.io to set up client connectivity. query.example.com below is a placeholder.

List Query History​

GET /api/query-history

Query parameters:

ParameterTypeDefaultDescription
limitinteger50Maximum records to return (max 500)
offsetinteger0Pagination offset
statusstring(all)Filter by status: completed, failed, cancelled
user_idstring(all)Filter by user ID
query_typestring(all)Filter by query type: select, insert, etc.

Example: list recent failed queries

curl -s 'https://query.example.com/api/query-history?status=failed&limit=50' \
-H "Authorization: Bearer $TOKEN" | jq

Response:

[
{
"queryId": "a1b2c3d4-...",
"status": "failed",
"sql": "SELECT * FROM nonexistent_table",
"userId": "alice",
"tenantId": "acme-corp",
"queryType": "select",
"resourceGroup": "/root/interactive",
"priority": 50,
"queuedAt": "2026-03-27T10:15:00Z",
"startedAt": "2026-03-27T10:15:00Z",
"endedAt": "2026-03-27T10:15:00Z",
"durationMs": 12,
"rowsProduced": 0,
"bytesScanned": 0,
"fragments": 0,
"errorMessage": "Table 'nonexistent_table' not found in schema 'public'",
"cuConsumed": 0.0
}
]

Get a Specific Query​

GET /api/query-history/{query_id}
curl -s 'https://query.example.com/api/query-history/a1b2c3d4-...' \
-H "Authorization: Bearer $TOKEN" | jq

SQL Interface​

Query history is also available through the SQL SHOW command:

-- List recent queries (default limit 50)
SHOW QUERY HISTORY;

-- With filters
SHOW QUERY HISTORY LIMIT 100;

Use Cases​

Debugging Slow Queries​

Identify the slowest queries over a time period to prioritize optimization efforts:

curl -s 'https://query.example.com/api/query-history?status=completed&limit=100' \
-H "Authorization: Bearer $TOKEN" \
| jq 'sort_by(-.durationMs) | .[0:10] | .[] | {queryId, sql, durationMs, bytesScanned}'

Cost Attribution​

Sum compute units consumed per user for chargeback:

curl -s 'https://query.example.com/api/query-history?limit=500' \
-H "Authorization: Bearer $TOKEN" \
| jq 'group_by(.userId) | map({user: .[0].userId, total_cu: (map(.cuConsumed // 0) | add)})'

Audit Trail​

Query history provides a record of every SQL statement executed against the system, including the authenticated user, timestamp, and result status. This supports compliance requirements for data access auditing.

Capacity Planning​

Analyze query patterns over time to identify peak usage periods, resource-intensive workloads, and opportunities to right-size warehouse capacity.

Storage and Retention​

History availability and retention are managed by Gnok for your account. Use Studio History to inspect available records; arrange any required exports or longer retention through your administrator and support@gnok.io.