原文:http://blog.51cto.com/freebile/1068610

 

db2有图形执行计划显示工具,如果没有图形环境,如unix主机,可以生成文本的
文件来显示执行计划
1.如果第一次执行,请先 connect to dbname,
执行db2 -tvf $HOME/sqllib/misc/EXPLAIN.DDL建立执行计划表
2.db2 set current explain mode explain
设置成解释模式,并不真正执行下面将发出的sql命令

3.db2 "select count(*) from DOA.ODS_SFC_SALE_BARCODE_T"  
执行你想要分析的sql语句


4.db2 set current explain mode no

取消解释模式
5.db2exfmt -d sample  -g TIC -w -l -s % -n % -o db2exmt.out
执行计划输出到文件db2exmt.out

相关参数设置可以参考
(This application formats the contents of the Explain tables.
Given a database name and other qualifying information, this tool will,
query the Explain tables for information and format the results.

Syntax is:

db2exfmt [[-1] [-d <dbname>;] [-e <schema>;] [-f O] [-h] [-l] [-n <name>;] [-o <outfile>;]
          [-s <schema>;] [-t]] [-u <user>; <pw>;] [-w <timestamp>;] [-# <sectnbr>;] [-v <srcvers>;]

Input Fields:
        -d <dbname>;     = database name containing packages
        -e <schema>;     = Explain table schema
        -f O            = Formatting flags (O = Operator summary)
        -g[x]  [O[T|F]IC] - Graph plan. x - turn off options (default is to turn them on) Options include:
                             O = only generate graph
                             T = Include Total Cost in graph
                             F = Include First Tuple Cost in graph
                             I = Include I/O Cost in graph
                             C = Include Cardinality in graph
                          Any combination of these options is allowed,
                          except 'F' and 'T', which are mutually exclusive.
        -h              = help
        -l              = respect package name case
        -n <name>;       = name of source of Explain
                          request (SOURCE_NAME)
        -no_map_char    = do no map a non-printable character to a '.'
        -no_prompt      = do not prompt for user input
        -o <outfile>;    = name of output file
        -r <requester>;  = id of explain requester
        -s <schema>;     = Schema or qualifier of source of Explain
                          request (SOURCE_SCHEMA)
        -t              = terminal output desired
        -u <user>; <pw>;  = user ID and password for connecting to database
        -v <srcvers>;    = Source Version of source of Explain request (default %)
        -w <timestamp>;  = Explain timestamp (use -1 to get newest Explain request)
        -# <sectnbr>;    = section number in source (use zero for all sections)

-1              = Use defaults -e % -n % -s % -v % -w -1 -# 0   If Explain schema is not supplied, the contents of the environment
        variable $USER, or $USERNAME will be used as a default. If this
        variable is not found, the user will be prompted for an Explain schema.

Source name, source schema, and Explain timestamp may be supplied
        in LIKE predicate form, which allows percent sign (%) and
        underscore (_) to be used as pattern matching characters to select
        multiple sources with one invocation.

Prompting will occur for all fields that are not supplied or are
        incompletely specified (except for the -h, -l and -no_map_char options).

If -o is specified without a file name, and -t is not specified,
        the user will be prompted for a file name (the default name is
        db2exfmt.out).

If neither -o nor -t is specified, the user will be prompted for
        a file name (the default is terminal output).

If -o and -t are both specified, then the output will be directed
        to the terminal.
)

6.查看输出文件分析sql的运行开销,示例输出如下

-------------------

DB2 Universal Database Version 9.5, 5622-044 (c) Copyright IBM Corp. 1991, 2007
Licensed Material - Program Property of IBM
IBM DATABASE 2 Explain Table Format Tool

******************** EXPLAIN INSTANCE ********************

DB2_VERSION:   09.05.4
SOURCE_NAME:   SQLC2G15
SOURCE_SCHEMA:   NULLID  
SOURCE_VERSION:  
EXPLAIN_TIME:   2012-11-23-16.02.53.924371 
EXPLAIN_REQUESTER:  DOAADMIN

Database Context:
----------------
 Parallelism:   None
 CPU Speed:   4.959615e-07
 Comm Speed:   100
 Buffer Pool size:  438463
 Sort Heap size:  256
 Database Heap size:  2645
 Lock List size:  100
 Maximum Lock List:  20
 Average Applications:  1
 Locks Available:  1280

Package Context:
---------------
 SQL Type:   Dynamic
 Optimization Level:  5
 Blocking:   Block All Cursors
 Isolation Level:  Cursor Stability

---------------- STATEMENT 1  SECTION 201 ----------------
 QUERYNO:   3
 QUERYTAG:   CLP                 
 Statement Type:  Select
 Updatable:   No
 Deletable:   No
 Query Degree:   1

Original Statement:
------------------
select count(*) 
from DOA.ODS_SFC_SALE_BARCODE_T

Optimized Statement:
-------------------
SELECT Q3.$C0 
FROM 
   (SELECT COUNT(*) 
   FROM 
      (SELECT $RID$ 
      FROM DOA.ODS_SFC_SALE_BARCODE_T AS Q1) AS Q2) AS Q3

Access Plan:
-----------
 Total Cost:   51435.9
 Query Degree:  1

Rows 
     RETURN
     (   1)
      Cost 
       I/O 
       |
        1 
     GRPBY 
     (   2)
     51435.9 
      2027 
       |
     765027 
     IXSCAN
     (   3)
     51341.1 
      2027 
       |
     765027 
 INDEX: DOA     
    S_SALE_T1
       Q1

Extended Diagnostic Information:
--------------------------------

No extended Diagnostic Information for this statement.

Plan Details:
-------------

1) RETURN: (Return Result)
  Cumulative Total Cost:   51435.9
  Cumulative CPU Cost:   1.53426e+09
  Cumulative I/O Cost:   2027
  Cumulative Re-Total Cost:  747.847
  Cumulative Re-CPU Cost:  1.50787e+09
  Cumulative Re-I/O Cost:  0
  Cumulative First Row Cost:  51435.9
  Estimated Bufferpool Buffers:  2028

Arguments:
  ---------
  BLDLEVEL: (Build level)
   DB2 v9.5.0.4 : s090429
  HEAPUSE : (Maximum Statement Heap Usage)
   80 Pages
  PREPTIME: (Statement prepare time)
            1 milliseconds
  STMTHEAP: (Statement heap size)
   6402

Input Streams:
  -------------
   3) From Operator #2

Estimated number of rows:  1
    Number of columns:   1
    Subquery predicate ID:   Not Applicable

Column Names:
    ------------
    +Q4.$C0

2) GRPBY : (Group By)
  Cumulative Total Cost:   51435.9
  Cumulative CPU Cost:   1.53426e+09
  Cumulative I/O Cost:   2027
  Cumulative Re-Total Cost:  747.847
  Cumulative Re-CPU Cost:  1.50787e+09
  Cumulative Re-I/O Cost:  0
  Cumulative First Row Cost:  51435.9
  Estimated Bufferpool Buffers:  2028

Arguments:
  ---------
  AGGMODE : (Aggregration Mode)
   COMPLETE
  GROUPBYC: (Group By columns)
   FALSE
  GROUPBYN: (Number of Group By columns)
   0
  ONEFETCH: (One Fetch flag)
   FALSE

Input Streams:
  -------------
   2) From Operator #3

Estimated number of rows:  765027
    Number of columns:   0
    Subquery predicate ID:   Not Applicable

Output Streams:
  --------------
   3) To Operator #1

Estimated number of rows:  1
    Number of columns:   1
    Subquery predicate ID:   Not Applicable

Column Names:
    ------------
    +Q4.$C0

3) IXSCAN: (Index Scan)
  Cumulative Total Cost:   51341.1
  Cumulative CPU Cost:   1.343e+09
  Cumulative I/O Cost:   2027
  Cumulative Re-Total Cost:  652.991
  Cumulative Re-CPU Cost:  1.31662e+09
  Cumulative Re-I/O Cost:  0
  Cumulative First Row Cost:  50.0327
  Estimated Bufferpool Buffers:  2028

Arguments:
  ---------
  MAXPAGES: (Maximum pages for prefetch)
   2026
  PREFETCH: (Type of Prefetch)
   NONE
  ROWLOCK : (Row Lock intent)
   NEXT KEY SHARE
  SCANDIR : (Scan Direction)
   FORWARD
  TABLOCK : (Table Lock intent)
   INTENT SHARE
  TBISOLVL: (Table access Isolation Level)
   CURSOR STABILITY

Input Streams:
  -------------
   1) From Object DOA.S_SALE_T1

Estimated number of rows:  765027
    Number of columns:   1
    Subquery predicate ID:   Not Applicable

Column Names:
    ------------
    +Q1.$RID$

Output Streams:
  --------------
   2) To Operator #2

Estimated number of rows:  765027
    Number of columns:   0
    Subquery predicate ID:   Not Applicable

Objects Used in Access Plan:
---------------------------

Schema: DOA     
 Name:  ODS_SFC_SALE_BARCODE_T
 Type:  Table (reference only)

Schema: DOA     
 Name:  S_SALE_T1
 Type:  Index
   Time of creation:   2011-01-15-14.03.41.217506
   Last statistics update:  2012-04-23-18.45.51.142593
   Number of columns:   1
   Number of rows:   765027
   Width of rows:    -1
   Number of buffer pool pages:  50996
   Distinct row values:   No
   Tablespace name:   TS_INDEX_4K
   Tablespace overhead:   24.100000
   Tablespace transfer rate:  0.900000
   Source for statistics:   Single Node
   Prefetch page count:   128
   Container extent page count:  32
   Index clustering statistic:  97.000000
   Index leaf pages:   2026
   Index tree levels:   3
   Index full key cardinality:  18700
   Index first key cardinality:  18700
   Index first 2 keys cardinality: -1
   Index first 3 keys cardinality: -1
   Index first 4 keys cardinality: -1
   Index sequential pages:  0
   Index page density:   0
   Index avg sequential pages:  0
   Index avg gap between sequences:0
   Index avg random pages:  2026
   Fetch avg sequential pages:  -1
   Fetch avg gap between sequences:-1
   Fetch avg random pages:  -1
   Index RID count:   765027
   Index deleted RID count:  0
   Index empty leaf pages:  0
   Base Table Schema:   DOA     
   Base Table Name:   ODS_SFC_SALE_BARCODE_T
   Columns in index:
    BILL(A)

Base Table For Index Not Already Shown:
---------------------------------------

Schema: DOA     
 Name:  ODS_SFC_SALE_BARCODE_T
   Time of creation:   2011-01-15-13.40.52.458517
   Last statistics update:  2012-04-23-18.45.51.142593
   Number of data partitions:  1
   Number of columns:   21
   Number of rows:   765027
   Number of pages:   50996
   Number of pages with rows:  50996
   Table overflow record count:  0
   Indexspace name:   TS_INDEX_4K
   Tablespace name:   TS_4K
   Tablespace overhead:   24.100000
   Tablespace transfer rate:  0.900000
   Prefetch page count:   -1
   Container extent page count:  32

Long tablespace name:   TS_4K

(转)explain、db2exfmt 命令的使用:文本输出执行计划的更多相关文章

  1. MySQL 执行计划explain详解

    MySQL 执行计划explain详解 2015-08-10 13:56:27 分类: MySQL explain命令是查看查询优化器如何决定执行查询的主要方法.这个功能有局限性,并不总会说出真相,但 ...

  2. 0912MySQL 执行计划explain详解

    转自http://blog.itpub.net/29773961/viewspace-1767044/ 该博客内容是比较全的,虽然写的比较晦涩,多读几遍还是不错的 explain命令是查看查询优化器如 ...

  3. explain查看sql执行计划

    http://www.cnblogs.com/wolf-sun/p/5291563.html 一该命令作用:该命令会向您展示查询是如何被执行的. 1.各个项的含义:https://blog.csdn. ...

  4. 【mysql】mysql 调优之 ——执行计划 explain

    1.what is explain(explain 是个什么东东) explain(解释),在 Mysql 中 作为一个关键词,用来解释 Mysql 是如何执行语句,可以连接 select .dele ...

  5. 高性能mysql 附录D explain执行计划详解

    EXPLAIN: extended关键字:在explain后使用extended关键字,可以显示filtered列和warning信息.在较旧的MySQL版本中,扩展信息是使用EXPLAIN EXTE ...

  6. MySQL执行计划【explain】详解

    本文已经收录到github仓库,仓库用于分享Java相关知识总结,包括Java基础.MySQL.Springboot.mybatis.Redis.rabbitMQ等等,欢迎大家提pr和star! gi ...

  7. Mysql explain执行计划

    EXPLAIN(小写explain)显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. EXPLAIN + sql语句可以查看mysql的执行 ...

  8. 详解Linux中的cat文本输出命令用法

    作系统 > LINUX >   详解Linux中的cat文本输出命令用法 Linux命令手册   发布时间:2016-01-14 14:14:35   作者:张映    我要评论   这篇 ...

  9. 使用MySQL中的EXPLAIN解释命令来检查SQL

    我们看到许多客户的系统因为SQL及数据库设计的很差所以导致许多性能上的问题,这些问题不好解决,但是可以采用一套简单的策略来检查生产系统,发现并纠正一些共性问题. 很显然,您应该尽最大努力设计出最好的数 ...

随机推荐

  1. .Net实现Windows服务安装完成后自动启动的两种方法

    考虑到部署方便,我们一般都会将C#写的Windows服务制作成安装包.在服务安装完成以后,第一次还需要手动启动服务,这样非常不方便. 方法一:在安装完成事件里面调用命令行的方式启动服务 此操作之前要先 ...

  2. nginx 下载 大文件被截断

    如果出现大文件被截断,且ngix的日志大量出现以下类似报错: 则说明是nginx没有fastcgi_temp的读写权限.其中fastcgi_temp是自己的文件夹名称,每个人的不同且路径也会不同,这个 ...

  3. 启动Android App时,动态将Sqlite数据库文件导入到手机中类方法

    package com.aqioo.db; import java.io.File; import java.io.FileOutputStream; import java.io.InputStre ...

  4. Mysql之数据表操作

    数据表操作: 查看当前数据库中所有的表: show tables; 查看当前使用数据库: select database(); 使用数据表: use 表名; 创建数据表: create table 数 ...

  5. Ng第十二课:支持向量机(Support Vector Machines)(三)

    11 SMO优化算法(Sequential minimal optimization) SMO算法由Microsoft Research的John C. Platt在1998年提出,并成为最快的二次规 ...

  6. Ng第一课:引言(Introduction)

    Machine Learning(机器学习)是研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能. 它是人工智能的核心,是使计算机具有智能的根本 ...

  7. MapGis如何实现WebGIS分布式大数据存储的

    作为解决方案厂商,MapGis是如何实现分布式大数据存储的呢? MapGIS在传统关系型空间数据库引擎MapGIS SDE的基础之上,针对地理大数据的特点,构建了MapGIS DataStore分布式 ...

  8. DeepFace和GAN

    由于换脸技术的影响,现在造假视频的成本越来越低.AI换脸视频也越来越热门,甚至有一些已经达到了以假乱真的程度.虽然有明星反对表示无奈,可是.... 据报道,2018年,arXiv上发布了902篇GAN ...

  9. 20155326 《Java程序设计》第8周学习总结

    20155326 <Java程序设计>第8周学习总结 教材学习内容总结 NIO (1)NIO使用频道来衔接数据节点,在处理数据时,NIO可以让你设定缓冲区容量,在缓冲区中对感兴趣的数据区块 ...

  10. Curl工具的使用

      Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 工具下载 在官网处下载工具包:http:// ...