

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息，请参阅[博客文章](https://www.amazonaws.cn/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

# SYS\_EXTERNAL\_QUERY\_DETAIL
<a name="SYS_EXTERNAL_QUERY_DETAIL"></a>

使用 SYS\_EXTERNAL\_QUERY\_DETAIL 查看段级别查询的详细信息。每行代表来自特定 WLM 查询的一段，其中包含 Amazon S3 中处理的行数、处理的字节数以及外部表的分区信息等详细信息。此视图除了具有与外部查询处理相关的更多详细信息之外，每一行还将在 SYS\_QUERY\_DETAIL 视图中有一个相应条目。

SYS\_EXTERNAL\_QUERY\_DETAIL 对所有用户可见。超级用户可以查看所有行；普通用户只能查看其自己的数据。有关更多信息，请参阅 [系统表和视图中的数据可见性](cm_chap_system-tables.md#c_visibility-of-data)。

## 表列
<a name="SYS_EXTERNAL_QUERY_DETAIL-table-columns"></a>


| 列名称  | 数据类型  | 描述  | 
| --- | --- | --- | 
| user\_id | integer | 提交查询的用户标识符。 | 
| query\_id | bigint | 外部查询的查询标识符。 | 
| transaction\_id | bigint | 事务标识符。 | 
| child\_query\_sequence | integer | 重写的用户查询的顺序。从 0 开始，类似于 segment\_id。 | 
| segment\_id | integer | 查询分段的分段标识符。 | 
| source\_type | character(32) | 查询的数据源类型，可能是针对 Redshift Spectrum 的 S3、针对联合查询的 PG。 | 
| start\_time | timestamp | 查询开始的时间。 | 
| end\_time | timestamp | 查询完成的时间。 | 
| duration | bigint | 在查询上花费的时间（微秒）。 | 
| total\_partitions | integer | Amazon S3 查询所需的分区数。 | 
| qualified\_partitions | integer | Amazon S3 查询扫描的分区数。 | 
| scanned\_file | bigint | 扫描的 Amazon S3 文件数。 | 
| returned\_rows | bigint | Amazon S3 查询的扫描行数，或联合查询返回的行数。 | 
| returned\_bytes | bigint | Amazon S3 查询的扫描字节数或联合查询返回的字节数。 | 
| file\_format | 文本 | Amazon S3 文件的文件格式。 | 
| file\_location | 文本 | 外部表的 Amazon S3 位置。 | 
| external\_query\_text | 文本 | 联合查询的段级查询文本。 | 
| warning\_message | character(4000) | 查询运行的时候显示的警告消息。 | 
| table\_name | character(136) | 正在操作的步骤的表名。 | 
| is\_recursive | character(1) | 表示是否对子文件夹进行递归扫描。 | 
| is\_nested | character(1) | 表示是否访问嵌套列数据类型。 | 
| s3list\_time | bigint | 文件列出的持续时间（以毫秒为单位）。 | 
| get\_partition\_time | 长整数 | 从 Amazon Glue Data Catalog 和 Apache Hive 中为给定的外部对象列出和限定分区所花费的时间。 | 

## 示例查询
<a name="SYS_EXTERNAL_QUERY_DETAIL-sample-queries"></a>

以下查询显示了外部查询详细信息。

```
SELECT query_id,
       segment_id,
       start_time,
       end_time,
       total_partitions,
       qualified_partitions,
       scanned_files,
       returned_rows,
       returned_bytes,
       trim(external_query_text) query_text,
       trim(file_location) file_location
FROM sys_external_query_detail
ORDER BY query_id, start_time DESC
LIMIT 2;
```

示例输出。

```
 query_id | segment_id |         start_time         |          end_time          | total_partitions | qualified_partitions | scanned_files | returned_rows | returned_bytes | query_text | file_location
----------+------------+----------------------------+----------------------------+------------------+----------------------+---------------+---------------+----------------+------------+---------------
   763251 |          0 | 2022-02-15 22:32:23.312448 | 2022-02-15 22:32:24.036023 |                3 |                    3 |             3 |         38203 |        2683414 |            |
   763254 |          0 | 2022-02-15 22:32:40.17103  | 2022-02-15 22:32:40.839313 |                3 |                    3 |             3 |         38203 |        2683414 |            |
```