You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IBM Informix插入时查询异行报245、144错误,疑似Bug?

生产环境Informix死锁问题排查与疑问

问题现象

生产环境中出现死锁相关错误:当某事务向decisions表插入一行(该行foo = "CCCC")时,查询该表中完全不同的行(查询语句为select * from decisions where bar = 3 and foo = "CCCC";)会触发锁错误,且查询会先返回目标行再报错。

报错信息如下:

245: Could not position within a file via an index.

144: ISAM error: key value locked
Error in line 1
Near character position 70

注:bar为decisions表主键,foo为关联options表的外键。

环境与复现情况

  • 数据库版本:Informix 12.10
  • 事务隔离级别:可重复读
  • 表锁模式:涉事options和decisions表均配置为行锁模式
  • 复现情况:生产库及新建测试库中均能稳定复现该问题

不同查询语句的执行表现

  • 无报错的查询:
    • select * from decisions where bar = 3;
    • select * from decisions where bar = 3 and foo = "CCCC" order by ber;(ber为decisions表中非索引字段)
  • 触发报错的查询:
    • select * from decisions where bar = 3 and foo = "CCCC";

生产环境已通过添加非索引字段排序的方式临时解决该问题。

查询执行计划分析

通过执行set explain on;分析查询计划,发现:

  • select * from decisions where foo = "CCCC" and bar = "QWE" order by foo;:使用foo字段的外键索引
  • select * from decisions where foo = "CCCC" and bar = "QWE" order by ber;:使用bar字段的主键索引

疑问

为何仅部分查询会触发锁错误?怀疑该问题与主键、外键自动创建的索引机制有关,是否属于Informix的已知Bug?

表结构与测试数据

表结构

create table options (
        foo     char(4)                 not null,
        fee     int                     not null)
        extent size 16 next size 16
        lock mode row;

alter table options add constraint (
        primary key (foo)
                constraint cons1 );

create table decisions (
        bar     char(3)                 not null,
        foo     char(4)                 not null,
        ber     int                     not null)
        extent size 131072 next size 65536
        lock mode row;

alter table decisions add constraint (
        primary key (bar)
                constraint cons2 );

alter table decisions add constraint (
        foreign key (foo) references options(foo)
                constraint cons3 );

测试数据

options表数据

AAAA|0|
BBBB|0|
CCCC|1|
DDDD|4|
EEEE|1|
FFFF|8|

decisions表数据

QWE|AAAA|0|
WER|AAAA|9|
ERT|CCCC|2|
RTY|AAAA|32|
TYU|CCCC|1234|
YUI|CCCC|42398|
UIO|AAAA|23178|
IOP|CCCC|1233|
OPA|CCCC|11|
PAS|AAAA|890|
ASD|AAAA|90|
SDF|CCCC|2|
DFG|AAAA|4|
FGH|CCCC|7|

内容的提问来源于stack exchange,提问作者aaaaalz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 23:22:15