GBase 8a
运维管理
文章

Out of range value for column[0] 原因和解决办法

发表于2026-05-07 12:07:0520次浏览5个评论

一、原因

此类原因为自增主键的值超过了主键列int类型的最大值2147483647,导致进行insert或load时候报错,具体报错如下:

  1. insert报错详情:

  2. load报错详情:

二、复现和分析

  1. 按照下面代码新建表并生成测试数据,使表中数据接近2147483647行
CREATE TABLE "t1" (
  "id" int(4) NOT NULL AUTO_INCREMENT,
  "name" varchar(100) DEFAULT NULL,
  PRIMARY KEY ("id")
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' ;

insert into  t1(name) values ('A');
insert into  t1(name) values ('B');
insert into  t1(name) values ('C');
insert into  t1(name) values ('D');
insert into  t1(name) values ('E');

insert into t1(name) select name from t1;
...
...
insert into t1(name) select name from t1;
  1. 导出1千万行数据,并进行load或者再次insert即会报错
select name from t1 limit 10000000 into outfile '/tmp/t1.txt'  fields terminated by '|'  WRITEMODE BY overwrites ; 
load data infile 'file:///tmp/t1.txt' into table t1 data_format 3  fields terminated by '|' table_fields 'name'; max_bad_records 0;

  1. 再gn节点登录,执行查询,可以看到准确的下一个自增列键值,gc节点的显示不准确。任意一个gn节点的自增主键键值超过2147483647即会报错
select TABLE_SCHEMA,TABLE_NAME,TABLE_ROWS,AUTO_INCREMENT,from information_schema.tables where table_name='t1_n1' and table_schema='testdb'  ;

三、解决办法

  1. 注意上述问题对表进行delete并不能使自增主键的键值变小(往往就是因为一直delete表导致此类问题),如果表中数据不要了,可以直接进行truncate,会使自增主键键值归0,或者执行一下脚本收缩表(收缩表会导致原来行主键值发生变化)。
set gcluster_shrink_to_rebalance=1;
alter table t1 shrink space full;
  1. 将自增主键的字段类型由int更改为bigint。
CREATE TABLE "t1" (
  "id" bigint NOT NULL AUTO_INCREMENT,
  "name" varchar(100) DEFAULT NULL,
  PRIMARY KEY ("id")
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' ;

评论

登录后才可以发表评论
用户头像
山佳发表于 2个月前
111
用户头像
GBase用户28017发表于 2个月前
透彻。
用户头像
山佳发表于 2个月前
来了
青菇凉发表于 2个月前
来了
GBase用户51848发表于 2个月前
三人行必有我师