35 8
TABLE: SKAPOOR TABLE: SKAPOOR
STAFF ORG
现在,这就是您要在生产 sample 数据库上继续的计划。您需要在测试环境中模拟该计划。
从生产 sample 数据库中收集下列信息:
db2look -d SAMPLE -l -o storage.out
db2look -d SAMPLE -f -fd -o config.out
db2look -d SAMPLE -e -a -m -t ORG SALES -o table.ddl
测试环境:
修改上面将数据库从 SAMPLE 连接到 DUMMYDB 时所收集的每个文件中的数据库名。
例如,如果您查看了 3 个文件的内容,就会注意到:
CONNECT TO SAMPLE;
将它修改为:
CONNECT TO DUMMYDB;
在测试环境中接管这些文件。本例中,所有的表都是在默认的表空间 USERSPACE1 中创建的。因此,它们也应在测试系统上相同的 SMS 表空间中用 storage.out 中转储的相同配置(包括 PREFETCHSIZE、EXTENTSIZE 等)进行创建。
在 config.out 文件中进行少量修改。将下列内容:
UPDATE DB CFG FOR SAMPLE USING dft_queryopt 5;
修改为
UPDATE DB CFG FOR SAMPLE USING dft_queryopt 3;
并保存 config.out 文件。
现在,执行 storage.out、config.out 和 table.ddl,如下:
db2 -tvf storage.out > storage_output.out
db2 -tvf config.out > config_output.out
db2 -tvf table.ddl > table.out
检查输出文件以确保所有命令都成功运行了。并且按照生产环境设置中所显示的用于 SAMPLE DB 的设置来修改 DBHEAP、STMTHEAP、NUM_FREQVALUES、NUM_QUANTILES,使它们适用于 DUMMYDB。同时,检查注册表变量设置是否尽可能地相同。
使用 db2stop 和 db2start 停止并启动该实例。重新为 DUMMYDB 数据库创建解释表:
db2 connect to dummydb;
<install path>\sqllib\misc\db2 -tvf EXPLAIN.DDL
db2 terminate;
现在,对 DUMMYDB 数据库运行查询,在前面对 SAMPLE 数据库运行查询时所生成的 query.sql 文件中将数据库名从 SAMPLE 修改为 DUMMYDB。
C:\>db2 -tvf query.sql
connect to dummydb
Database Connection Information
Database server = DB2/NT 8.2.1
SQL authorization ID = SKAPOOR
Local database alias = DUMMYDB
set current explain mode explain
DB20000I The SQL command completed successfully.
select * from org a, staff b where a.deptnumb=b.dept and b.dept=15
SQL0217W The statement was not executed as only Explain information requests
are being processed. SQLSTATE=01604
set current explain mode no
DB20000I The SQL command completed successfully.
C:\>db2 terminate
DB20000I The TERMINATE command completed successfully.
[page_break]生成 db2exfmt 输出:
db2exfmt -d DUMMYDB -g TIC -w -1 -n % -s % -# 0 -o test_dummydb_exfmt.txt
检查 test_dummydb_exfmt.txt 的内容并查看访问计划:
Access Plan:
-----------
Total Cost: 25.8843
Query Degree: 1
Rows
RETURN
( 1)
Cost
I/O
关键词:运用db2look 重新创建优化器访问计划