Query History
On this page
Overview
A high-frequency event-tracing feature has been introduced in SingleStore 8.
Query event tracing, the first of this event-tracing feature, is designed to help identify which queries take the longest or that fail so they can be isolated and optimized.
For query execution reporting, Query_
is the initial event type to be implemented, where each query execution and its details can be traced and viewed in near real-time.
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 traced 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"",""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"",""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:{"user_name": string, (empty string if the user has been dropped)"connection_id": integer,"activity_name": string,"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)"success": bool,[ "error_code": string, ] (field only present if success = false)[ "error_message": string, ] (field only present if success = false)"start_time": string (datetime(6)),"duration_ms": bigint,"context_database": string}Note: Currently, when a multi-insert query is traced, a
plan_
ofid -1
is reflected without an associatedactivity_
.name 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","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"",""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"",""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;
In this section
Last modified: September 16, 2024