六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 84|回复: 0

db2 Optimizing queries:db2 优化查询

[复制链接]

升级  60.33%

117

主题

117

主题

117

主题

举人

Rank: 3Rank: 3

积分
381
 楼主| 发表于 2013-1-13 18:35:54 | 显示全部楼层 |阅读模式
db2 -tvf test.sqldb2 runstats on table mytab with distribution and detailed indexes all shrlevel change
上面的db2 -tvf是最普通不过的命令了,就是执行脚本文件,下面的这个命令就是收集表在数据库中的统计信息,收集统计信息的作用就是优化查询计划,查询计划好了,SQL就快了,不过在runstats之前最好先执行以下reorg命令.
db2 reorg table mytab

有些时候会提示让你加上表的模式名,假设你的模式名是:schema:
db2 reorg table schema.mytab
这个方法对于runstats也是适用的。

visual explain A graphical tool available in the db2  Command Center (or Control Center) - to examine single queries, whether static or dynamic. Shows a color-coded tree. Clicking on a node allows you to view the arguments, statistics, and cost estimate of the node. You can also jump directly to DB2's documentation on that node type. Visual Explain can also be run from the command line as db2vexp.exe, though it then lacks static SQL ability.
db2expln The "bare bones" tool, giving text output from static SQL packages only. This can optionally include a character mode graph.
dynexpln Gives a text-mode analysis of a dynamic SQL query. It actually packages the dynamic query and calls db2expln to do the work.  From unix command line invoke it as:
  dynexpln -d mydb -f test.sql
  dynexpln -h
db2exfmt  A formatter for previously stored explain data.

执行计划查看工具:
db2vexp.exe db2自带的图形化执行计划查看工具
db2expln    文本输出的静态SQL执行计划查看工具
dynexpln    文本输出的动态SQL查询计划
dynexpln -d mydb -f test.sql
dynexpln -h
db2exfmt    前面其它工具获得的执行计划格式化工具
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表