List SQL execution records¶
View SQL execution records in the current workspace by condition. Use the results to investigate failed or slow executions, or SQL run against a particular database. By default, the API returns only records run by the current identity. With the required permission, it can return records for the entire workspace.
POST https://moi.matrixorigin.cn/newmoi/query/history
Preparation before calling¶
Prepare a personal access token with access to the current workspace and the current workspace ID.
Request body¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/query/history" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"status": "Success",
"databases": ["analytics"],
"start": "2026-08-18T00:00:00Z",
"end": "2026-08-18T01:00:00Z",
"limit": 20,
"order_by": ["request_at"],
"order": "DESC"
}'
Parameter |
Type |
Required |
Description |
|---|---|---|---|
scope |
string |
No |
View records for the current identity or the current workspace. |
status |
string |
No |
Filters by execution status. |
user |
string[] |
No |
Filters by executing user. |
databases |
string[] |
No |
Filters by database name. |
statement |
string |
No |
Performs a contains match on SQL text. |
query_type |
string[] |
No |
Filters by statement category: |
duration |
unsigned integer |
No |
Minimum execution duration, in nanoseconds. |
start |
string |
No |
Query start time, for example |
end |
string |
No |
Query end time, for example |
statement_id |
string |
No |
Filters by statement ID. |
transaction_id |
string |
No |
Filters by exact transaction ID. |
session_id |
string |
No |
Filters by session ID. |
selected_field |
string[] |
No |
Specifies fields to return. |
sql_source_type |
string[] |
No |
Filters by SQL source. |
offset |
unsigned integer |
No |
Zero-based offset. Default: |
limit |
unsigned integer |
No |
Maximum records to return in one request. |
order_by |
string[] |
No |
Sort fields. |
order |
string |
No |
Sort direction. |
cu |
unsigned integer |
No |
Capacity-usage threshold. |
Read scope
|
Records returned |
Permission |
|---|---|---|
self |
Records for the current identity. |
Default scope. |
workspace |
Workspace-wide records. |
Requires workspace audit read permission. |
Query time and ID
Specify a complete date, time, and time zone. If both the start and end times are omitted, the API queries records from the five minutes before the request. You can specify only one of the times as a query boundary.
For a complete statement ID or session ID, the API performs an exact match. For a valid ID fragment, it matches records that contain the fragment. An ID fragment can contain only letters, numbers, and hyphens.
Select returned content
If you do not specify returned fields, the API returns its default fields. Results always include the request time whether or not you specify fields. If you do not specify SQL sources, the API returns only user SQL and external SQL. When the page size is omitted or 0, the API uses 10; the maximum is 1000. The capacity-usage filter takes effect only when the current deployment supports it and the threshold is greater than 0.
Sortable fields
If order_by is omitted, the API orders records by request time in descending order. order: DESC retains descending order; other values are handled as ascending order.
Field |
Meaning |
|---|---|
request_at |
Request time. |
response_at |
Response time. |
duration |
Execution duration. |
rows_read |
Number of rows read. |
bytes_scan |
Number of bytes scanned. |
cu |
Capacity usage. |
Read the next page
To read the next page, increase offset by the number of records actually returned in the current response and keep the original filters. For example, if the first page uses offset: 0 and limit: 20, make the following request for the next page:
curl -X POST "https://moi.matrixorigin.cn/newmoi/query/history" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"status": "Success",
"databases": ["analytics"],
"start": "2026-08-18T00:00:00Z",
"end": "2026-08-18T01:00:00Z",
"offset": 20,
"limit": 20,
"order_by": ["request_at"],
"order": "DESC"
}'
Stop paging when the accumulated number of records reaches the total or the current response has no records.
Success response¶
On success, the API returns SQL execution records. An empty data.query_list means no records can be returned for the current filters; this does not mean that SQL execution failed.
{
"code": "OK",
"msg": "OK",
"data": {
"total": 1,
"offset": 0,
"limit": 20,
"query_list": [
{
"statement_id": "5c6f22fb-ef0e-4f46-b06f-c31e1a7afb48",
"database": "analytics",
"statement": "SELECT * FROM orders",
"request_at": "2026-08-18T00:30:00Z",
"response_at": "2026-08-18T00:30:01Z",
"duration": 1000,
"status": "Success",
"query_type": "DQL",
"result_count": 10
}
]
}
}
Field |
Type |
Description |
|---|---|---|
code |
string |
|
msg |
string |
|
data.total |
integer |
Total number of records that match the filters. |
data.offset |
unsigned integer |
Offset used in this response. |
data.limit |
unsigned integer |
Actual per-page limit used in this response. |
data.query_list |
object[] |
SQL execution records. |
data.query_list[].statement_id |
string |
Statement ID. |
data.query_list[].transaction_id |
string |
Transaction ID. |
data.query_list[].session_id |
string |
Session ID. |
data.query_list[].account |
string |
Account used for execution. |
data.query_list[].user |
string |
Executing user. |
data.query_list[].host |
string |
Execution host. |
data.query_list[].database |
string |
Database used for execution. |
data.query_list[].statement |
string |
SQL statement text. |
data.query_list[].statement_tag |
string |
Statement tag. |
data.query_list[].statement_fingerprint |
string |
Statement fingerprint. |
data.query_list[].node_uuid |
string |
Execution node UUID. |
data.query_list[].node_type |
string |
Execution node type. |
data.query_list[].request_at |
string |
Execution start time. |
data.query_list[].response_at |
string |
Execution end time. |
data.query_list[].duration |
unsigned integer |
Execution duration in nanoseconds. |
data.query_list[].status |
string |
Execution status. |
data.query_list[].error_code |
string |
Error code. |
data.query_list[].error |
string |
Error message. |
data.query_list[].exec_plan |
string |
Stored execution profile. |
data.query_list[].rows_read |
unsigned integer |
Number of rows read. |
data.query_list[].bytes_scan |
unsigned integer |
Number of bytes scanned. |
data.query_list[].statement_type |
string |
Statement type. |
data.query_list[].query_type |
string |
Statement category. |
data.query_list[].role_id |
unsigned integer |
Execution role ID. |
data.query_list[].sql_source_type |
string |
SQL source type. |
data.query_list[].result_count |
integer |
Number of result rows. |
data.query_list[].cu |
number |
Capacity usage. |
data.query_list[].connection_id |
integer |
Database connection ID. |
Error response¶
{
"code": "ErrParamInvalid",
"msg": "Invalid request parameter",
"data": null
}
Field |
Type |
Description |
|---|---|---|
code |
string |
Error code. |
msg |
string |
Error message. |
data |
null |
— |
Next steps¶
Select an SQL execution record¶
To continue troubleshooting, select an SQL execution record from the results and note its statement ID and execution time. You can then get SQL execution details or get the SQL execution profile.
To run an SQL statement again, obtain the SQL text from the selected record, confirm the target database and the current identity’s permissions, then execute SQL.