DB2 手动修改索引统计信息时: SQL1227N Reason Code = "8"
2015-11-23 22:44
447 查看
问题:
在手动修改某个索引的统计信息时,报错 SQL1227N, Reason Code = "8":
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 "1" for column "INDCARD" 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
问题分析:
可能的原因之一是统计信息与对应表的不一致。
重现:
$ db2level
DB21085I Instance "e97q6c" uses "64" bits and DB2 code release "SQL09076" with
level identifier "08070107".
Informational tokens are "DB2 v9.7.0.6", "s120629", "IP23414", and Fix Pack
"6".
Product is installed at "/opt/IBM/db2/V9.7.6".
$ db2 "create table t1(id int, name char(20))"
DB20000I The SQL command completed successfully.
$ db2 "insert into t1 values(1,'ab'),(2,'bc'),(3,'cd'),(1,'ef'),(4,'bc'),(5,'bc')"
DB20000I The SQL command completed successfully.
$ db2 "create index idx1 on t1(id)"
DB20000I The SQL command completed successfully.
$ db2 "create index idx2 on t1(name)"
DB20000I The SQL command completed successfully.
$ db2 "select NLEAF, NLEVELS, INDCARD, substr(INDNAME,1,30) as INDNAME from syscat.indexes where TABNAME='T1'"
NLEAF NLEVELS INDCARD INDNAME
-------------------- ------- -------------------- ------------------------------
-1 -1 -1 IDX1
-1 -1 -1 IDX2
2 record(s) selected.
$ db2 "runstats on table E97Q6C.T1 and detailed INDEXES ALL"
DB20000I The RUNSTATS command completed successfully.
$ db2 "select NLEAF, NLEVELS, INDCARD, substr(INDNAME,1,30) as INDNAME from syscat.indexes where TABNAME='T1'"
NLEAF NLEVELS INDCARD INDNAME
-------------------- ------- -------------------- ------------------------------
1 1 6 IDX1
1 1 6 IDX2
2 record(s) selected.
$ db2 " update SYSSTAT.INDEXES set INDCARD=5 where INDNAME='IDX1' and tabname= 'T1' "
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 "5" for column "INDCARD" 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
$ db2 " update SYSSTAT.INDEXES set INDCARD=6 where INDNAME='IDX1' and tabname= 'T1' "
DB20000I The SQL command completed successfully.
$ db2 " update SYSSTAT.INDEXES set INDCARD=188 where INDNAME='IDX1' and tabname= 'T1' "
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 "188" for column "INDCARD" 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
解决:
先修改表的统计信息,再修改索引的统计信息,使其保持一致
$ db2 "update SYSSTAT.TABLES SET CARD=188 where tabname='T1'"
DB20000I The SQL command completed successfully.
$ db2 " update SYSSTAT.INDEXES set INDCARD=188 where INDNAME='IDX1' and tabname= 'T1' "
DB20000I The SQL command completed successfully.
$ db2 "select NLEAF, NLEVELS, INDCARD, substr(INDNAME,1,30) as INDNAME from syscat.indexes where TABNAME='T1'"
NLEAF NLEVELS INDCARD INDNAME
-------------------- ------- -------------------- ------------------------------
1 1 188 IDX1
1 1 6 IDX2
2 record(s) selected.
----------------------------------------------------------------------
在以下的版本中测试,得到完全相同的结果:
[db2b /home/db2users/e101q3a]$ db2level
DB21085I This instance or install (instance name, where applicable: "e101q3a")
uses "64" bits and DB2 code release "SQL10013" with level identifier
"0204010E".
Informational tokens are "DB2 v10.1.0.3", "s130918", "IP23509", and Fix Pack
"3".
Product is installed at "/opt/IBM/db2/V10.1.3".
在手动修改某个索引的统计信息时,报错 SQL1227N, Reason Code = "8":
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 "1" for column "INDCARD" 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
问题分析:
可能的原因之一是统计信息与对应表的不一致。
重现:
$ db2level
DB21085I Instance "e97q6c" uses "64" bits and DB2 code release "SQL09076" with
level identifier "08070107".
Informational tokens are "DB2 v9.7.0.6", "s120629", "IP23414", and Fix Pack
"6".
Product is installed at "/opt/IBM/db2/V9.7.6".
$ db2 "create table t1(id int, name char(20))"
DB20000I The SQL command completed successfully.
$ db2 "insert into t1 values(1,'ab'),(2,'bc'),(3,'cd'),(1,'ef'),(4,'bc'),(5,'bc')"
DB20000I The SQL command completed successfully.
$ db2 "create index idx1 on t1(id)"
DB20000I The SQL command completed successfully.
$ db2 "create index idx2 on t1(name)"
DB20000I The SQL command completed successfully.
$ db2 "select NLEAF, NLEVELS, INDCARD, substr(INDNAME,1,30) as INDNAME from syscat.indexes where TABNAME='T1'"
NLEAF NLEVELS INDCARD INDNAME
-------------------- ------- -------------------- ------------------------------
-1 -1 -1 IDX1
-1 -1 -1 IDX2
2 record(s) selected.
$ db2 "runstats on table E97Q6C.T1 and detailed INDEXES ALL"
DB20000I The RUNSTATS command completed successfully.
$ db2 "select NLEAF, NLEVELS, INDCARD, substr(INDNAME,1,30) as INDNAME from syscat.indexes where TABNAME='T1'"
NLEAF NLEVELS INDCARD INDNAME
-------------------- ------- -------------------- ------------------------------
1 1 6 IDX1
1 1 6 IDX2
2 record(s) selected.
$ db2 " update SYSSTAT.INDEXES set INDCARD=5 where INDNAME='IDX1' and tabname= 'T1' "
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 "5" for column "INDCARD" 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
$ db2 " update SYSSTAT.INDEXES set INDCARD=6 where INDNAME='IDX1' and tabname= 'T1' "
DB20000I The SQL command completed successfully.
$ db2 " update SYSSTAT.INDEXES set INDCARD=188 where INDNAME='IDX1' and tabname= 'T1' "
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 "188" for column "INDCARD" 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
解决:
先修改表的统计信息,再修改索引的统计信息,使其保持一致
$ db2 "update SYSSTAT.TABLES SET CARD=188 where tabname='T1'"
DB20000I The SQL command completed successfully.
$ db2 " update SYSSTAT.INDEXES set INDCARD=188 where INDNAME='IDX1' and tabname= 'T1' "
DB20000I The SQL command completed successfully.
$ db2 "select NLEAF, NLEVELS, INDCARD, substr(INDNAME,1,30) as INDNAME from syscat.indexes where TABNAME='T1'"
NLEAF NLEVELS INDCARD INDNAME
-------------------- ------- -------------------- ------------------------------
1 1 188 IDX1
1 1 6 IDX2
2 record(s) selected.
----------------------------------------------------------------------
在以下的版本中测试,得到完全相同的结果:
[db2b /home/db2users/e101q3a]$ db2level
DB21085I This instance or install (instance name, where applicable: "e101q3a")
uses "64" bits and DB2 code release "SQL10013" with level identifier
"0204010E".
Informational tokens are "DB2 v10.1.0.3", "s130918", "IP23509", and Fix Pack
"3".
Product is installed at "/opt/IBM/db2/V10.1.3".
相关文章推荐
- DB2 自动递增字段实现方法
- 创建一个空的IBM DB2 ECO数据库的方法
- IBM DB2 Connect简介(1)
- DB2 日期和时间的函数应用说明
- DB2 常用命令速查(备忘)
- DB2 常用命令小结
- DB2比较常用与实用sql语句总结
- db2 导入导出单个表的操作详解
- DB2新手使用的一些小笔记:新建实例、数据库路径不存在、客户端连接 .
- CentOS下DB2数据库安装过程详解
- 比较SQL Server与Oracle、DB2
- PostgreSQL教程(八):索引详解
- Oracle外键不加索引引起死锁示例
- oracle 索引的相关介绍(创建、简介、技巧、怎样查看) .
- 用SQL建立索引的方法步骤
- SQL效率提升之一些SQL编写建议并有效利用索引
- SQLSERVER的非聚集索引结构深度理解
- SQL Server误区30日谈 第8天 有关对索引进行在线操作的误区
- SQL Server 索引介绍
- SQL Server自动更新统计信息的基本算法