

 从补丁 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/)。

# STL\_LIMIT
<a name="r_STL_LIMIT"></a>

分析在 SELECT 查询中使用 LIMIT 子句时发生的执行步骤。

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

**注意**  
STL\_LIMIT 仅包含在主预置集群上运行的查询。它不包含在并发扩展集群或无服务器命名空间上运行的查询。要访问在主集群、并发扩展集群和无服务器命名空间上运行的查询的解释计划，我们建议您使用 SYS 监控视图 [SYS\_QUERY\_DETAIL](SYS_QUERY_DETAIL.md)。SYS 监控视图中的数据经过格式化处理，便于使用和理解。

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


| 列名称  | 数据类型  | 描述  | 
| --- | --- | --- | 
| userid | integer | 生成该条目的用户 ID。 | 
| query | integer | 查询 ID。查询列可用于连接其他系统表和视图。 | 
| slice | integer | 标识运行查询所在切片的标识符。 | 
| segment | integer | 标识查询区段的数字。 | 
| step | integer | 运行的查询步骤。 | 
| starttime | timestamp | 查询开始的时间（采用 UTC 表示）。总时间包括排队和执行时间。秒的小数部分以 6 位精度表示。例如：2009-06-12 11:29:19.131358。 | 
| endtime | timestamp | 查询完成的时间（采用 UTC 表示）。总时间包括排队和执行时间。秒的小数部分以 6 位精度表示。例如：2009-06-12 11:29:19.131358。 | 
| tasknum | 整数 | 分配用于运行步骤的查询任务进程的数量。 | 
| rows | bigint | 处理的总行数。 | 
| checksum | bigint | 此信息仅供内部使用。 | 

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

为了在 STL\_LIMIT 中生成行，此示例首先使用 LIMIT 子句对 VENUE 表运行了以下查询。

```
select * from venue
order by 1
limit 10;
```

```
 venueid |         venuename          |    venuecity    | venuestate | venueseats
---------+----------------------------+-----------------+------------+------------
       1 | Toyota Park                | Bridgeview      | IL         |          0
       2 | Columbus Crew Stadium      | Columbus        | OH         |          0
       3 | RFK Stadium                | Washington      | DC         |          0
       4 | CommunityAmerica Ballpark  | Kansas City     | KS         |          0
       5 | Gillette Stadium           | Foxborough      | MA         |      68756
       6 | New York Giants Stadium    | East Rutherford | NJ         |      80242
       7 | BMO Field                  | Toronto         | ON         |          0
       8 | The Home Depot Center      | Carson          | CA         |          0
       9 | Dick's Sporting Goods Park | Commerce City   | CO         |          0
      10 | Pizza Hut Park             | Frisco          | TX         |          0
(10 rows)
```

然后，运行以下查询来查找您已对 VENUE 表运行的最后一个查询的查询 ID。

```
select max(query)
from stl_query;
```

```
  max
--------
 127128
(1 row)
```

或者，您可以运行以下查询来验证查询 ID 是否对应于之前运行的 LIMIT 查询。

```
select query, trim(querytxt)
from stl_query
where query=127128;
```

```
 query  |                  btrim
--------+------------------------------------------
 127128 | select * from venue order by 1 limit 10;
(1 row)
```

最后，运行以下查询来返回有关 STL\_LIMIT 表中的 LIMIT 查询的信息。

```
select slice, segment, step, starttime, endtime, tasknum
from stl_limit
where query=127128
order by starttime, endtime;
```

```
  slice | segment | step |         starttime          |          endtime           | tasknum
 -------+---------+------+----------------------------+----------------------------+---------
      1 |       1 |    3 | 2013-09-06 22:56:43.608114 | 2013-09-06 22:56:43.609383 |      15
      0 |       1 |    3 | 2013-09-06 22:56:43.608708 | 2013-09-06 22:56:43.609521 |      15
  10000 |       2 |    2 | 2013-09-06 22:56:43.612506 | 2013-09-06 22:56:43.612668 |       0
(3 rows)
```