使用DB2look重新创建优化器访问计划(5)
手工修改统计数据之一。在 db2look.out 文件中搜索下列语句(请注重,模式名、TABSCHEMA 和 INDSCHEMA 可能与您的具体情况不同):
UPDATE SYSSTAT.INDEXESSET 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=0WHERE 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.outdb2 -tvf storage.out > storage_output.outdb2 terminatedb2stopdb2startdb2 -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, 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=37,NUMRIDS_DELETED=0, NUM_EMPTY_LEAFS=0 WHERE INDNAME =’NAME_IND’ AND INDSCHEMA = ’SKAPOOR ’AND TABNAME = ’STAFF’ AND TABSCHEMA = ’SKAPOOR ’DB21034E The command was processed asan SQL statement because it was not avalid Command Line Processor command.During SQL processing it returned:SQL1227N The catalog statistic "37"for column "FULLKEYCARD" is out of rangefor its target column, has an invalidformat, or is inconsistent in relationto some other statistic. Reason Code = "8".SQLSTATE=23521正如您可以看到的,上面用于索引 NAME_IND 的 UPDATE 语句失败了,因为 FULLKEYCARD 大于表的基数(CARD)。正如通过
db2look.out 文件中的下列更新语句可以看到的,CARD 是 35:UPDATE SYSSTAT.TABLESSET CARD=35,NPAGES=1,FPAGES=1,OVERFLOW=0,ACTIVE_BLOCKS=0WHERE TABNAME = ’STAFF’ AND TABSCHEMA = ’SKAPOOR ’;
现在,再次以解释模式运行相同的查询:db2 "select name from staff where id=10 order by name"
并生成访问计划。您将看到它是不同的:Access Plan:-----------Total Cost: 12.972Query Degree: 1RowsRETURN( 1)CostI/O|1TBSCAN( 2)12.9721|1SORT( 3)12.97081|1TBSCAN( 4)12.96821|35TABLE: SKAPOORSTAFF
该示例显示,假如在表上发生 WRITE 活动时运行 RUNSTATS,统计数据就可能与本示例中的不一致。因此,用于更新统计数据的 UPDATE
语句可能失败并产生 SQL1227N 错误消息。所有的 UPDATE 语句都运行成功十分重要,假如存在不一致性,就应该进行修理并重新运行。本例中,解决方案是将KEYCARDS 和 NUMRIDS 从 37 重新修改为 35。
相关文章: