
# 查询SQL执行计划绑定情况 - QueryingtheBindingStatusofaSQLExecutionPlan
#### 功能介绍
查询SQL执行计划绑定情况。
- 调用接口前，您需要了解API [认证鉴权](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_011.html)。
- 调用接口前，您需要提前获取到[地区和终端节点](https://developer.huaweicloud.com/endpoint)。
 
#### 接口约束
仅支持包含有CN或DN（主、备）组件的节点。
#### 调试
您可以在[API Explorer](https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=GaussDBforopenGauss&api=ListSqlPlanAction)中调试该接口。
#### URI
POST /v3/{project_id}/instances/{instance_id}/sql/{node_id}/plans/query
表1路径参数 
| 参数          | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| project_id  | 是    | String | **参数解释：** 租户在某一Region下的项目ID。 获取方法请参见[获取项目ID](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_196.html)。 **约束限制：** 不涉及。 **取值范围：** 只能由英文字母、数字组成，且长度为32个字符。 **默认取值**： 不涉及。                                                                                                                                                                                                                                                                                                                               |
| instance_id | 是    | String | **参数解释：** 实例ID，此参数是用户创建实例的唯一标识。请参考[查询数据库实例列表 - QueryingDBInstances](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_328.html)接口获取实例ID。 **约束限制：** 不涉及。 **取值范围：** 只能由英文字母、数字组成，且长度为36个字符。 **默认取值** **：** 不涉及。 |
| node_id     | 是    | String | **参数解释：** 节点ID，仅支持非日志类型的CN或主DN、备DN节点。 获取方式请参考[查询实例的组件列表 - QueryingtheComponentsofaDBInstance](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_028.html)。 **约束限制：** 不涉及。 **取值范围：** 只能由英文字母、数字组成，且长度为36个字符。 **默认取值** **：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | **参数解释：** 用户Token。 通过调用IAM服务[获取用户Token](https://support.huaweicloud.com/api-iam/iam_30_0001.html)接口获取。 请求响应成功后在响应消息头中包含的"X-Subject-Token"的值即为Token值。 **约束限制：** 不涉及。 **取值范围：** 不涉及。 **默认取值** **：** 不涉及。 |
| X-Language   | 否    | String | **参数解释：** 指定接口返回信息的语言类型。 **约束限制：** 不涉及。 **取值范围：** - **zh-cn**：中文  - **en-us**：英文   **默认取值** **：** **en-us**                     |
   
表3请求Body参数 
| 参数        | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|:---|
| sql_id    | 是    | String | **参数解释：** 归一化的SQL ID，获取方法请参见[查询慢SQL列表 - QueryingSlowSQLStatements](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_297.html)。 **约束限制：** 不涉及。 **取值范围：** 不涉及。 **默认取值** **：** 不涉及。 |
| page_size | 是    | String | **参数解释：** SQL执行计划每页显示数量。 **约束限制：** 不涉及。 **取值范围：** 整数，1\~100。 **默认取值** **：** 不涉及。             |
| offset    | 是    | String | **参数解释：** SQL执行计划起始页码。 **约束限制：** 不涉及。 **取值范围：** 大于等于0的整数。 **默认取值** **：** 0               |
   
#### 响应参数
表4响应Body参数 
| 参数                       | 参数类型             | 描述                                                                                                                                                                                                                                                                     |
|:---|:---|:---|
| total                    | Integer          | **参数解释：** SQL执行计划总数。 **取值范围：** 不涉及。 |
| sql_plan_bind_state_list | Array of objects | **参数解释：** 执行计划列表，详情请参见[表5]。                                                                               |
   
 表5sql_plan_bind_state_list 
| 参数       | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|
| outline  | String | **参数解释：** 当前计划的概览。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                      |
| cost     | String | **参数解释：** SQL执行计划的开销。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                              |
| status   | String | **参数解释：** 绑定状态。 **取值范围：** - bind：绑定。  - drop：解绑。   |
| sql_hash | String | **参数解释：** SQL文本的哈希值。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                 |
| plan_id  | String | **参数解释：** SQL执行计划ID。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                    |
   
#### 请求示例
查询SQL执行计划绑定情况。
```
POST https://gaussdb-opengauss.cn-north-1.myhuaweicloud.com/v3/4a89780fa1024361bcb855fed6aab89e/instances/99220a1a5b714977b61be98185636732in14/sql/60856bc060f1476b81af52a17e0e5fc7no14/plans/query
{ 
  "offset" : "0", 
  "page_size" : "10", 
  "sql_id" : "418132115" 
}
```
#### 响应示例
查询SQL执行计划成功。
```
{ 
  "total" : 1, 
  "sql_plan_bind_state_list" : [ { 
    "outline" : "begin_outline_data\n use_hash_agg(@\"sel$1\")\n NestLoop(@\"sel$1\" root.store_sales@\"sel$1\" root.store_returns@\"sel$1\" root.store@\"sel$1\" root.customer@\"sel$1\" root.promotion@\"sel$1\" root.ad2@\"sel$1\" root.item@\"sel$1\")\n Leading(@\"sel$1\" ((((((root.store_sales@\"sel$1\" root.store_returns@\"sel$1\") root.store@\"sel$1\") root.customer@\"sel$1\") root.promotion@\"sel$1\") root.ad2@\"sel$1\") root.item@\"sel$1\"))\n NestLoop(@\"sel$1\" root.store_sales@\"sel$1\" root.store_returns@\"sel$1\" root.store@\"sel$1\" root.customer@\"sel$1\" root.promotion@\"sel$1\" root.ad2@\"sel$1\")\n Leading(@\"sel$1\" (((((root.store_sales@\"sel$1\" root.store_returns@\"sel$1\") root.store@\"sel$1\") root.customer@\"sel$1\") root.promotion@\"sel$1\") root.ad2@\"sel$1\"))\n NestLoop(@\"sel$1\" root.store_sales@\"sel$1\" root.store_returns@\"sel$1\" root.store@\"sel$1\" root.customer@\"sel$1\" root.promotion@\"sel$1\")\n Leading(@\"sel$1\" ((((root.store_sales@\"sel$1\" root.store_returns@\"sel$1\") root.store@\"sel$1\") root.customer@\"sel$1\") root.promotion@\"sel$1\"))\n NestLoop(@\"sel$1\" root.store_sales@\"sel$1\" root.store_returns@\"sel$1\" root.store@\"sel$1\" root.customer@\"sel$1\")\n Leading(@\"sel$1\" (((root.store_sales@\"sel$1\" root.store_returns@\"sel$1\") root.store@\"sel$1\") root.customer@\"sel$1\"))\n NestLoop(@\"sel$1\" root.store_sales@\"sel$1\" root.store_returns@\"sel$1\" root.store@\"sel$1\")\n Leading(@\"sel$1\" ((root.store_sales@\"sel$1\" root.store_returns@\"sel$1\") root.store@\"sel$1\"))\n HashJoin(@\"sel$1\" root.store_sales@\"sel$1\" root.store_returns@\"sel$1\")\n Leading(@\"sel$1\" (root.store_sales@\"sel$1\" root.store_returns@\"sel$1\"))\n TableScan(@\"sel$1\" root.store_sales@\"sel$1\")\n IndexOnlyScan(@\"sel$1\" root.store_returns@\"sel$1\" store_returns_pkey)\n IndexScan(@\"sel$1\" root.store@\"sel$1\" store_pkey)\n NestLoop_Index(@\"sel$1\" root.store@\"sel$1\", (root.store_sales@\"sel$1\"))\n IndexScan(@\"sel$1\" root.customer@\"sel$1\" customer_pkey)\n NestLoop_Index(@\"sel$1\" root.customer@\"sel$1\", (root.store_sales@\"sel$1\"))\n IndexOnlyScan(@\"sel$1\" root.promotion@\"sel$1\" promotion_pkey)\n NestLoop_Index(@\"sel$1\" root.promotion@\"sel$1\", (root.store_sales@\"sel$1\"))\n IndexScan(@\"sel$1\" root.ad2@\"sel$1\" customer_address_pkey)\n NestLoop_Index(@\"sel$1\" root.ad2@\"sel$1\", (root.customer@\"sel$1\"))\n IndexScan(@\"sel$1\" root.item@\"sel$1\" item_pkey)\n NestLoop_Index(@\"sel$1\" root.item@\"sel$1\", (root.store_sales@\"sel$1\"))\n version(\"1.0.0\")\n end_outline_data", 
    "cost" : "84178.87", 
    "status" : "bind", 
    "sql_hash" : "400834521", 
    "plan_id" : "378071839" 
  } ] 
}
```
#### 状态码
- 正常 200
  
- 异常 请参见[状态码](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_194.html)。
  
 
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-gaussdb/gaussdb_api_195.html)。
