去除序列修改限制

This commit is contained in:
yelingzhi
2023-11-01 03:27:51 +00:00
parent 81a0d1055e
commit 826dda207e
8 changed files with 103 additions and 39 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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
-------------------------------------------------------------

View File

@ -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

View File

@ -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

View File

@ -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;