diff --git a/src/gausskernel/optimizer/commands/sequence.cpp b/src/gausskernel/optimizer/commands/sequence.cpp index 92f394809..324954119 100644 --- a/src/gausskernel/optimizer/commands/sequence.cpp +++ b/src/gausskernel/optimizer/commands/sequence.cpp @@ -1990,7 +1990,8 @@ static void check_value_min_max(int64 value, int64 min_value, int64 max_value) /* isInit is true for DefineSequence, false for AlterSequence, we use it * to differentiate them */ - if (strcmp(defel->defname, "owned_by") != 0 && strcmp(defel->defname, "maxvalue") != 0) { + if (strcmp(defel->defname, "owned_by") != 0 && strcmp(defel->defname, "maxvalue") != 0 && + strcmp(defel->defname, "cache") != 0) { ereport( ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("ALTER SEQUENCE is not yet supported."))); } diff --git a/src/test/regress/input/sequence_cache_test.source b/src/test/regress/input/sequence_cache_test.source new file mode 100644 index 000000000..5b51ad3bf --- /dev/null +++ b/src/test/regress/input/sequence_cache_test.source @@ -0,0 +1,21 @@ +drop table if exists test_tab; +drop sequence if exists test_seq; +create sequence test_seq cache 2; +create table test_tab(id int default nextVal('test_seq'), name varchar(20)); +create user test_user with password 'openGauss@123'; +grant all privileges to test_user; +select last_value from test_seq; +insert into test_tab(name) values('test1'); +select last_value from test_seq; +insert into test_tab(name) values('test2'),('test3'); +select * from test_tab; +select last_value from test_seq; +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "insert into test_tab(name) values('test5');" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select last_value from test_seq;" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select * from test_tab;" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "insert into test_tab(name) values('test7');" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select last_value from test_seq;" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select * from test_tab;" +drop user test_user cascade; +drop table if exists test_tab; +drop sequence if exists test_seq; \ No newline at end of file diff --git a/src/test/regress/output/sequence_cache_test.source b/src/test/regress/output/sequence_cache_test.source new file mode 100644 index 000000000..0b1fcdd31 --- /dev/null +++ b/src/test/regress/output/sequence_cache_test.source @@ -0,0 +1,74 @@ +drop table if exists test_tab; +NOTICE: table "test_tab" does not exist, skipping +drop sequence if exists test_seq; +NOTICE: sequence "test_seq" does not exist, skipping +create sequence test_seq cache 2; +create table test_tab(id int default nextVal('test_seq'), name varchar(20)); +create user test_user with password 'openGauss@123'; +grant all privileges to test_user; +select last_value from test_seq; + last_value +------------ + 1 +(1 row) + +insert into test_tab(name) values('test1'); +select last_value from test_seq; + last_value +------------ + 2 +(1 row) + +insert into test_tab(name) values('test2'),('test3'); +select * from test_tab; + id | name +----+------- + 1 | test1 + 2 | test2 + 3 | test3 +(3 rows) + +select last_value from test_seq; + last_value +------------ + 4 +(1 row) + +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "insert into test_tab(name) values('test5');" +INSERT 0 1 +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select last_value from test_seq;" + last_value +------------ + 6 +(1 row) + +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select * from test_tab;" + id | name +----+------- + 1 | test1 + 2 | test2 + 3 | test3 + 5 | test5 +(4 rows) + +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "insert into test_tab(name) values('test7');" +INSERT 0 1 +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select last_value from test_seq;" + last_value +------------ + 8 +(1 row) + +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select * from test_tab;" + id | name +----+------- + 1 | test1 + 2 | test2 + 3 | test3 + 5 | test5 + 7 | test7 +(5 rows) + +drop user test_user cascade; +drop table if exists test_tab; +drop sequence if exists test_seq; diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index dce0e132a..8d596d320 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -760,3 +760,4 @@ test: leaky_function_operator #test: gs_guc test: smp +test: sequence_cache_test \ No newline at end of file