Query History
On this page
Overview
SingleStore supports high-frequency event-tracing.
Query event tracing is designed to help identify which queries take the longest or that fail so they can be isolated and optimized.
For query execution reporting, the Query_
trace monitors query execution details and can be viewed in near real-time.
Enhanced query tracing allows users to trace the high-level execution metrics collected by MV_Query_
traces.Query_
traces.
Query event traces are configurable, where a query execution may only be traced if it takes longer than, for example, 1,000 milliseconds (1 second) to run, where the query text may be set to either be included or omitted.
Event Type |
|
Engine Variable |
Set the value of this engine variable to |
Parameter |
Value(s) |
Capture query text? |
|
Record queries that take x amount of time to complete, in milliseconds |
While |
Trace all queries that have failed |
|
Prerequisites
-
A self-managed cluster running SingleStore version 8.
5 or later -
For Toolbox-based deployments:
-
The latest version of SingleStore Toolbox installed on the main deployment host
-
Cluster monitoring must be enabled to review the Query History dashboard.
If cluster monitoring is already configured, you can download and import the Query History dashboard.
-
-
For Operator-based deployments, cluster monitoring must be enabled to view the Query History dashboard.
If cluster monitoring is already configured, you can download and import the Query History dashboard.
The MV_ TRACE_ EVENTS Information Schema
The MV_
information schema is a ring buffer with a size defined by the value of the trace_
engine variable.
While MV_
can be used to view the most recent events that meet a specified criteria, the information displayed is only temporary.
View MV_ TRACE_ EVENTS
The following examples can be used to record those queries that take longer than 1,000 milliseconds, or one second, to run, which can be used to create a collection of all of the expensive events that have occurred over a specified period of time.
Successful Queries
Run the following to display those SQL statements that have been executed successfully.
Note that the following steps are provided to demonstrate how the query events are traced, and only provide a glimpse into which queries are captured.
-
Set the events queue size,
trace_
, to 16,000,000 bytes.events_ queue_ size SET GLOBAL trace_events_queue_size = 16000000; -
Enable the
Query_
event type.completion CREATE EVENT TRACE Query_completion WITH (Query_text = on, Duration_threshold_ms = 1000); -
Display the query trace events.
SELECT * FROM information_schema.MV_TRACE_EVENTS;NODE_ID,NODE_IP,NODE_TYPE,NODE_START_EPOCH_S,EVENT_ID,EVENT_TYPE,TIME,DETAILS 1,127.0.0.1,MA,1698096978,1,Query_completion,2023-10-25 16:39:51.747556,"{""activity_name"":""Select_MV_PROCESS_PERMISSIONS__et_al_453a6b42e2c4cc91"",""connection_id"":44,""context_database"":"""",""duration_ms"":76,""plan_id"":55,""query_text"":""select * from information_schema.mv_trace_events"",""resource_pool_name"":""default_pool"",""row_count"":86,""start_time"":""2023-10-25 16:39:51.671264"",""success"":1,""user_name"":""root""}" 1,127.0.0.1,MA,1698096978,2,Query_completion,2023-10-25 16:40:17.988318,"{""activity_name"":""Select_MV_PROCESS_PERMISSIONS__et_al_453a6b42e2c4cc91"",""connection_id"":44,""context_database"":"""",""duration_ms"":2,""plan_id"":55,""query_text"":""select * from information_schema.mv_trace_events"",""resource_pool_name"":""default_pool"",""row_count"":89,""start_time"":""2023-10-25 16:40:17.986134"",""success"":1,""user_name"":""root""}"
The payload that describes an event is stored in the
DETAILS
JSON field that contains the following fields:{"activity_name": string,"connection_id": integer,"context_database": string,"duration_ms": bigint,"plan_id": integer,"query_text": string, (on by default; can be sizeable as comments are included)"resource_pool_name": string, (empty if no resource pool)"row_count": integer,"start_time": string (datetime(6)),"success": bool,"user_name": string (empty string if the user has been dropped)[, "error_code": string, ] (field only present if success = false)[, "error_message": string ] (field only present if success = false)}Note: Currently, when a multi-insert query is traced, a
plan_
ofid -1
is reflected without an associatedactivity_
.name Note: For read queries,
row_
refers to the total number of rows sent back to the client.count For write queries, row_
refers to the total number of rows affected across the cluster.count The following is an example of the
DETAILS
column JSON output.The query_
contains literals (sanitized via the SECRET function), and includes comments.text {"activity_name":"Select_MV_PROCESS_PERMISSIONS__et_al_453a6b42e2c4cc91","connection_id":44,"context_database":"","duration_ms":76,"plan_id":55,"query_text":"select * from information_schema.mv_trace_events","resource_pool_name":"default_pool","row_count": 86,"start_time":"2023-10-25 16:39:51.671264","success":1,"user_name":"root"}
Failed Queries
Run the following to display those SQL statements that have failed to execute and the associated reason.
Note that the following steps are provided to demonstrate how the query events are traced, and they only provide a glimpse into which queries are captured.
-
Set the events queue size,
trace_
, to 16,000,000 bytes.events_ queue_ size SET GLOBAL trace_events_queue_size = 16000000; -
Enable the Query_
completion event type to capture failed queries. CREATE EVENT TRACE Query_completion WITH (Query_text = on, Duration_threshold_ms = 1000, Trace_all_failed_executions= on); -
Run the following to display the query events.
SELECT * FROM information_schema.MV_TRACE_EVENTS;NODE_ID,NODE_IP,NODE_TYPE,NODE_START_EPOCH_S,EVENT_ID,EVENT_TYPE,TIME,DETAILS 1,127.0.0.1,MA,1698096978,1,Query_completion,2023-10-25 16:39:51.747556,"{""activity_name"":""Select_MV_PROCESS_PERMISSIONS__et_al_453a6b42e2c4cc91"",""connection_id"":44,""context_database"":"""",""duration_ms"":76,""plan_id"":55,""query_text"":""select * from information_schema.mv_trace_events"",""resource_pool_name"":""default_pool"",""row_count"":86,""start_time"":""2023-10-25 16:39:51.671264"",""success"":1,""user_name"":""root""}" 1,127.0.0.1,MA,1698096978,2,Query_completion,2023-10-25 16:40:17.988318,"{""activity_name"":""Select_MV_PROCESS_PERMISSIONS__et_al_453a6b42e2c4cc91"",""connection_id"":44,""context_database"":"""",""duration_ms"":2,""plan_id"":55,""query_text"":""select * from information_schema.mv_trace_events"",""resource_pool_name"":""default_pool"",""row_count"":86,""start_time"":""2023-10-25 16:40:17.986134"",""success"":1,""user_name"":""root""}"
Time-Bound Queries
Run the following to display those SQL statements that are time-bound.
Note that the following steps are provided to demonstrate how the query events are traced, and only provide a glimpse into which queries are captured.
-
Set the events queue size,
trace_
, to 16,000,000 bytes.events_ queue_ size SET GLOBAL trace_events_queue_size = 16000000; -
Run the following to display just those query events that were created since a specified time
@t
.SET @t = NOW(6); /* Or use a desired time instead of the current time */ -
Run the following to display the query events.
SELECT * FROM information_schema.MV_TRACE_EVENTS WHERE TIME > @t;
Enhanced Query Tracing
Note
This is a Preview feature.
With enhanced query tracing, users can trace high-level execution metrics collected by MV_
Enhanced query tracing is controlled via a configuration option for Query_
called Enhanced_
.lite
, full
, and off
.off
by default.
For the remainder of this document, "enhanced query tracing" refers to Query_
tracing with Enhanced_
set to lite
or full
.
Usage
If an existing Query_
event is present on the cluster, drop that event before enabling enhanced query tracing.
DROP EVENT TRACE Query_completion;
Create an event trace with Enhanced_
set to off
, lite
, or full
.
CREATE EVENT TRACE Query_completion WITH(Enhanced_stats_collection = {off | lite | full}, ...);
The new configuration will update asynchronously across all nodes in the cluster.
To view the configuration, query MV_CONFIGURATION
column.
Explanation of Modes
Off
High-level query execution stats from MV_
or MV_
are not collected.
Lite
Collects distributed high-level execution metrics of the query's execution and stores the aggregated metrics together with the Query_
event.
{"activity_name": "Update_t__et_al_290900f5eb4d75d2","connection_id": 8,"context_database": "db","duration_ms": 33,"enhanced_stats": {"aggregated_stats": {"avgMemoryBytes": 263055,"blobCacheMissBytes": 0,"blobCacheWaitTimeMs": 0,"cpuTimeMs": 54,"cpuWaitTimeMs": 0,"diskLogicalReadBytes": 40530,"diskLogicalWriteBytes": 28784,"diskPhysicalReadBytes": 0,"diskPhysicalWriteBytes": 212992,"diskSpillingBytes": 0,"diskTimeMs": 0,"extractorTimeMs": 0,"lockTimeMs": 0,"logBufferLargeTxTimeMs": 0,"logBufferWaitMs": 0,"logBufferWriteBytes": 77009,"logFlushWaitMs": 0,"memoryMBSecs": 0.032894,"memoryMajorFaults": 0,"networkRecvBytes": 2961,"networkSendBytes": 4448,"networkTimeMs": 40,"rgQueuedTimeMs": 0,"rowLockTimeMs": 0,"transformTimeMs": 0,"wmQueuedTimeMs": 0}},"plan_id": 27,"query_text": "update t set b = b+1","resource_pool_name": "default_pool","row_count": 4,"start_time": "2025-03-05 16:39:01.411371","success": 1,"user_name": "root"}
Full
Collects the same stats as lite
.
{"activity_name": "Select_t1__et_al_54e9e5098b9ef23f","connection_id": 8,"context_database": "db","duration_ms": 244,"enhanced_stats": {"aggregated_stats": {"avgMemoryBytes": 18025,"blobCacheMissBytes": 0,"blobCacheWaitTimeMs": 0,"cpuTimeMs": 169,"cpuWaitTimeMs": null,"diskLogicalReadBytes": 748154,"diskLogicalWriteBytes": 818,"diskPhysicalReadBytes": null,"diskPhysicalWriteBytes": null,"diskSpillingBytes": 0,"diskTimeMs": null,"extractorTimeMs": 0,"lockTimeMs": 2,"logBufferLargeTxTimeMs": 0,"logBufferWaitMs": 0,"logBufferWriteBytes": 0,"logFlushWaitMs": 0,"memoryMBSecs": 0.01931,"memoryMajorFaults": null,"networkRecvBytes": 229227,"networkSendBytes": 6752,"networkTimeMs": 162,"rgQueuedTimeMs": 0,"rowLockTimeMs": 0,"transformTimeMs": 0,"wmQueuedTimeMs": 0},"distributed_stats": [{"info": {"node_id": 1},"stats": {"avgMemoryBytes": 14246,"blobCacheMissBytes": 0,"blobCacheWaitTimeMs": 0,"cpuTimeMs": 101,"cpuWaitTimeMs": null,"diskLogicalReadBytes": 55624,"diskLogicalWriteBytes": 142,"diskPhysicalReadBytes": null,"diskPhysicalWriteBytes": null,"diskSpillingBytes": 0,"diskTimeMs": null,"extractorTimeMs": 0,"lockTimeMs": 0,"logBufferLargeTxTimeMs": 0,"logBufferWaitMs": 0,"logBufferWriteBytes": 0,"logFlushWaitMs": 0,"memoryMBSecs": 0.003326,"memoryMajorFaults": null,"networkRecvBytes": 226569,"networkSendBytes": 3629,"networkTimeMs": 142,"rgQueuedTimeMs": 0,"rowLockTimeMs": 0,"transformTimeMs": 0,"wmQueuedTimeMs": 0}},{"info": {"node_id": 2},"stats": {"avgMemoryBytes": 19078,"blobCacheMissBytes": 0,"blobCacheWaitTimeMs": 0,"cpuTimeMs": 68,"cpuWaitTimeMs": null,"diskLogicalReadBytes": 692530,"diskLogicalWriteBytes": 676,"diskPhysicalReadBytes": null,"diskPhysicalWriteBytes": null,"diskSpillingBytes": 0,"diskTimeMs": null,"extractorTimeMs": 0,"lockTimeMs": 2,"logBufferLargeTxTimeMs": 0,"logBufferWaitMs": 0,"logBufferWriteBytes": 0,"logFlushWaitMs": 0,"memoryMBSecs": 0.015985,"memoryMajorFaults": null,"networkRecvBytes": 2658,"networkSendBytes": 3123,"networkTimeMs": 20,"rgQueuedTimeMs": 0,"rowLockTimeMs": 0,"transformTimeMs": 0,"wmQueuedTimeMs": 0}}]},"plan_id": 2,"query_text": "select a, b, data from t1 join t2 on a = id","resource_pool_name": "default_pool","row_count": 3,"start_time": "2025-01-29 14:45:32.790434","success": 1,"user_name": "root"}
Remarks
-
Some of the statistics collected are considered "advanced statistics" and are only collected when
read_
is set toadvanced_ counters ON
.Refer to Management Statistics Reference for details. When read_
is set toadvanced_ counters OFF
, the values for these statistics appear as null. -
In rare cases, when errors are encountered in query execution, or when certain activities are killed as part of normal query processing, some execution stats are not traced.
-
The execution metrics collected by enhanced query tracing may have noticeable differences and discrepancies from the same metrics collected by Historical Monitoring.
-
Runtime metrics are collected at a slightly different point in time in query execution for enhanced query tracing than they are for workload monitoring / profiling.
In the majority of cases, the difference should not be noticeable. -
For write queries with two-phase commit (2PC) enabled, enhanced query tracing includes stats collected by any internal
PREPARE
queries.In contrast, workload monitoring / profiling does not necessarily associate the internal PREPARE
query with the user query. -
Queries that create remote result tables on leaf nodes may have differences in metrics due to the difference in timing of the collection of metrics from the result tables between enhanced query tracing and workload monitoring / profiling.
-
Queries that are retried during execution (e.
g. during online failover) will have all of their attempts' stats collected and aggregated for enhanced query tracing as a single query execution (i. e. in one Query_
event).completion In contrast, for workload monitoring / profiling, every failed attempt increments the failure_
, and each retry is considered a separate execution.count
-
In this section
Last modified: March 12, 2025