在oracle数据库中可以在sqlplus中打开trace选项后查看sql的执行计划,在DB2数据库中同样也有类似的功能,DB2提供了一个比较简单的工具db2expln工具来查看SQL的执行计划

可以通过输入db2expln来查看其帮助信息。

C:/Documents and Settings/liufeng>db2explnDB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2008
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain ToolA database name must be specified.SQL and XQUERY Explain Tool describes the access plan selection for static SQL s
tatements
in the packages stored in the DB2 Universal Database system catalogs.
Given a database name, package name, package creator, and section number,
SQL and XQUERY Explain Tool will interpret and describe the information in thesecatalogs.The syntax is:.-----------.V           |>>--db2expln----<option>--+--><where <option> and <parameter> are taken from the list below. Each <option>
may appear only once, and they may be specified in any order.Connection Options:-database      = Connect to the database named .-d -user    = Connect as user  with password .-u  A database name must be specified.Output Options:-terminal          = Send output to the terminal.-t-output <file>     = Write output to the file named <file>.-o <file>Either terminal or file output must be specified.Help Options:-help              = Display this help text.-h-?Package Options:-schema        = The package creator must match .-c -package       = The package name must match .-p -version       = The package version must match . If notspecified, then the package with the version ''(the empty string) will be explained.-section        = The section number is . Use 0 (zero) for-s                all sections in the package.-escape       = Use <character> as the escape character when-e <character>            matching patterns.-noupper                = Do not upper case creator, package and version-l                        before matching.The creator and package information must be specified unless dynamic SQL isbeing explained. If the section information is not specified, then allsections will be displayed.The  for creator, package, and version is in LIKE predicate form,which allows the percent sign (%%) and underscore (_) as pattern matchingcharacters. This allows multiple packages to be explained with oneinvocation of db2expln. The escape character can be used to force the %%and _ characters to be treated literally. (See the SQL Reference for moreinformation on the LIKE predicate.) If multiple packages may be matched,the section number is automatically set to 0 (all sections).Dynamic Statement Options:-statement <statement>  = The dynamic statement <statement> will be-q <sql>                  explained.-stmtfile <file>        = The dynamic statements contained in the file-f <file>                 <file> will be explained. <File> must exist atthe client.-cache ,,,= Retrieve the statement identified by the given IDsfrom the dynamic SQL cache. (The IDs can beobtained by running db2pd with the -dynamicoption.-noenv                  = By default, each statement that affects the compileenvironment will be invoked after it has beenexplained. This option prevents the execution ofthese statements.Explain Options:-setup <file>           = The SQL statements in <file> will be invokedbefore any sections or statements are explained.The SQL statements in <file> will not beexplained. Errors in the setup script are reportedbut ignored.-terminator <character> = Each SQL statement for -setup, -statement, and-z <character>            -stmtfile ends at <character>. If this option isnot specified, then each statement is assumed tobe one line long-graph                  = Reconstruct the original optimizer plan graph (as-g                        presented by Visual Explain). Note that thereconstructed graph may not exactly match theoriginal plan.-opids                  = Show the operator ID numbers.-i-nostats                = Do not show compiler statistics in the graph.Event Monitor Options:-actevm           = The name of the activities event monitor whoseactivitystmt logical grouping contains the sectionenvironments to be explained.-actevm must be specified if -appid, -uowid,-actid or -actid2 are to be specified.-appid         = The application identifier uniquely identifyingthe application that issued the activities whosesection environments are to be explained.-uowid          = The unit of work ID whose section environments areto be explained. The unit of work ID is uniqueonly within a given application.-actid          = The activity ID whose section environments are tobe explained. The activity ID is only uniquewithin a given unit of work.-actid2         = The activity secondary ID whose sectionenvironments are to be explained. This defaultsto zero if not specified.The specific options available may vary by database server.
Use "db2expln -help -database " to get the options available for
a specific server.从以上信息中可以看出该工具可以查看package以及sql的执行计划
以下是某个sql的执行计划的例子:
C:/Documents and Settings/liufeng>db2expln -d mydb -u sde esrichina -statement "
select db2gse.st_astext(shape) from sde.streets where objectid_1>10 and objectid
_1<100" -terminal -gDB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2008
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain ToolDB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2008
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool******************** DYNAMIC ***************************************==================== STATEMENT ==========================================Isolation Level          = Cursor StabilityBlocking                 = Block Unambiguous CursorsQuery Optimization Class = 5Partition Parallel       = NoIntra-Partition Parallel = NoSQL Path                 = "SYSIBM", "SYSFUN", "SYSPROC", "SYSIBMADM","SDE"Statement:select db2gse.st_astext(shape)from sde.streetswhere objectid_1>10 and objectid_1<100Section Code Page = 1208Estimated Cost = 259.877533
Estimated Cardinality = 88.970406Access Table Name = SDE.STREETS  ID = 2,280
|  Index Scan:  Name = SDE.R11_RK1  ID = 2
|  |  Regular Index (Not Clustered)
|  |  Index Columns:
|  |  |  1: OBJECTID_1 (Ascending)
|  #Columns = 0
|  Compressed Table
|  Skip Inserted Rows
|  Avoid Locking Committed Data
|  Currently Committed for Cursor Stability
|  #Key Columns = 1
|  |  Start Key: Exclusive Value
|  |  |  |  1: 10
|  |  Stop Key: Exclusive Value
|  |  |  |  1: 100
|  Index-Only Access
|  Index Prefetch: None
|  Isolation Level: Uncommitted Read
|  Lock Intents
|  |  Table: Intent None
|  |  Row  : None
|  Sargable Index Predicate(s)
|  |  Insert Into Sorted Temp Table  ID = t1
|  |  |  #Columns = 1
|  |  |  #Sort Key Columns = 1
|  |  |  |  Key 1: (Ascending)
|  |  |  Sortheap Allocation Parameters:
|  |  |  |  #Rows     = 89.000000
|  |  |  |  Row Width = 20
|  |  |  Piped
|  |  |  Duplicate Elimination
Sorted Temp Table Completion  ID = t1
List Prefetch Preparation
|  Access Table Name = SDE.STREETS  ID = 2,280
|  |  #Columns = 1
|  |  Compressed Table
|  |  Skip Inserted Rows
|  |  Avoid Locking Committed Data
|  |  Currently Committed for Cursor Stability
|  |  RID List Fetch Scan
|  |  Fetch Using Prefetched List
|  |  |  Prefetch: 6 Pages
|  |  Lock Intents
|  |  |  Table: Intent Share
|  |  |  Row  : Next Key Share
|  |  Sargable Predicate(s)
|  |  |  #Predicates = 2
Nested Loop Join
|  Piped Inner
|  Access Table Name = DB2GSE.GSE_SPATIAL_REFERENCE_SYSTEMS  ID = 4,5
|  |  Index Scan:  Name = DB2GSE.GSE_SRS_ID  ID = 2
|  |  |  Regular Index (Not Clustered)
|  |  |  Index Columns:
|  |  |  |  1: SRS_ID (Ascending)
|  |  #Columns = 8
|  |  Skip Inserted Rows
|  |  Avoid Locking Committed Data
|  |  Currently Committed for Cursor Stability
|  |  Evaluate Predicates Before Locking for Key
|  |  #Key Columns = 1
|  |  |  Start Key: Inclusive Value
|  |  |  |  |  1: ?
|  |  |  Stop Key: Inclusive Value
|  |  |  |  |  1: ?
|  |  Data Prefetch: None
|  |  Index Prefetch: None
|  |  Lock Intents
|  |  |  Table: Intent Share
|  |  |  Row  : Next Key Share
Return Data to Application
|  #Columns = 1End of sectionOptimizer Plan:RowsOperator(ID)Cost88.9704n/aRETURN( 1)259.878|88.9704n/aNLJOIN( 2)259.866/--------/       /-------/88.9704                             1n/a                              n/aFETCH                            FETCH(--)                             ( 7)47.3244                          15.1409/       /                /-------/       /88.9704  2.72109e+06       1                   326n/a        n/a          n/a                  n/aRIDSCN   Table:         IXSCAN    Table:( 4)    SDE             ( 8)     DB2GSE15.2035  STREETS        7.57664   GSE_SPATIAL_REFERENCE_SYSTEMS|                       |88.9704                  326n/a                 Index:SORT                 DB2GSE( 5)                 GSE_SRS_ID15.2032|88.9704n/aIXSCAN( 6)15.1872|2.72109e+06Index:SDER11_RK1
DB2的SQL执行计划输出还是比oracle的详细的多。至于以上的各项信息可以查看DB2的帮助文档。

DB2 SQL执行计划相关推荐

  1. DB查询分析器7.01新增的周、月SQL执行计划功能

                DB查询分析器7.01新增的周.月SQL执行计划功能 马根峰               (广东联合电子服务股份有限公司, 广州 510300) 1      引言   中国本 ...

  2. Oracle查看SQL执行计划的方式

    Oracle查看SQL执行计划的方式 获取Oracle sql执行计划并查看执行计划,是掌握和判断数据库性能的基本技巧.下面案例介绍了多种查看sql执行计划的方式: 基本有以下几种方式: 1.通过sq ...

  3. sql server varchar最大长度_来自灵魂的拷问—知道什么是SQL执行计划吗?

    面试官说:工作这么久了,应该知道sql执行计划吧,讲讲Sql的执行计划吧!看了看面试官手臂上纹的大花臂和一串看不懂的韩文,吞了吞口水,暗示自己镇定点,整理了一下思绪缓缓的对面试官说:我不会 面试官:. ...

  4. oracle sql 执行计划分析_《真正读懂Oracle SQL执行计划》

    maclean_0071人评论1235人阅读2013-10-25 15:18:12 [视频教学:性能优化]Maclean Liu的Oracle性能优化讲座第一回<真正读懂Oracle SQL执行 ...

  5. oracle执行计划走索引类型,SQL执行计划问题:where条件是主键(NUMBER类型字段)LIKE  :VAR,为什么执行计划不走索引?...

    SQL执行计划问题:where条件是主键(NUMBER类型字段)LIKE  :VAR,为什么执行计划不走索引? 中文社区 (MOSC) 数据库 (MOSC) 6 Replies Last update ...

  6. 资源放送丨《Oracle数据库SQL执行计划的取得和解析》PPT视频

    前段时间,墨天轮邀请Oracle优化方面的资深专家 陈晓辉 老师分享了<Oracle数据库SQL执行计划的取得和解析>,在这里我们共享一下PPT和视频,供大家参考学习. Oracle优化资 ...

  7. 2场直播丨Oracle数据库SQL执行计划的取得和解析、一次特殊的 Oralce 硬解析性能问题的技术分享...

    1. Oracle数据库SQL执行计划的取得和解析- 2021.02.23 2月23日(周二)晚八点直播课,Oracle优化资深专家陈晓辉,以专业ORACLE数据库技术支持工程师的角度讲解SQL文的执 ...

  8. 查看SQL执行计划的方法及优劣

    作者 | 胡佳伟:云和恩墨技术工程师,有多年数据库优化经验,在一线执行过多个包括通信.保险等行业的优化项目. 在 Oracle 的性能分析中,很多时候需要对 SQL 进行分析,而最重要的就是对执行计划 ...

  9. SQL执行计划错误导致临时表空间不足

    故障现象:临时表空间不足的问题已经报错过3次,客户也烦了,前两次都是同事添加5G的数据文件,目前已经达到40G,占用临时表空间主要是distinct 和group by 以及Union all 表数据 ...

  10. sql执行组件是灰色的_如何分析SQL执行计划图形组件

    sql执行组件是灰色的 In the previous articles of this series, SQL Server Execution Plans overview and SQL Ser ...

最新文章

  1. HttpPost导包遇到的问题
  2. Android 广播机制---BroadCast
  3. 51单片机控制步进电机的c语言程序,用AT89C51单片机控制步进电机的汇编源程序...
  4. 嵌入式设备ntp同步时间的一些笔记
  5. .netcore mvc docker环境jenkins一键部署(DevOps)
  6. json输出count如何计算_基于 Kafka + Flink + Redis 的电商大屏实时计算案例
  7. 怎么看接收灵敏度desense问题?
  8. 电子签章引入jar包
  9. C++汽车4S店管理系统
  10. Frsky X9D Plus遥控器和 Frisky R8 Pro接收机对频
  11. python使用作为转义符的开始符号_python转义符的使用
  12. 【Java分享客栈】我为什么极力推荐XXL-JOB作为中小厂的分布式任务调度平台
  13. 智慧政务说明书 督察督办(八)
  14. 2、如何搭建百度离线地图服务
  15. 【Appium】手机滑动swipe方法及如何进行坐标定位
  16. Notepad++添加读取十六进制插件HexEditor
  17. 05-现代威胁环境下的10个SIEM用例
  18. 实例010 猴子吃桃
  19. PICO《轻世界》体验:随心畅玩,洒脱创作,潜力无限
  20. 2021东京奥运会在哪看直播?当贝投影F3看直播效果好么?

热门文章

  1. 关于黑莓8700刷ROM4.5后使用五笔输入法出现问号的处理
  2. HTML期末网页设计——设计报告
  3. php 清理脚本病毒,Autorun 病毒清除工具bat代码
  4. 网易云音乐——网易云云盘上传音乐自动改名的解决方法
  5. 成为黑客必须掌握的知识!
  6. ESXi7.0 安装 MacOS (ESXi Unlocker 3.0.3)
  7. “猜猜红桃A在哪里”——android小游戏(入门学习必备)
  8. 本人见过的最有用的日志!不来转藏肯定后悔
  9. 【千份热门课后习题答案大全】
  10. rx590 黑苹果 无货_黑苹果配置挑选,教你组装一台苹果机