From 826dda207eb3777e45668aab35890ef6d5cf56c1 Mon Sep 17 00:00:00 2001 From: yelingzhi Date: Wed, 1 Nov 2023 03:27:51 +0000 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=BA=8F=E5=88=97=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../optimizer/commands/sequence/sequence.cpp | 16 ------ .../regress/expected/alter_sequence_001.out | 49 +++++++++++++++++++ src/test/regress/expected/large_sequence.out | 3 -- .../regress/expected/single_node_sequence.out | 24 +++++---- .../regress/expected/xc_returning_step2.out | 13 +++-- src/test/regress/parallel_schedule0 | 2 +- src/test/regress/parallel_schedule0B | 2 +- src/test/regress/sql/alter_sequence_001.sql | 33 +++++++++++++ 8 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 src/test/regress/expected/alter_sequence_001.out create mode 100644 src/test/regress/sql/alter_sequence_001.sql diff --git a/src/gausskernel/optimizer/commands/sequence/sequence.cpp b/src/gausskernel/optimizer/commands/sequence/sequence.cpp index 8dd21db7c..127dc69fe 100644 --- a/src/gausskernel/optimizer/commands/sequence/sequence.cpp +++ b/src/gausskernel/optimizer/commands/sequence/sequence.cpp @@ -2102,22 +2102,6 @@ static void PreProcessSequenceOptions( foreach (option, options) { DefElem* defel = (DefElem*)lfirst(option); - /* Now we only support ALTER SEQUENCE OWNED BY and MAXVALUE to support upgrade. */ - if (!isInit) { - /* isInit is true for DefineSequence, false for AlterSequence, we use it - * to differentiate them - */ - bool isDefOwnedAndMaxValue = - strcmp(defel->defname, "owned_by") != 0 && strcmp(defel->defname, "maxvalue") != 0; -#ifndef ENABLE_MULTIPLE_NODES - isDefOwnedAndMaxValue = isDefOwnedAndMaxValue && strcmp(defel->defname, "cache") != 0; -#endif - if (isDefOwnedAndMaxValue) { - ereport( - ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("ALTER SEQUENCE is not yet supported."))); - } - } - if (strcmp(defel->defname, "increment") == 0) { CheckDuplicateDef(elms[DEF_IDX_INCREMENT_BY]); elms[DEF_IDX_INCREMENT_BY] = defel; diff --git a/src/test/regress/expected/alter_sequence_001.out b/src/test/regress/expected/alter_sequence_001.out new file mode 100644 index 000000000..4a9c09042 --- /dev/null +++ b/src/test/regress/expected/alter_sequence_001.out @@ -0,0 +1,49 @@ +DROP SCHEMA IF EXISTS test_alter_seq_sche_01 CASCADE; +NOTICE: schema "test_alter_seq_sche_01" does not exist, skipping +CREATE SCHEMA test_alter_seq_sche_01; +SET CURRENT_SCHEMA TO test_alter_seq_sche_01; +create sequence seqa; +select nextval('seqa'); + nextval +--------- + 1 +(1 row) + +alter sequence seqa increment 10; +select nextval('seqa'); + nextval +--------- + 11 +(1 row) + +select nextval('seqa'); + nextval +--------- + 21 +(1 row) + +alter sequence seqa restart 200; +select nextval('seqa'); + nextval +--------- + 200 +(1 row) + +select nextval('seqa'); + nextval +--------- + 210 +(1 row) + +alter sequence seqa cycle; +alter sequence seqa start 10; +alter sequence seqa maxvalue 1000; +alter sequence seqa minvalue 5; +select sequence_name , last_value , start_value , increment_by , max_value , min_value , cache_value , is_cycled , is_called from seqa; + sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | is_cycled | is_called +---------------+------------+-------------+--------------+-----------+-----------+-------------+-----------+----------- + seqa | 210 | 10 | 10 | 1000 | 5 | 1 | t | t +(1 row) + +DROP SCHEMA test_alter_seq_sche_01 CASCADE; +NOTICE: drop cascades to sequence seqa diff --git a/src/test/regress/expected/large_sequence.out b/src/test/regress/expected/large_sequence.out index e7a389f03..835fac0b6 100644 --- a/src/test/regress/expected/large_sequence.out +++ b/src/test/regress/expected/large_sequence.out @@ -443,11 +443,8 @@ SELECT * FROM nextval('foo'); ALTER LARGE SEQUENCE IF EXISTS foo NOMAXVALUE; -- alter other attributes are not supported ALTER LARGE SEQUENCE IF EXISTS foo MINVALUE 1; -ERROR: ALTER SEQUENCE is not yet supported. ALTER LARGE SEQUENCE IF EXISTS foo NO CYCLE; -ERROR: ALTER SEQUENCE is not yet supported. ALTER LARGE SEQUENCE IF EXISTS foo START 1; -ERROR: ALTER SEQUENCE is not yet supported. ALTER LARGE SEQUENCE IF EXISTS foo CACHE 100; -- test for largeserial CREATE TABLE serialTest (f1 text, f2 largeserial); diff --git a/src/test/regress/expected/single_node_sequence.out b/src/test/regress/expected/single_node_sequence.out index 9363715b0..94ab62332 100644 --- a/src/test/regress/expected/single_node_sequence.out +++ b/src/test/regress/expected/single_node_sequence.out @@ -259,23 +259,22 @@ SELECT nextval('sequence_test2'); ALTER SEQUENCE sequence_test2 RESTART WITH 24 INCREMENT BY 4 MAXVALUE 36 MINVALUE 5 CYCLE; -ERROR: ALTER SEQUENCE is not yet supported. SELECT nextval('sequence_test2'); nextval --------- - 33 + 24 (1 row) SELECT nextval('sequence_test2'); nextval --------- - 34 + 28 (1 row) SELECT nextval('sequence_test2'); nextval --------- - 35 + 32 (1 row) SELECT nextval('sequence_test2'); @@ -287,27 +286,26 @@ SELECT nextval('sequence_test2'); SELECT nextval('sequence_test2'); nextval --------- - 37 + 5 (1 row) ALTER SEQUENCE sequence_test2 RESTART; -ERROR: ALTER SEQUENCE is not yet supported. SELECT nextval('sequence_test2'); nextval --------- - 38 + 32 (1 row) SELECT nextval('sequence_test2'); nextval --------- - 39 + 36 (1 row) SELECT nextval('sequence_test2'); nextval --------- - 40 + 5 (1 row) -- Information schema @@ -317,7 +315,7 @@ SELECT * FROM information_schema.sequences WHERE sequence_name IN ORDER BY sequence_name ASC; sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option ------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+-------------- - regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 1 | 9223372036854775807 | 1 | NO + regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 5 | 36 | 4 | YES regression | public | serialtest2_f2_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO regression | public | serialtest2_f3_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO regression | public | serialtest2_f4_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO @@ -396,9 +394,9 @@ SELECT * FROM information_schema.sequences WHERE sequence_name IN ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq', 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq') ORDER BY sequence_name ASC; - sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option -------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+-------------- - regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 1 | 9223372036854775807 | 1 | NO + sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option +------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------+-----------+-------------- + regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 5 | 36 | 4 | YES (1 row) -- test case sensitivity of index names diff --git a/src/test/regress/expected/xc_returning_step2.out b/src/test/regress/expected/xc_returning_step2.out index 88f7d033a..a50c3f634 100644 --- a/src/test/regress/expected/xc_returning_step2.out +++ b/src/test/regress/expected/xc_returning_step2.out @@ -157,7 +157,6 @@ select * from t order by 1; truncate table products; alter sequence products_product_id_seq restart with 1; -ERROR: ALTER SEQUENCE is not yet supported. ------------------------------------------------------------- -- functions in returning ------------------------------------------------------------- @@ -338,11 +337,13 @@ update products set price = price + 1.0 WHERE product_id = ANY('{1,4,5}'::int[]) select * from t order by 1; product_id | ?column? ------------+---------- -(0 rows) + 1 | t + 4 | t + 5 | t +(3 rows) truncate table products; alter sequence products_product_id_seq restart with 1; -ERROR: ALTER SEQUENCE is not yet supported. ------------------------------------------------------------- -- functions in returning ------------------------------------------------------------- @@ -557,11 +558,13 @@ DELETE FROM products WHERE product_id = ANY('{1,4,5}'::int[]) returning product_ select * from t order by 1; product_id | ?column? ------------+---------- -(0 rows) + 1 | t + 4 | t + 5 | t +(3 rows) truncate table products; alter sequence products_product_id_seq restart with 1; -ERROR: ALTER SEQUENCE is not yet supported. ------------------------------------------------------------- -- functions in returning ------------------------------------------------------------- diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index a4b809550..a8d4bc37f 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -1059,7 +1059,7 @@ test: sytcomp_del_upt4orderby test: aioptimizer test: aioptimizer_small test: pgfincore -test: rename_table test_plsql_core +test: rename_table test_plsql_core alter_sequence_001 # debug instrument test: test_debug5 diff --git a/src/test/regress/parallel_schedule0B b/src/test/regress/parallel_schedule0B index ca26dd1ef..8664c5d0d 100644 --- a/src/test/regress/parallel_schedule0B +++ b/src/test/regress/parallel_schedule0B @@ -214,7 +214,7 @@ test: vec_delete_part1 vec_delete_part2 test: vec_set_func test: hw_cursor_rollback hw_cursor_rollback_ustore -test: alter_schema_db_rename_seq +test: alter_schema_db_rename_seq alter_sequence_001 test: a_outerjoin_conversion diff --git a/src/test/regress/sql/alter_sequence_001.sql b/src/test/regress/sql/alter_sequence_001.sql new file mode 100644 index 000000000..5992fcaa6 --- /dev/null +++ b/src/test/regress/sql/alter_sequence_001.sql @@ -0,0 +1,33 @@ +DROP SCHEMA IF EXISTS test_alter_seq_sche_01 CASCADE; + +CREATE SCHEMA test_alter_seq_sche_01; + +SET CURRENT_SCHEMA TO test_alter_seq_sche_01; + +create sequence seqa; + +select nextval('seqa'); + +alter sequence seqa increment 10; + +select nextval('seqa'); + +select nextval('seqa'); + +alter sequence seqa restart 200; + +select nextval('seqa'); + +select nextval('seqa'); + +alter sequence seqa cycle; + +alter sequence seqa start 10; + +alter sequence seqa maxvalue 1000; + +alter sequence seqa minvalue 5; + +select sequence_name , last_value , start_value , increment_by , max_value , min_value , cache_value , is_cycled , is_called from seqa; + +DROP SCHEMA test_alter_seq_sche_01 CASCADE;