本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
STL_EXPLAIN
顯示已提交供執行之用的查詢的 EXPLAIN 計劃。
所有使用者都可看見 STL_EXPLAIN。超級使用者可以看見所有資料列;一般使用者只能看見自己的資料。如需詳細資訊,請參閱系統資料表和檢視中資料的可見性。
注意
STL_EXPLAIN 僅包含在主要佈建叢集上執行的查詢。它不包含在並行擴展叢集或無伺服器命名空間上執行的查詢。若要存取在主要叢集、並行擴展叢集和無伺服器命名空間上執行的查詢說明計劃,建議您使用 SYS 監控檢視 SYS_QUERY_EXPLAIN 。SYS 監視檢視中的資料會格式化為更易於使用和理解。
資料表欄
欄名稱 | 資料類型 | 描述 |
---|---|---|
userid | integer | 產生項目的使用者之 ID。 |
query | integer | 查詢 ID。查詢欄可用於加入其他系統表格與檢視。 |
nodeid | integer | 計劃節點識別碼,其中節點會在查詢執行時映射至一個或多個步驟。 |
parentid | integer | 父節點的計劃節點識別碼。父節點具有一些子節點。例如,合併聯結是已聯結資料表上掃描的父項。 |
plannode | character(400) | 來自 EXPLAIN 輸出的節點文字。在 EXPLAIN 輸出中,提及在運算節點上執行的計劃節點是以 XN 為字首。 |
info | character(400) | 計劃節點的限定詞和篩選條件資訊。例如,此資料欄中包括聯結條件和 WHERE 子句限制。 |
範例查詢
考慮彙總聯結查詢的下列 EXPLAIN 輸出:
explain select avg(datediff(day, listtime, saletime)) as avgwait from sales, listing where sales.listid = listing.listid; QUERY PLAN ------------------------------------------------------------------------------ XN Aggregate (cost=6350.30..6350.31 rows=1 width=16) -> XN Hash Join DS_DIST_NONE (cost=47.08..6340.89 rows=3766 width=16) Hash Cond: ("outer".listid = "inner".listid) -> XN Seq Scan on listing (cost=0.00..1924.97 rows=192497 width=12) -> XN Hash (cost=37.66..37.66 rows=3766 width=12) -> XN Seq Scan on sales (cost=0.00..37.66 rows=3766 width=12) (6 rows)
如果執行此查詢且其查詢 ID 為 10,則您可以使用 STL_EXPLAIN 資料表,來查看 EXPLAIN 命令所傳回相同類型的資訊:
select query,nodeid,parentid,substring(plannode from 1 for 30), substring(info from 1 for 20) from stl_explain where query=10 order by 1,2; query| nodeid |parentid| substring | substring -----+--------+--------+--------------------------------+------------------- 10 | 1 | 0 |XN Aggregate (cost=6717.61..6 | 10 | 2 | 1 | -> XN Merge Join DS_DIST_NO | Merge Cond:("outer" 10 | 3 | 2 | -> XN Seq Scan on lis | 10 | 4 | 2 | -> XN Seq Scan on sal | (4 rows)
請考處下列查詢:
select event.eventid, sum(pricepaid) from event, sales where event.eventid=sales.eventid group by event.eventid order by 2 desc; eventid | sum --------+---------- 289 | 51846.00 7895 | 51049.00 1602 | 50301.00 851 | 49956.00 7315 | 49823.00 ...
如果此查詢的 ID 為 15,則下列系統檢視查詢會傳回已完成的計劃節點。在此情況下,會保留節點的順序,以顯示執行的實際順序:
select query,nodeid,parentid,substring(plannode from 1 for 56) from stl_explain where query=15 order by 1, 2 desc; query|nodeid|parentid| substring -----+------+--------+-------------------------------------------------------- 15 | 8 | 7 | -> XN Seq Scan on eve 15 | 7 | 5 | -> XN Hash(cost=87.98..87.9 15 | 6 | 5 | -> XN Seq Scan on sales(cos 15 | 5 | 4 | -> XN Hash Join DS_DIST_OUTER(cos 15 | 4 | 3 | -> XN HashAggregate(cost=862286577.07.. 15 | 3 | 2 | -> XN Sort(cost=1000862287175.47..10008622871 15 | 2 | 1 | -> XN Network(cost=1000862287175.47..1000862287197. 15 | 1 | 0 |XN Merge(cost=1000862287175.47..1000862287197.46 rows=87 (8 rows)
下列查詢會擷取包含視窗函數之任何查詢計劃的查詢 ID:
select query, trim(plannode) from stl_explain where plannode like '%Window%'; query| btrim -----+------------------------------------------------------------------------ 26 | -> XN Window(cost=1000985348268.57..1000985351256.98 rows=170 width=33) 27 | -> XN Window(cost=1000985348268.57..1000985351256.98 rows=170 width=33) (2 rows)