已关闭
[Bug]: 【GENERATED AS IDENTITY] B 库 nocycle 达 maxvalue 后静默复用,插入重复值不报错 #8453
cloudsbreak创建于  20 天前关闭于  2 天前
cloudsbreak
cloudsbreak成员
20 天前 创建

测试类型

SQL功能

测试版本

7.0.0LTS

问题描述

B 模式库中,GENERATED AS IDENTITY 列设置 nocycle 后达到 maxvalue 时,应报错但静默复用 maxvalue 继续插入,导致重复值。
PostgreSQL 17.4 实测:达 maxvalue 后报 nextval: reached maximum value of sequence。
openGauss B 库实测:达 maxvalue 后静默成功,插入重复值不报错。

操作系统和硬件信息

数据库版本: openGauss 7.0.0-LTS

测试环境

企业版单机

被测功能

GENERATED AS IDENTITY

预置条件

操作步骤

-- 需在 B 模式库执行
DROP TABLE IF EXISTS t_identity_nocycle CASCADE;
CREATE TABLE t_identity_nocycle(a int GENERATED ALWAYS AS IDENTITY (MAXVALUE 3 MINVALUE 1), b int);
ALTER TABLE t_identity_nocycle ALTER COLUMN a SET CYCLE;
ALTER TABLE t_identity_nocycle ALTER COLUMN a SET NOCYCLE;
INSERT INTO t_identity_nocycle(b) VALUES(1); -- a=1
INSERT INTO t_identity_nocycle(b) VALUES(1); -- a=2
INSERT INTO t_identity_nocycle(b) VALUES(1); -- a=3
INSERT INTO t_identity_nocycle(b) VALUES(1); -- 第 4 次插入
SELECT a FROM t_identity_nocycle ORDER BY a;

预期输出

第 4 次插入报错 nextval: reached maximum value of sequence (3)
-- PostgreSQL 17.4 实测(语法差异,PG 用 NO CYCLE 而非 NOCYCLE)
CREATE TABLE t_identity_nocycle(a int GENERATED ALWAYS AS IDENTITY (MAXVALUE 3 MINVALUE 1 NO CYCLE), b int);
INSERT INTO t_identity_nocycle(b) VALUES(1); -- a=1
INSERT INTO t_identity_nocycle(b) VALUES(1); -- a=2
INSERT INTO t_identity_nocycle(b) VALUES(1); -- a=3
INSERT INTO t_identity_nocycle(b) VALUES(1); -- 第 4 次插入
-- ERROR: nextval: reached maximum value of sequence "t_identity_nocycle_a_seq" (3)

实际输出

第 4 次插入成功,a=3(重复),查询结果 1,2,3,3

日志信息

第 4 次插入成功,a=3(重复),查询结果 1,2,3,3

提单组织

联合伙伴

测试代码

likedislike
cloudsbreakcloudsbreak成员
20 天前 添加了label:bug
opengauss_bot
opengauss_bot成员
20 天前 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
20 天前 将 TestManager 设为负责人
opengauss_bot
opengauss_bot成员
20 天前 评论:

Welcome To openGauss Community

Hey @cloudsbreak , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @libiao2024, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .

likedislike
opengauss_botopengauss_bot成员
20 天前 添加了label:sig/SQLEngine
sungang14sungang14成员
14 天前 issue优先级由 无优先级 改变为 次要
sungang14sungang14成员
14 天前 关联了看板:openGauss 7.0.0-LTS
XXXCAXXXCA
8 天前 关联了pull request:fix GENERATED AS IDENTITY in B mode
ywzq1161327784ywzq1161327784成员
7 天前 issue状态由 待办的 改变为 待回归
cloudsbreak
cloudsbreak成员
2 天前 评论:

image.png

likedislike
cloudsbreakcloudsbreak成员
2 天前 issue状态由 待回归 改变为 已验收
cloudsbreakcloudsbreak成员
2 天前 关闭了 issue