有效使用 Optim Query Tuner 工具进行 SQL 查询语句的优化
2009-12-07 00:00:00 来源:WEB开发网
图 5. Statistics Advisor 推荐结果
查看原图(大图)
图 6. Statistics Advisor 推荐 RUNSTATS 结果
查看原图(大图)
此后,在新的环境下重新调优 SQL,OQT 给出了较高优先级的 Query Advisor 的建议,如图 7 所示。
图 7. Query Advisor 结果
其分析结果显示,SYSIBM.SYSPACKSTMT 和 SYSIBM.SYSPACKAGE 表在列 LOCATION 和 CONTOKEN 上存在外键关系,可考虑加入一些 join 连接谓词来增加查询的过滤性,避免代价较大的笛卡儿连接。即隐含的提示为: 添加连接谓词 T1.LOCATION = T2.LOCATION AND T1.CONTOKEN = T2.CONTOKEN 后,查询仍是等价的。于是,重写查询语句为如下形式:
SELECT HEX(SUBSTR(T1.STMT, 48, 1)) AS HEXMRIC,
CAST(SUBSTR(T1.STMT, 48, 1) AS CHAR(1) CCSID EBCDIC FOR SBCS DATA) AS DBRMMRIC,
HEX (SUBSTR(T1.STMT, 47, 1)) AS HEXPDRM,
CAST(SUBSTR(T1.STMT, 47, 1) AS CHAR (1) CCSID EBCDIC FOR SBCS DATA) AS DBRMPDRM
FROM SYSIBM.SYSPACKSTMT T1, SYSIBM.SYSPACKAGE T2
WHERE T1.COLLID = :H :H AND
T1.NAME = :H :H AND
T1.VERSION = :H :H AND
T1.COLLID = T2.COLLID AND
T1. LOCATION = T2. LOCATION AND
T1. CONTOKEN = T2. CONTOKEN AND
T1.NAME = T2.NAME AND
T1.VERSION = T2.VERSION AND
T2.TYPE = ' ' AND
T1.SECTNO = 0 AND
T1.SEQNO = 0 AND
T1.STMTNO = 0
更多精彩
赞助商链接