From 0f4e2bcb4157a287f36ce29e83e8de31615ef1d8 Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Tue, 30 Mar 2021 17:22:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BC=80=E6=94=BEALTER=20SEQUENCE=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BF=AE=E6=94=B9cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../optimizer/commands/sequence.cpp | 3 +- .../regress/input/sequence_cache_test.source | 21 ++++++ .../regress/output/sequence_cache_test.source | 74 +++++++++++++++++++ src/test/regress/parallel_schedule0 | 1 + 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/test/regress/input/sequence_cache_test.source create mode 100644 src/test/regress/output/sequence_cache_test.source 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 From c58481a663f950fc4fb42a0d9240e7fb645964cd Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Wed, 31 Mar 2021 10:57:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/regress/input/sequence_cache_test.source | 3 +++ src/test/regress/output/sequence_cache_test.source | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/test/regress/input/sequence_cache_test.source b/src/test/regress/input/sequence_cache_test.source index 5b51ad3bf..d3f9985ab 100644 --- a/src/test/regress/input/sequence_cache_test.source +++ b/src/test/regress/input/sequence_cache_test.source @@ -16,6 +16,9 @@ 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('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;" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "Alter sequence test_seq cache 3;" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "insert into test_tab(name) values('test9');" +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "select last_value from test_seq;" 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 index 0b1fcdd31..f9345b409 100644 --- a/src/test/regress/output/sequence_cache_test.source +++ b/src/test/regress/output/sequence_cache_test.source @@ -69,6 +69,16 @@ INSERT 0 1 7 | test7 (5 rows) +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "Alter sequence test_seq cache 3;" +ALTER SEQUENCE +\! @abs_bindir@/gsql -d regression -p @portstring@ -U test_user -W openGauss@123 -c "insert into test_tab(name) values('test9');" +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 +------------ + 11 +(1 row) + drop user test_user cascade; drop table if exists test_tab; drop sequence if exists test_seq; From b543a18192ee64fca0e2eef5253658c677aae7bf Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Wed, 21 Apr 2021 15:52:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E5=B8=83?= =?UTF-8?q?=E5=BC=8F=E9=9A=94=E7=A6=BB=E4=BF=AE=E6=94=B9cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/optimizer/commands/sequence.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gausskernel/optimizer/commands/sequence.cpp b/src/gausskernel/optimizer/commands/sequence.cpp index 324954119..a8ceb01fe 100644 --- a/src/gausskernel/optimizer/commands/sequence.cpp +++ b/src/gausskernel/optimizer/commands/sequence.cpp @@ -1990,8 +1990,12 @@ 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 && - strcmp(defel->defname, "cache") != 0) { + if (strcmp(defel->defname, "owned_by") != 0 && strcmp(defel->defname, "maxvalue") != 0 +#ifndef ENABLE_MULTIPLE_NODES + && strcmp(defel->defname, "cache") != 0) { +#else + ) { +#endif ereport( ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("ALTER SEQUENCE is not yet supported."))); }