更新时间:2025-09-25 GMT+08:00
分享

查询SQL链路信息

功能介绍

主要用于查询SQL某次执行(对应归一化SQL ID和唯一SQL ID传值)过程中的全部链路信息,包含各个阶段的多维度耗时统计。对于分布式版实例,可查询对应SQL的完整执行链路,包含CN和DN上SQL语句的耗时分析。

调试

您可以在API Explorer中调试该接口。

URI

GET /v3/{project_id}/instances/{instance_id}/full-sql/sql-trace

表1 参数说明

名称

是否必选

参数类型

说明

project_id

String

参数解释:

租户在某一Region下的项目ID。

获取方法请参见获取项目ID

约束限制:

不涉及。

取值范围:

只能由英文字母、数字组成,且长度为32个字符。

默认取值

不涉及。

instance_id

String

参数解释:

实例ID,此参数是用户创建实例的唯一标识。

约束限制:

不涉及。

取值范围:

只能由英文字母、数字组成,且长度为36个字符。

默认取值

不涉及。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

用户Token。

通过调用IAM服务获取用户Token接口获取。

请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。

约束限制:

不涉及。

取值范围

不涉及。

默认取值

不涉及。

X-Language

String

参数解释:

语言。

约束限制:

不涉及。

取值范围

  • zh-cn
  • en-us

默认取值

en-us

表3 请求Query参数

参数

是否必选

参数类型

描述

sql_id

String

参数解释:

归一化SQL ID,对应内核字段:unique_sql_id。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值

不涉及。

sql_exec_id

String

参数解释

唯一SQL ID,对应内核字段:debug_query_id。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

transaction_id

String

参数解释:

事务ID,对应内核字段:transaction_id。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值

不涉及。

trace_id

String

参数解释:

链路ID,对应内核字段:trace_id。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值

不涉及。

特别注意,结合全量SQL业务特性,实际调用时,以上四个参数请至少传值一个,请勿不作任何过滤。

响应参数

表4 响应Body参数

参数

参数类型

描述

[数组元素]

Array of NodeExecutionInfo

参数解释

SQL链路节点执行信息列表。

详情请参见表5

表5 NodeExecutionInfo

参数

参数类型

描述

component_id

String

参数解释

组件ID。

取值范围

不涉及。

node_id

String

参数解释

节点ID。

取值范围

不涉及。

transaction_id

String

参数解释

事务ID。

取值范围

不涉及。

sql_id

String

参数解释

归一化SQL ID。

取值范围

不涉及。

sql_exec_id

String

参数解释

唯一SQL ID。

取值范围

不涉及。

db_name

String

参数解释

数据库名称。

取值范围

不涉及。

schema_name

String

参数解释

schema名称。

取值范围

不涉及。

start_time

String

参数解释

语句启动的时间,格式为“yyyy-mm-ddThh:mm: ssssssZ”。其中,T指某个时间的开始;Z指时区偏移量,例如北京时间偏移显示为+0800。

取值范围

不涉及。

finish_time

String

参数解释

语句结束的时间,格式为“yyyy-mm-ddThh:mm: ssssssZ”。其中,T指某个时间的开始;Z指时区偏移量,例如北京时间偏移显示为+0800。

取值范围

不涉及。

all_time

Long

参数解释

执行总耗时(单位:微秒)。

取值范围

不涉及。

user_name

String

参数解释

用户名。

取值范围

不涉及。

client_addr

String

参数解释

用户发起的请求的客户端地址。

取值范围

不涉及。

client_port

Integer

参数解释

用户发起的请求的客户端端口。

取值范围

不涉及。

trace_id

String

参数解释

驱动传入的trace id,与应用的一次请求相关联。

取值范围

不涉及。

application_name

String

参数解释

用户发起的请求的应用程序名称。

取值范围

不涉及。

session_id

String

参数解释

用户session id。

取值范围

不涉及。

is_slow_sql

Boolean

参数解释

该SQL是否为慢SQL。

取值范围

不涉及。

execution_time_details

Object of ExecutionTimeDetail

参数解释

执行时间详细信息。

详情请参见表6

表6 ExecutionTimeDetail

参数

参数类型

描述

resource_time

Object of ResourceTime

参数解释

资源耗时信息。

详情请参见表7 ResourceTime

kernel_time

Object of KernelTime

参数解释

内核模块耗时信息。

详情请参见表9 KernelTime

kernel_execution_time

Object of KernelExecutionTime

参数解释

内核执行模块耗时信息。

详情请参见表11 KernelExecutionTime

wait_event_time

Object of WaitEventTime

参数解释

等待事件和语句锁事件耗时信息。

详情请参见表13 WaitEventTime

表7 ResourceTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

resource_time_details

Object of ResourceTimeDetail

参数解释

资源耗时详细信息。

详情请参见表8 ResourceTimeDetail

表8 ResourceTimeDetail

参数

参数类型

描述

cpu_time

Long

参数解释

CPU时间(单位:微秒)。

取值范围

不涉及。

data_io_time

Long

参数解释

IO上的时间花费(单位:微秒)。

取值范围

不涉及。

other_time

Long

参数解释

其余耗时(单位:微秒)。

取值范围

不涉及。

表9 KernelTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

kernel_time_details

Object of KernelTimeDetail

参数解释

内核耗时详细信息。

详情请参见表10 KernelTimeDetail

表10 KernelTimeDetail

参数

参数类型

描述

parse_time

Long

参数解释

SQL解析时间(单位:微秒)。

取值范围

不涉及。

rewrite_time

Long

参数解释

SQL重写时间(单位:微秒)。

取值范围

不涉及。

plan_time

Long

参数解释

SQL生成计划时间(单位:微秒)。

取值范围

不涉及。

execution_time

Long

参数解释

执行器内执行时间(单位:微秒)。

取值范围

不涉及。

other_time

Long

参数解释

其余耗时(单位:微秒)。

取值范围

不涉及。

表11 KernelExecutionTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

kernel_execution_time_details

Object of KernelExecTimeDetail

参数解释

内核执行耗时详细信息。

详情请参见表12 KernelExecTimeDetail

表12 KernelExecTimeDetail

参数

参数类型

描述

execution_time

Long

参数解释

执行器内执行时间(单位:微秒)。

取值范围

不涉及。

other_time

Long

参数解释

其余耗时(单位:微秒)。

取值范围

不涉及。

表13 WaitEventTime

参数

参数类型

描述

code_wait_event_time

Object of CodeWaitEventTime

参数解释

等待事件代码耗时。

详情请参见表14 CodeWaitEventTime

resource_wait_event_time

Object of ResourceWaitEventTime

参数解释

资源类等待事件耗时。

详情请参见表15 ResourceWaitEventTime

表14 CodeWaitEventTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

code_wait_event_time_details

Object of EventTime

参数解释

内核模块耗时信息。

详情请参见表20 EventTime

表15 ResourceWaitEventTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

resource_wait_event_time_details

Object of ResourceWaitEvenTimeDetail

参数解释

资源类等待事件耗时详细信息。

详情请参见表16 ResourceWaitEvenTimeDetail

other_time

Long

参数解释

资源类等待事件外耗时(单位:微秒)。

取值范围

不涉及。

表16 ResourceWaitEvenTimeDetail

参数

参数类型

描述

data_io_time

Object of DataIoTime

参数解释

IO耗时信息。

详情请参见表17 DataIoTime

lock_time

Object of LockTime

参数解释

加锁耗时信息。

详情请参见表18 LockTime

lwlock_time

Object of LwlockTime

参数解释

轻量级加锁耗时信息。

详情请参见表19 LwlockTime

表17 DataIoTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

data_io_time_details

Object of EventTime

参数解释

内核侧IO耗时详情。

详情请参见表20 EventTime

表18 LockTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

lock_time_details

Object of EventTime

参数解释

内核侧加锁耗时详细信息。

详情请参见表20 EventTime

表19 LwlockTime

参数

参数类型

描述

all_time

Long

参数解释

总耗时(单位:微秒)。

取值范围

不涉及。

lwlock_time_details

Object of EventTime

参数解释

内核侧轻量级锁耗时详情。

详情请参见表20 EventTime

表20 EventTime

参数

参数类型

描述

events

Array of TopTime

参数解释

TOP5事件耗时信息列表。

详情请参见表21 TopTime

left_time

Long

参数解释

其余事件耗时(单位:微秒)。

取值范围

不涉及。

other_time

Long

参数解释

事件外耗时(单位:微秒)。

取值范围

不涉及。

表21 TopTime

参数

参数类型

描述

event_name

String

参数解释

事件名。

取值范围

不涉及。

event_time

Long

参数解释

事件耗时(单位:微秒)。

取值范围

不涉及。

请求示例

查询指定单条SQL的链路信息。

GET https://gaussdb-opengauss.cn-north-1.myhuaweicloud.com/v3/4a89780fa1024361bcb855fed6aab89e/instances/cf9c879513144362bce2b3760ed81d3bin14/full-sql/sql-trace?sql_id=67570929&sql_exec_id=72620543991485094&id=f084ca811d62f93af3dff2d508a981bc

响应示例

[
    {
        "component_id": "cn_5001",
        "node_id": "b470c6297bb24c258e3eccf8dcaaa3f0no14",
        "transaction_id": "0",
        "sql_id": "67570929",
        "sql_exec_id": "72620543991485094",
        "db_name": "postgres",
        "schema_name": "\"$user\",public",
        "start_time": "2025-08-08 09:59:28 +0000",
        "finish_time": "2025-08-08 09:59:28 +0000",
        "all_time": 474,
        "user_name": "rdsAdmin",
        "client_addr": "127.0.0.1",
        "client_port": 51698,
        "trace_id": "",
        "application_name": "cm_agent",
        "session_id": "140316080338496",
        "is_slow_sql": false,
        "execution_time_details": {
            "resource_time": {
                "all_time": 474,
                "resource_time_details": {
                    "cpu_time": 417,
                    "data_io_time": 0,
                    "other_time": 57
                }
            },
            "kernel_time": {
                "all_time": 474,
                "kernel_time_details": {
                    "parse_time": 21,
                    "rewrite_time": 3,
                    "plan_time": 132,
                    "execution_time": 16,
                    "other_time": 318
                }
            },
            "kernel_execution_time": {
                "all_time": 474,
                "kernel_execution_time_details": {
                    "execution_time": 16,
                    "other_time": 458
                }
            },
            "wait_event_time": {
                "code_wait_event_time": {
                    "all_time": 474,
                    "code_wait_event_time_details": {
                        "events": [
                            {
                                "event_name": "wait seq scan",
                                "event_time": 57
                            },
                            {
                                "event_name": "flush data",
                                "event_time": 28
                            },
                            {
                                "event_name": "wait xact commit command",
                                "event_time": 21
                            },
                            {
                                "event_name": "wait xact start command",
                                "event_time": 13
                            },
                            {
                                "event_name": "wait heap hot search buffer",
                                "event_time": 9
                            }
                        ],
                        "left_time": 0,
                        "other_time": 346
                    }
                },
                "resource_wait_event_time": {
                    "all_time": 474,
                    "resource_wait_event_time_details": {
                        "data_io_time": {
                            "all_time": 0,
                            "data_io_time_details": {
                                "events": [
                                    {
                                        "event_name": "BufHashTableSearch",
                                        "event_time": 16
                                    }
                                ],
                                "left_time": 0,
                                "other_time": 0
                            }
                        },
                        "lock_time": {
                            "all_time": 0,
                            "lock_time_details": {
                                "events": [],
                                "left_time": 0,
                                "other_time": 0
                            }
                        },
                        "lwlock_time": {
                            "all_time": 0,
                            "lwlock_time_details": {
                                "events": [],
                                "left_time": 0,
                                "other_time": 0
                            }
                        }
                    },
                    "other_time": 0
                }
            }
        }
    }
]

状态码

错误码

请参见错误码

相关文档