Teradata SQL調優
1.最佳化過程:依照執行時間,資料量和複雜度來定位瓶頸。檢視sql執行計劃,判斷其合理性。
效能監控 ==》目標選取 ==》效能分析 ==》過程最佳化 ==》執行跟蹤(效能監控)
注意:每個過程中都會產生必須的文件
[@more@]2.效能分析:• Review PDM
--表定義 --PI的選擇 --表的記錄數與空間佔用
• Review SQL
--關聯的表 --邏輯處理複雜度 --整體邏輯 --多餘的處理
• 測試執行
--響應時間
• 檢視EXPLAIN
--瓶頸定位
3.過程最佳化:
• 業務規則理解
--合理選取資料訪問路徑
• PDM設計
--調整PDM
• SQL寫法不最佳化,忽略了Teradata的機理與特性
--調整SQL
• Teradata最佳化器未得到足夠的統計資訊
--Collect Statistics
4.Multiple Insert/select --> Multi-Statement Insert/Select
* 並行插入空表不記錄Transient Journal
* 充分利用Teradata向空表Insert較快以及並行操作的特性如:
• 現狀 INSERT INTO ${TARGETDB}.DES (Party_Id ,Party_Name ... )
SELECT … FROM SRC1 ;
INSERT INTO ${TARGETDB}.DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC2 ;
INSERT INTO ${TARGETDB}.DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC3 ;
說明:序列執行,多個Transaction
• 最佳化後: INSERT INTO ${TARGETDB}.DES (Party_Id ,Party_Name ... )
SELECT … FROM SRC1
;INSERT INTO ${TARGETDB}.DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC2
;INSERT INTO ${TARGETDB}.DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC3 ;
說明:並行執行,單個Transaction
5.Insert/Select with Union/Union all --> Multi-Statement Insert/Select
* Union 需要排除重複記錄,Union all雖不需要排重,但都需要佔用大量的Spool空間,都需要進行重新組織資料
如:現狀:
INSERT INTO ${TARGETDB}.DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC1 ;
UNION ALL SELECT … FROM SRC2 ;
UNION ALL SELECT … FROM SRC3 ;
…
調整後:
INSERT INTO ${TARGETDB}.DES (Party_Id ,Party_Name ... )
SELECT … FROM SRC1
;INSERT INTO ${TARGETDB}.T01_DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC2
;INSERT INTO ${TARGETDB}.T01_DES
(Party_Id ,Party_Name ... )
SELECT … FROM SRC3 ;
6.排除重複記錄
* 針對單表內的重複記錄使用ROW_ NUMBER函式排重
* 排重方式多了一層子查詢
* 增加了大量的資料重新分佈的時間
現狀:
……
INSERT INTO ${TARGETDB}.T01_INDIV (Party_Id ,Party_Name ... )
SELECT COALESCE(b1.Party_Id,'-1') ,
COALESCE(TRIM(b1.Party_name),'') ...
FROM
( select party_id party_name, … ,
ROW_NUMBER() OVER
(PARTITION BY Party_Id ORDER BY Party_Name )
as rownum from ${TEMPDB}.T01_INDIV b1 … ) AA
where AA.rownum = 1 ……
建議做法:
INSERT INTO ${TEMPDB}.T01_INDIV …
INSERT INTO ${TEMPDB}.T01_INDIV …
……
INSERT INTO ${TARGETDB}.T01_INDIV (Party_Id ,Party_Name ... )
SELECT party_id party_name, …
From ${TEMPDB}.T01_INDIV b1
Qualify ROW_NUMBER() OVER
(PARTITION BY Party_Id ORDER BY Party_Name ) = 1
• 運用Qualify + ROW_ NUMBER函式
• SQL語句簡潔明瞭
• 避免子查詢
最佳化前explain:
……
4) We do an all-AMPs STAT FUNCTION step from PTEMP.VT_T01_INDIV_cur by way of an all-rows scan with no residual conditions into Spool 5 (Last Use), which is assumed to be redistributed by value to all AMPs. The result rows are put into Spool 3 (all_amps), which is built locally on the AMPs.
5) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of an all-rows scan into Spool 1 (all_amps), which is built locally on the AMPs. The result spool file will not be cached in memory. The size of Spool 1 is estimated with no confidence to be 6,781,130 rows. The estimated time for this step is 16.01 seconds.
6) We do an all-AMPs RETRIEVE step from Spool 1 (Last Use) by way of an all-rows scan with a condition of ("ROWNUMBER = 1") into Spool 8 (all_amps), which is redistributed by hash code to all AMPs. Then we do a SORT to order Spool 8 by row hash. The result spool file will not be cached in memory. The size of Spool 8 is estimated with no confidence to be 6,781,130 rows. The estimated time for this step is 1 minute.
7) We do an all-AMPs MERGE into PDATA.T01_INDIV from Spool 8 (Last Use).
最佳化後explain:
……
4) We do an all-AMPs STAT FUNCTION step from PTEMP.VT_T01_INDIV_cur by way of an all-rows scan with no residual conditions into Spool 5 (Last Use), which is assumed to be redistributed by value to all AMPs. The result rows are put into Spool 3 (all_amps), which is built locally on the AMPs.
5) We do an all-AMPs RETRIEVE step from Spool 3 (Last Use) by way of an all-rows scan with a condition of ("Field_10 = 1") into Spool 1 (all_amps), which is redistributed by hash code to all AMPs. Then we do a SORT to order Spool 1 by row hash. The result spool file will not be cached in memory. The size of Spool 1 is estimated with no confidence to be 6,781,130 rows. The estimated time for this step is 1 minute.
6) We do an all-AMPs MERGE into PDATA.T01_INDIV from Spool 1 (Last Use).
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16723161/viewspace-1013482/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL調優SQL
- sql調優1SQL
- oracle sql調優OracleSQL
- MySQL調優篇 | SQL調優實戰(5)MySql
- MySQL索引和SQL調優MySql索引
- SQL調優真實案例SQL
- SQL效能調優綜述SQL
- [精華zt] SQL調優整理SQL
- SQL Server一次SQL調優案例SQLServer
- Teradata:2024年高管AI調查AI
- SQL 調優一般思路SQL
- 【sql調優】動態取樣SQL
- 一條大sql的調優SQL
- 效能調優——SQL最佳化SQL
- Oracle SQL調優系列之SQL Monitor ReportOracleSQL
- MySQL 索引和 SQL 調優總結MySql索引
- Oracle SQL調優之分割槽表OracleSQL
- SQL調優13連問,收藏好!SQL
- delete相關的pl/sql調優deleteSQL
- 使用hint來調優sql語句SQL
- SQL Server效能調優札記 [zt]SQLServer
- 【sql調優】系統資訊統計SQL
- 我如何調優SQL Server查詢SQLServer
- SQL調優公式T=S/V (zt)SQL公式
- 記一次SQL Server刪除SQL調優SQLServer
- Sql最佳化(十九) 調優工具(2)sql_traceSQL
- 使用SQL調整顧問得到SQL優化建議SQL優化
- oracle筆記整理13——效能調優之SQL優化Oracle筆記SQL優化
- 記一次SQL調優過程SQL
- 大廠都是怎麼SQL調優的?SQL
- mysql調優從書寫sql開始MySql
- 生產系統pl/sql調優案例SQL
- 【SQL 調優】繫結變數窺測SQL變數
- 通過ADDM進行SQL調優SQL
- 透過ADDM進行SQL調優SQL
- 【sql調優】繫結變數與CBOSQL變數
- 【sql調優】使用繫結變數(二)SQL變數
- 【sql調優】使用繫結變數(一)SQL變數