选择显示字体大小

使用db2look 重新创建优化器访问计划(4)

生成 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  
                
                4  
             msjoin 
             (   2)  
             25.8843  
                2  
          /-----+-----\ 
        1                4  
     tbscan           tbscan  
     (   3)           (   5)  
     12.913           12.9682  
        1                1  
                        
        8               35  
 table: skapoor   table: skapoor   
       org             staff  

您在测试中获得了一个不同于生产中的访问计划。本例中,显然我们在测试系统上已经将 dft_queryopt(默认的查询优化)从 5 修改为 3。因此,您看到的是 merge join 计划,而非 hash join 计划,以及有一点点区别的总成本(total cost)。 
因为这些计划不匹配(假设您不确定为什么),所以要检查 db2exfmt 输出中的配置。见 表 2。 
正如您可以看到的,测试(test)和生产(production)之间的惟一区别就是优化级别(optimization level),我们特意将之从 5 修改为 3,只是为了显示在测试环境中复制生产访问计划为何会不成功。 
本例中,您将使用下列 update 语句将 dft_queryopt 更新为 5: 

update db cfg for sample using dft_queryopt 5 

然后,停止并重新连接数据库。再次对 dummydb 发出 query.sql,并使用 db2exfmt 命令生成访问计划。这次,您将看到相同的访问计划。否则,就进一步确保本文中所讨论的所有优化器相关的参数都是相同的。 
示例 2: 
该示例显示了 db2look 命令中 -m 选项的重要性。前面用 -m 选项收集的统计数据在测试和生产中应该相同。本例中,我们将看到没有正确更新统计数据时计划是如何变化的。  
数据库管理器配置、数据库配置和 db2set 注册表变量与上面 示例 1 中的相同。这里的模式名是 skapoor。用您的表的模式替换它。数据库是相同的,与 示例 1 中一样是 sample 和 dummy。这里所使用的平台和 db2level 是 aix 5.1 和 db2 udb ese v8.2,fix pack 8,单分区。 
在 sample 数据库上执行下列命令: 

db2 "connect to sample" 
db2 "create index name_ind on staff (name,id)" 
db2 "runstats on table skapoor.staff with distribution and indexes all" 
db2 "set current explain mode explain" 
db2 "select name from staff where id=10 order by name" 
db2 "set current explain mode no" 
db2 "terminate" 

使用 db2exfmt 生成访问计划。您将看到下面的访问计划:  

access plan: 
----------- 
        total cost:             0.111065 
        query degree:           1 

      rows 
     return 
     (   1) 
      cost 
       i/o 
        
        1 
     ixscan 
     (   2) 
    0.111065 
        0 
        
       35 
 index: skapoor 
    name_ind 

从 sample 数据库中收集 db2look 信息: 

db2look -d sample -l -o storage.out 
db2look -d sample -e -a -m -t staff -o db2look.out 
db2look -d sample -f -fd -o config.out 

修改这些文件以使您连接 dummy 数据库,而非之前在上面 示例 1 中所连接的 sample 数据库。  
手工修改统计数据之一。在 db2look.out 文件中搜索下列语句(请注意,模式名、tabschema 和 indschema 可能与您的具体情况不同): 

update sysstat.indexes 
set nleaf=1, 
    nlevels=1, 
    firstkeycard=35, 
    first2keycard=35, 
    first3keycard=-1, 
    first4keycard=-1, 
    fullkeycard=35, 
    clusterfactor=-1.000000, 
    clusterratio=100, 
    sequential_pages=0, 
    density=0, 
    average_sequence_gap=0.000000, 
    average_sequence_fetch_gap=0.000000, 
    average_sequence_pages=0.000000, 
    average_sequence_fetch_pages=0.000000, 
    average_random_pages=1.000000, 
    average_random_fetch_pages=0.000000, 
    numrids=35, 
    numrids_deleted=0, 
    num_empty_leafs=0 
where indname = ’name_ind’ and indschema = ’skapoor ’ 
      and tabname = ’staff’ and tabschema = ’skapoor ’; 

现在,将 firstkeycard、first2keycard、fullkeycard 和 numrids 从 35 修改为 37。现在保存 db2look.out 文件并运行这 3 个文件: 

db2 -tvf config.out > config_output.out 
db2 -tvf storage.out > storage_output.out 
db2 terminate 
db2stop 
db2start 
db2 -tvf db2look.out > db2look_output.out 

检查前两个文件 config_output.out 和 storage_output.out 的内容,以确保它们运行成功。现在,检查 db2look_output.out 文件的内容。您将看到下列更新语句失败了: 

update sysstat.indexes set nleaf=1, nlevels=1, firstkeycard=37, first2keycard=37 
, first3keycard=-1, first4keycard=-1, fullkeycard=37, clusterfactor=-1.000000, c 
lusterratio=100, sequential_pages=0, density=0, average_sequence_gap=0.000000, a 
verage_sequence_fetch_gap=0.000000, average_sequence_pages=0.000000, average_seq 
uence_fetch_pages=0.000000, average_random_pages=1.000000, average_random_fetch_ 
pages=0.000000, numrids=37, numrids_deleted=0, num_empty_leafs=0 where indname = 
 ’name_ind’ and indschema = ’skapoor ’ and tabname = ’staff’ and tabschema = ’sk 
apoor ’ 
db21034e  the command was processed as an sql statement because it was not a 
valid command line processor command.  during sql processing it returned: 
sql1227n  the catalog statistic "37" for column "fullkeycard" is out of range 
for its target column, has an invalid format, or is inconsistent in relation 
to some other statistic. reason code = "8".  sqlstate=23521 

正如您可以看到的,上面用于索引 name_ind 的 update 语句失败了,因为 fullkeycard 大于表的基数(card)。正如通过 db2look.out 文件中的下列更新语句可以看到的,card 是 35: 

update sysstat.tables 
set card=35, 
    npages=1, 
    fpages=1, 
    overflow=0, 
    active_blocks=0 
where tabname = ’staff’ and tabschema = ’skapoor ’; 

现在,再次以解释模式运行相同的查询: 

db2 "select name from staff where id=10 order by name" 

并生成访问计划。您将看到它是不同的: 

access plan: 
----------- 
        total cost:             12.972 
        query degree:           1 

      rows 
     return 
     (   1) 
      cost 
       i/o 
        
        1 
     tbscan 
     (   2) 
     12.972 
        1 
        
        1 
     sort 
     (   3) 
     12.9708 
        1 
        
        1 
     tbscan 
     (   4) 
     12.9682 
        1 
        
       35 
 table: skapoor 
      staff 

该示例显示,如果在表上发生 write 活动时运行 runstats,统计数据就可能与本示例中的不一致。因此,用于更新统计数据的 update 语句可能失败并产生 sql1227n 错误消息。所有的 update 语句都运行成功十分重要,如果存在不一致性,就应该进行修理并重新运行。本例中,解决方案是将 keycards 和 numrids 从 37 重新修改为 35。 


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons