

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# STL\_WLM\_QUERY
<a name="r_STL_WLM_QUERY"></a>

在 WLM 處理的服務類別中包含每個嘗試執行之查詢的記錄。

所有使用者都可看見 STL\_WLM\_QUERY。超級使用者可以看見所有資料列；一般使用者只能看見自己的資料。如需詳細資訊，請參閱[系統資料表和檢視中資料的可見性](cm_chap_system-tables.md#c_visibility-of-data)。

此資料表中的部份或所有資料也會在 SYS 監控檢視 [SYS\_QUERY\_HISTORY](SYS_QUERY_HISTORY.md) 中找到。SYS 監視檢視中的資料會格式化為更易於使用和理解。我們建議您使用 SYS 監控檢視進行查詢。

## 資料表欄
<a name="r_STL_WLM_QUERY-table-columns"></a>


| 欄名稱  | 資料類型  | Description  | 
| --- | --- | --- | 
| userid | integer | 產生項目的使用者之 ID。 | 
| xid  | integer  | 查詢或子查詢的交易 ID。 | 
| task  | integer  | 用於透過工作負載管理員追蹤查詢的 ID。可與多個查詢 ID 關聯。如果查詢已重新啟動，會將新的查詢 ID (而非新的任務 ID) 指派給該查詢。 | 
| query  | integer | 查詢 ID。如果查詢已重新啟動，會將新的查詢 ID (而非新的任務 ID) 指派給該查詢。 | 
| service\_class  | integer  | 服務類別的 ID。如需服務類別 ID 的清單，請參閱 [WLM 服務類別 ID](cm-c-wlm-system-tables-and-views.md#wlm-service-class-ids)。 | 
| slot\_count | integer | 根據為佇列設定的並行層級，查詢使用的 WLM 查詢槽數。預設值為 1。如需詳細資訊，請參閱 [wlm\_query\_slot\_count](https://docs.aws.amazon.com/redshift/latest/dg/r_wlm_query_slot_count.html)。 | 
| service\_class\_start\_time  | timestamp  | 查詢已指派給服務類別的時間。此時間位於 UTC 時區。 | 
| queue\_start\_time  | timestamp  | 查詢進入服務類別佇列的時間。此時間位於 UTC 時區。 | 
| queue\_end\_time  | timestamp  | 查詢離開服務類別佇列的時間。此時間位於 UTC 時區。 | 
| total\_queue\_time  | bigint  | 查詢在佇列中花費的微秒總數 | 
| exec\_start\_time  | timestamp  | 查詢開始在服務類別執行的時間。此時間位於 UTC 時區。 | 
| exec\_end\_time  | timestamp  | 查詢在服務類別完成執行的時間。此時間位於 UTC 時區。 | 
| total\_exec\_time  | bigint  | 查詢花費在執行的微秒數。 | 
| service\_class\_end\_time  | timestamp  | 查詢離開服務類別的時間。此時間位於 UTC 時區。 | 
| final\_state  | character(16)  | 保留以供系統使用。 | 
| est\_peak\_mem | bigint | 保留以供系統使用。 | 
| query\_priority | char(20) | 查詢的優先順序。可能的值為 n/a、lowest、low、normal、high 和 highest，其中 n/a 表示不支援查詢優先順序。 | 
| service\_class\_name | character(64) | 服務類別名稱。如需服務類別的相關資訊，請參閱 [WLM 系統資料表和檢視](https://docs.aws.amazon.com/redshift/latest/dg/cm-c-wlm-system-tables-and-views.html)。 | 

## 範例查詢
<a name="r_STL_WLM_QUERY-sample-queries"></a>

 **檢視佇列和執行中的平均查詢時間** 

下列查詢顯示大於 4 之服務類別的目前組態。如需服務類別 ID 的清單，請參閱 [WLM 服務類別 ID](cm-c-wlm-system-tables-and-views.md#wlm-service-class-ids)。

下列查詢會傳回每個查詢花費在查詢佇列以及執行每個服務類別的平均時間 (以微秒為單位)。

```
select service_class as svc_class, count(*),
avg(datediff(microseconds, queue_start_time, queue_end_time)) as avg_queue_time,
avg(datediff(microseconds, exec_start_time, exec_end_time )) as avg_exec_time
from stl_wlm_query
where service_class > 4
group by service_class
order by service_class;
```

此查詢傳回下列範例輸出：

```
 svc_class | count | avg_queue_time | avg_exec_time
-----------+-------+----------------+---------------
         5 | 20103 |              0 |         80415
         5 |  3421 |          34015 |        234015
         6 |    42 |              0 |        944266
         7 |   196 |           6439 |       1364399
(4 rows)
```

 **檢視佇列和執行中的查詢時間上限** 

下列查詢會傳回每個查詢花費在任何查詢佇列以及執行每個服務類別的時間量上限 (以微秒為單位)。

```
select service_class as svc_class, count(*),
max(datediff(microseconds, queue_start_time, queue_end_time)) as max_queue_time,
max(datediff(microseconds, exec_start_time, exec_end_time )) as max_exec_time
from stl_wlm_query
where svc_class > 5  
group by service_class
order by service_class;
```

```
 svc_class | count | max_queue_time | max_exec_time
-----------+-------+----------------+---------------
         6 |    42 |              0 |       3775896
         7 |   197 |          37947 |      16379473
(4 rows)
```