已合并
#702 支持全局sequence cache #8647
#702 支持全局sequence cache #8647
已合并
sunquancheng创建于 2025年11月28日
共 85 个文件变更+10464-398
@@ -585,9 +585,9 @@ select object_definition(object_id('students','u '));
585(1 row)585(1 row)
586 586 
587select object_definition(object_id('sys.objects'));587select object_definition(object_id('sys.objects'));
588- object_definition 588+ object_definition
589--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------589+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
590- ((((((SELECT t.name, t.object_id, t.principal_id, t.schema_id, t.parent_object_id, t.type, t.type_desc, t.create_date, t.modify_date, t.is_ms_shipped, t.is_published, t.is_schema_published FROM tables t UNION ALL SELECT c.relname AS name, c.oid AS object_id, CASE s.nspowner WHEN c.relowner THEN NULL::oid ELSE c.relowner END AS principal_id, s.oid AS schema_id, (0)::oid AS parent_object_id, 'SO'::character(2) AS type, 'SEQUENCE_OBJECT'::nvarchar2(60) AS type_desc, (o.ctime)::timestamp without time zone AS create_date, (o.mtime)::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM ((pg_class c JOIN pg_namespace s ON ((s.oid = c.relnamespace))) JOIN pg_object o ON ((o.object_oid = c.oid))) WHERE (((c.relkind = ANY (ARRAY['S'::"char", 'L'::"char"])) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name]))) AND has_table_privilege(c.oid, 'SELECT'::text))) UNION ALL SELECT v.name, v.object_id, v.principal_id, v.schema_id, v.parent_object_id, v.type, v.type_desc, v.create_date, v.modify_date, v.is_ms_shipped, v.is_published, v.is_schema_published FROM views v) UNION ALL SELECT p.name, p.object_id, p.principal_id, p.schema_id, p.parent_object_id, p.type, p.type_desc, p.create_date, p.modify_date, p.is_ms_shipped, p.is_published, p.is_schema_published FROM procedures p) UNION ALL SELECT con.conname AS name, con.oid AS object_id, NULL::oid AS principal_id, con.connamespace AS schema_id, con.conrelid AS parent_object_id, (CASE con.contype WHEN 'c'::"char" THEN 'C'::text WHEN 'p'::"char" THEN 'PK'::text WHEN 'u'::"char" THEN 'UQ'::text WHEN 'f'::"char" THEN 'F'::text ELSE NULL::text END)::character(2) AS type, (CASE con.contype WHEN 'c'::"char" THEN 'CHECK_CONSTRAINT'::text WHEN 'p'::"char" THEN 'PRIMARY_KEY_CONSTRAINT'::text WHEN 'u'::"char" THEN 'UNIQUE_CONSTRAINT'::text WHEN 'f'::"char" THEN 'FOREIGN_KEY_CONSTRAINT'::text ELSE NULL::text END)::nvarchar2(60) AS type_desc, NULL::timestamp without time zone AS create_date, NULL::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM ((pg_constraint con JOIN pg_class c ON ((c.oid = con.conrelid))) JOIN pg_namespace s ON ((s.oid = con.connamespace))) WHERE (((con.contype = ANY (ARRAY['c'::"char", 'p'::"char", 'u'::"char", 'f'::"char"])) AND has_table_privilege(c.oid, 'SELECT'::text)) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name])))) UNION ALL SELECT tg.tgname AS name, tg.oid AS object_id, NULL::oid AS principal_id, c.relnamespace AS schema_id, tg.tgrelid AS parent_object_id, 'TR'::character(2) AS type, 'SQL DML trigger'::nvarchar2(60) AS type_desc, (o.ctime)::timestamp without time zone AS create_date, (o.mtime)::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM (((pg_trigger tg JOIN pg_class c ON ((c.oid = tg.tgrelid))) JOIN pg_namespace s ON ((s.oid = c.relnamespace))) JOIN pg_object o ON ((o.object_oid = tg.oid))) WHERE (has_table_privilege(c.oid, 'SELECT'::text) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name])))) UNION ALL SELECT NULL::name AS name, ad.oid AS object_id, NULL::oid AS principal_id, c.relnamespace AS schema_id, ad.adrelid AS parent_object_id, 'D'::character(2) AS type, 'DEFAULT'::nvarchar2(60) AS type_desc, (o.ctime)::timestamp without time zone AS create_date, (o.mtime)::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM (((pg_attrdef ad JOIN pg_class c ON ((c.oid = ad.adrelid))) JOIN pg_namespace s ON ((s.oid = c.relnamespace))) JOIN pg_object o ON ((o.object_oid = ad.adrelid))) WHERE (has_table_privilege(c.oid, 'SELECT'::text) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name])))) UNION ALL SELECT syn.synname AS name, syn.oid AS object_id, CASE s.nspowner WHEN syn.synowner THEN NULL::oid ELSE syn.synowner END AS principal_id, syn.synnamespace AS schema_id, (0)::oid AS parent_object_id, 'SN'::character(2) AS type, 'Synonym'::nvarchar2(60) AS type_desc, NULL::timestamp without time zone AS create_date, NULL::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM (pg_synonym syn JOIN pg_namespace s ON ((s.oid = syn.synnamespace))) WHERE (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name]));590+ ((((((SELECT t.name, t.object_id, t.principal_id, t.schema_id, t.parent_object_id, t.type, t.type_desc, t.create_date, t.modify_date, t.is_ms_shipped, t.is_published, t.is_schema_published FROM tables t UNION ALL SELECT c.relname AS name, c.oid AS object_id, CASE s.nspowner WHEN c.relowner THEN NULL::oid ELSE c.relowner END AS principal_id, s.oid AS schema_id, (0)::oid AS parent_object_id, 'SO'::character(2) AS type, 'SEQUENCE_OBJECT'::nvarchar2(60) AS type_desc, (o.ctime)::timestamp without time zone AS create_date, (o.mtime)::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM ((pg_class c JOIN pg_namespace s ON ((s.oid = c.relnamespace))) JOIN pg_object o ON ((o.object_oid = c.oid))) WHERE (((c.relkind = ANY (ARRAY['S'::"char", 'L'::"char", 'z'::"char", 'Z'::"char"])) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name]))) AND has_table_privilege(c.oid, 'SELECT'::text))) UNION ALL SELECT v.name, v.object_id, v.principal_id, v.schema_id, v.parent_object_id, v.type, v.type_desc, v.create_date, v.modify_date, v.is_ms_shipped, v.is_published, v.is_schema_published FROM views v) UNION ALL SELECT p.name, p.object_id, p.principal_id, p.schema_id, p.parent_object_id, p.type, p.type_desc, p.create_date, p.modify_date, p.is_ms_shipped, p.is_published, p.is_schema_published FROM procedures p) UNION ALL SELECT con.conname AS name, con.oid AS object_id, NULL::oid AS principal_id, con.connamespace AS schema_id, con.conrelid AS parent_object_id, (CASE con.contype WHEN 'c'::"char" THEN 'C'::text WHEN 'p'::"char" THEN 'PK'::text WHEN 'u'::"char" THEN 'UQ'::text WHEN 'f'::"char" THEN 'F'::text ELSE NULL::text END)::character(2) AS type, (CASE con.contype WHEN 'c'::"char" THEN 'CHECK_CONSTRAINT'::text WHEN 'p'::"char" THEN 'PRIMARY_KEY_CONSTRAINT'::text WHEN 'u'::"char" THEN 'UNIQUE_CONSTRAINT'::text WHEN 'f'::"char" THEN 'FOREIGN_KEY_CONSTRAINT'::text ELSE NULL::text END)::nvarchar2(60) AS type_desc, NULL::timestamp without time zone AS create_date, NULL::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM ((pg_constraint con JOIN pg_class c ON ((c.oid = con.conrelid))) JOIN pg_namespace s ON ((s.oid = con.connamespace))) WHERE (((con.contype = ANY (ARRAY['c'::"char", 'p'::"char", 'u'::"char", 'f'::"char"])) AND has_table_privilege(c.oid, 'SELECT'::text)) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name])))) UNION ALL SELECT tg.tgname AS name, tg.oid AS object_id, NULL::oid AS principal_id, c.relnamespace AS schema_id, tg.tgrelid AS parent_object_id, 'TR'::character(2) AS type, 'SQL DML trigger'::nvarchar2(60) AS type_desc, (o.ctime)::timestamp without time zone AS create_date, (o.mtime)::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM (((pg_trigger tg JOIN pg_class c ON ((c.oid = tg.tgrelid))) JOIN pg_namespace s ON ((s.oid = c.relnamespace))) JOIN pg_object o ON ((o.object_oid = tg.oid))) WHERE (has_table_privilege(c.oid, 'SELECT'::text) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name])))) UNION ALL SELECT NULL::name AS name, ad.oid AS object_id, NULL::oid AS principal_id, c.relnamespace AS schema_id, ad.adrelid AS parent_object_id, 'D'::character(2) AS type, 'DEFAULT'::nvarchar2(60) AS type_desc, (o.ctime)::timestamp without time zone AS create_date, (o.mtime)::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM (((pg_attrdef ad JOIN pg_class c ON ((c.oid = ad.adrelid))) JOIN pg_namespace s ON ((s.oid = c.relnamespace))) JOIN pg_object o ON ((o.object_oid = ad.adrelid))) WHERE (has_table_privilege(c.oid, 'SELECT'::text) AND (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name])))) UNION ALL SELECT syn.synname AS name, syn.oid AS object_id, CASE s.nspowner WHEN syn.synowner THEN NULL::oid ELSE syn.synowner END AS principal_id, syn.synnamespace AS schema_id, (0)::oid AS parent_object_id, 'SN'::character(2) AS type, 'Synonym'::nvarchar2(60) AS type_desc, NULL::timestamp without time zone AS create_date, NULL::timestamp without time zone AS modify_date, (0)::bit(1) AS is_ms_shipped, (0)::bit(1) AS is_published, (0)::bit(1) AS is_schema_published FROM (pg_synonym syn JOIN pg_namespace s ON ((s.oid = syn.synnamespace))) WHERE (s.nspname <> ALL (ARRAY['information_schema'::name, 'pg_catalog'::name, 'sys'::name, 'information_schema_tsql'::name]));
591(1 row)591(1 row)
592 592 
593select object_definition(object_id('constraint_name22'));593select object_definition(object_id('constraint_name22'));
@@ -100,9 +100,9 @@ select count(*) from sys.sequences obj inner join pg_class pc on pc.oid = obj.ob
100(1 row)100(1 row)
101 101 
102select * from seq1;102select * from seq1;
103- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 103+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
104----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------104+---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------+-----------
105- seq1 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | f | 0105+ seq1 | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | f | 0 | f
106(1 row)106(1 row)
107 107 
108select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,108select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -115,9 +115,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
115 115 
116create sequence seq2 increment by 2 minvalue 10 maxvalue 30 cycle;116create sequence seq2 increment by 2 minvalue 10 maxvalue 30 cycle;
117select * from seq2;117select * from seq2;
118- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 118+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
119----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------119+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
120- seq2 | 10 | 10 | 2 | 30 | 10 | 1 | 0 | t | f | 0120+ seq2 | 10 | 10 | 2 | 30 | 10 | 1 | 0 | t | f | 0 | f
121(1 row)121(1 row)
122 122 
123select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,123select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -130,9 +130,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
130 130 
131create sequence seq3 increment by 2 cache 5;131create sequence seq3 increment by 2 cache 5;
132select * from seq3;132select * from seq3;
133- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 133+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
134----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------134+---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------+-----------
135- seq3 | 1 | 1 | 2 | 9223372036854775807 | 1 | 5 | 0 | f | f | 0135+ seq3 | 1 | 1 | 2 | 9223372036854775807 | 1 | 5 | 0 | f | f | 0 | f
136(1 row)136(1 row)
137 137 
138select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,138select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -145,9 +145,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
145 145 
146create sequence seq4 increment by 2 start with 15 minvalue 10 maxvalue 30 cycle;146create sequence seq4 increment by 2 start with 15 minvalue 10 maxvalue 30 cycle;
147select * from seq4;147select * from seq4;
148- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 148+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
149----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------149+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
150- seq4 | 15 | 15 | 2 | 30 | 10 | 1 | 0 | t | f | 0150+ seq4 | 15 | 15 | 2 | 30 | 10 | 1 | 0 | t | f | 0 | f
151(1 row)151(1 row)
152 152 
153select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,153select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -160,9 +160,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
160 160 
161create large sequence seq11;161create large sequence seq11;
162select * from seq11;162select * from seq11;
163- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 163+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
164----------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------164+---------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------+-----------
165- seq11 | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0165+ seq11 | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0 | f
166(1 row)166(1 row)
167 167 
168select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,168select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -175,9 +175,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
175 175 
176create large sequence seq22 increment by 2 minvalue 10 maxvalue 30 cycle;176create large sequence seq22 increment by 2 minvalue 10 maxvalue 30 cycle;
177select * from seq22;177select * from seq22;
178- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 178+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
179----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------179+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
180- seq22 | 10 | 10 | 2 | 30 | 10 | 1 | 0 | t | f | 0180+ seq22 | 10 | 10 | 2 | 30 | 10 | 1 | 0 | t | f | 0 | f
181(1 row)181(1 row)
182 182 
183select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,183select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -190,9 +190,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
190 190 
191create large sequence seq33 increment by 2 cache 5;191create large sequence seq33 increment by 2 cache 5;
192select * from seq33;192select * from seq33;
193- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 193+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
194----------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------194+---------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------+-----------
195- seq33 | 1 | 1 | 2 | 170141183460469231731687303715884105727 | 1 | 5 | 0 | f | f | 0195+ seq33 | 1 | 1 | 2 | 170141183460469231731687303715884105727 | 1 | 5 | 0 | f | f | 0 | f
196(1 row)196(1 row)
197 197 
198select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,198select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -205,9 +205,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
205 205 
206create large sequence seq44 increment by 2 start with 15 minvalue 10 maxvalue 30 cycle;206create large sequence seq44 increment by 2 start with 15 minvalue 10 maxvalue 30 cycle;
207select * from seq44;207select * from seq44;
208- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 208+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
209----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------209+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
210- seq44 | 15 | 15 | 2 | 30 | 10 | 1 | 0 | t | f | 0210+ seq44 | 15 | 15 | 2 | 30 | 10 | 1 | 0 | t | f | 0 | f
211(1 row)211(1 row)
212 212 
213select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,213select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -223,9 +223,9 @@ start with 12345678901234567890
223minvalue 12345678901234567890223minvalue 12345678901234567890
224maxvalue 170141183460469231731687303715884105700 cycle;224maxvalue 170141183460469231731687303715884105700 cycle;
225select * from seq55;225select * from seq55;
226- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 226+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
227----------------+----------------------+----------------------+----------------------+-----------------------------------------+----------------------+-------------+---------+-----------+-----------+------227+---------------+----------------------+----------------------+----------------------+-----------------------------------------+----------------------+-------------+---------+-----------+-----------+------+-----------
228- seq55 | 12345678901234567890 | 12345678901234567890 | 12345678901234567890 | 170141183460469231731687303715884105700 | 12345678901234567890 | 1 | 0 | t | f | 0228+ seq55 | 12345678901234567890 | 12345678901234567890 | 12345678901234567890 | 170141183460469231731687303715884105700 | 12345678901234567890 | 1 | 0 | t | f | 0 | f
229(1 row)229(1 row)
230 230 
231select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,231select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -239,9 +239,9 @@ select start_value, increment, minimum_value, maximum_value, is_cycling, is_cach
239drop sequence if exists seq4;239drop sequence if exists seq4;
240create sequence seq4 increment by 5 minvalue 10 maxvalue 20;240create sequence seq4 increment by 5 minvalue 10 maxvalue 20;
241select * from seq4;241select * from seq4;
242- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 242+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
243----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------243+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
244- seq4 | 10 | 10 | 5 | 20 | 10 | 1 | 0 | f | f | 0244+ seq4 | 10 | 10 | 5 | 20 | 10 | 1 | 0 | f | f | 0 | f
245(1 row)245(1 row)
246 246 
247select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,247select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -262,9 +262,9 @@ select nextval('seq4');
262(1 row)262(1 row)
263 263 
264select * from seq4;264select * from seq4;
265- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 265+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
266----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------266+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
267- seq4 | 10 | 10 | 5 | 20 | 10 | 1 | 2 | f | t | 0267+ seq4 | 10 | 10 | 5 | 20 | 10 | 1 | 2 | f | t | 0 | f
268(1 row)268(1 row)
269 269 
270select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq4';270select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq4';
@@ -286,9 +286,9 @@ select nextval('seq4');
286(1 row)286(1 row)
287 287 
288select * from seq4;288select * from seq4;
289- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 289+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
290----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------290+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
291- seq4 | 15 | 10 | 5 | 20 | 10 | 1 | 1 | f | t | 0291+ seq4 | 15 | 10 | 5 | 20 | 10 | 1 | 1 | f | t | 0 | f
292(1 row)292(1 row)
293 293 
294select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq4';294select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq4';
@@ -310,9 +310,9 @@ select nextval('seq4');
310(1 row)310(1 row)
311 311 
312select * from seq4;312select * from seq4;
313- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 313+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
314----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------314+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
315- seq4 | 20 | 10 | 5 | 20 | 10 | 1 | 0 | f | t | 0315+ seq4 | 20 | 10 | 5 | 20 | 10 | 1 | 0 | f | t | 0 | f
316(1 row)316(1 row)
317 317 
318select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq4';318select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq4';
@@ -340,9 +340,9 @@ drop sequence if exists seq5;
340NOTICE: sequence "seq5" does not exist, skipping340NOTICE: sequence "seq5" does not exist, skipping
341create sequence seq5 increment by 5 minvalue 10 maxvalue 20 cycle;341create sequence seq5 increment by 5 minvalue 10 maxvalue 20 cycle;
342select * from seq5;342select * from seq5;
343- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 343+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
344----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------344+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
345- seq5 | 10 | 10 | 5 | 20 | 10 | 1 | 0 | t | f | 0345+ seq5 | 10 | 10 | 5 | 20 | 10 | 1 | 0 | t | f | 0 | f
346(1 row)346(1 row)
347 347 
348select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,348select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -363,9 +363,9 @@ select nextval('seq5');
363(1 row)363(1 row)
364 364 
365select * from seq5;365select * from seq5;
366- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 366+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
367----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------367+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
368- seq5 | 10 | 10 | 5 | 20 | 10 | 1 | 2 | t | t | 0368+ seq5 | 10 | 10 | 5 | 20 | 10 | 1 | 2 | t | t | 0 | f
369(1 row)369(1 row)
370 370 
371select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';371select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';
@@ -387,9 +387,9 @@ select nextval('seq5');
387(1 row)387(1 row)
388 388 
389select * from seq5;389select * from seq5;
390- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 390+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
391----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------391+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
392- seq5 | 15 | 10 | 5 | 20 | 10 | 1 | 1 | t | t | 0392+ seq5 | 15 | 10 | 5 | 20 | 10 | 1 | 1 | t | t | 0 | f
393(1 row)393(1 row)
394 394 
395select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';395select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';
@@ -411,9 +411,9 @@ select nextval('seq5');
411(1 row)411(1 row)
412 412 
413select * from seq5;413select * from seq5;
414- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 414+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
415----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------415+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
416- seq5 | 20 | 10 | 5 | 20 | 10 | 1 | 0 | t | t | 0416+ seq5 | 20 | 10 | 5 | 20 | 10 | 1 | 0 | t | t | 0 | f
417(1 row)417(1 row)
418 418 
419select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';419select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';
@@ -435,9 +435,9 @@ select nextval('seq5');
435(1 row)435(1 row)
436 436 
437select * from seq5;437select * from seq5;
438- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 438+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
439----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------439+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
440- seq5 | 10 | 10 | 5 | 20 | 10 | 1 | 2 | t | t | 0440+ seq5 | 10 | 10 | 5 | 20 | 10 | 1 | 2 | t | t | 0 | f
441(1 row)441(1 row)
442 442 
443select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';443select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq5';
@@ -460,9 +460,9 @@ select nextval('seq5');
460 460 
461create sequence seq6 increment by 5 minvalue 4 maxvalue 5;461create sequence seq6 increment by 5 minvalue 4 maxvalue 5;
462select * from seq6;462select * from seq6;
463- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 463+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
464----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------464+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
465- seq6 | 4 | 4 | 5 | 5 | 4 | 1 | 0 | f | f | 0465+ seq6 | 4 | 4 | 5 | 5 | 4 | 1 | 0 | f | f | 0 | f
466(1 row)466(1 row)
467 467 
468select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,468select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -483,9 +483,9 @@ select nextval('seq6');
483(1 row)483(1 row)
484 484 
485select * from seq6;485select * from seq6;
486- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 486+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
487----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------487+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
488- seq6 | 4 | 4 | 5 | 5 | 4 | 1 | 0 | f | t | 0488+ seq6 | 4 | 4 | 5 | 5 | 4 | 1 | 0 | f | t | 0 | f
489(1 row)489(1 row)
490 490 
491select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq6';491select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq6';
@@ -504,9 +504,9 @@ select nextval('seq6'); -- error, exhausted
504ERROR: nextval: reached maximum value of sequence "seq6" (5)504ERROR: nextval: reached maximum value of sequence "seq6" (5)
505CONTEXT: referenced column: nextval505CONTEXT: referenced column: nextval
506select * from seq6;506select * from seq6;
507- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 507+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
508----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------508+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
509- seq6 | 4 | 4 | 5 | 5 | 4 | 1 | 0 | f | t | 0509+ seq6 | 4 | 4 | 5 | 5 | 4 | 1 | 0 | f | t | 0 | f
510(1 row)510(1 row)
511 511 
512select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq6';512select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq6';
@@ -517,9 +517,9 @@ select current_value, is_exhausted, last_used_value from sys.sequences where nam
517 517 
518create sequence seq7 increment by -2 minvalue -2 maxvalue 2;518create sequence seq7 increment by -2 minvalue -2 maxvalue 2;
519select * from seq7;519select * from seq7;
520- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 520+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
521----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------521+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
522- seq7 | 2 | 2 | -2 | 2 | -2 | 1 | 0 | f | f | 0522+ seq7 | 2 | 2 | -2 | 2 | -2 | 1 | 0 | f | f | 0 | f
523(1 row)523(1 row)
524 524 
525select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,525select start_value, increment, minimum_value, maximum_value, is_cycling, is_cached, cache_size,
@@ -540,9 +540,9 @@ select nextval('seq7');
540(1 row)540(1 row)
541 541 
542select * from seq7;542select * from seq7;
543- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 543+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
544----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------544+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
545- seq7 | 2 | 2 | -2 | 2 | -2 | 1 | 2 | f | t | 0545+ seq7 | 2 | 2 | -2 | 2 | -2 | 1 | 2 | f | t | 0 | f
546(1 row)546(1 row)
547 547 
548select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';548select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';
@@ -564,9 +564,9 @@ select nextval('seq7');
564(1 row)564(1 row)
565 565 
566select * from seq7;566select * from seq7;
567- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 567+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
568----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------568+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
569- seq7 | 0 | 2 | -2 | 2 | -2 | 1 | 1 | f | t | 0569+ seq7 | 0 | 2 | -2 | 2 | -2 | 1 | 1 | f | t | 0 | f
570(1 row)570(1 row)
571 571 
572select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';572select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';
@@ -588,9 +588,9 @@ select nextval('seq7');
588(1 row)588(1 row)
589 589 
590select * from seq7;590select * from seq7;
591- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 591+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
592----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------592+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
593- seq7 | -2 | 2 | -2 | 2 | -2 | 1 | 0 | f | t | 0593+ seq7 | -2 | 2 | -2 | 2 | -2 | 1 | 0 | f | t | 0 | f
594(1 row)594(1 row)
595 595 
596select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';596select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';
@@ -609,9 +609,9 @@ select nextval('seq7'); -- error, exhausted
609ERROR: nextval: reached minimum value of sequence "seq7" (-2)609ERROR: nextval: reached minimum value of sequence "seq7" (-2)
610CONTEXT: referenced column: nextval610CONTEXT: referenced column: nextval
611select * from seq7;611select * from seq7;
612- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 612+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
613----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------613+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
614- seq7 | -2 | 2 | -2 | 2 | -2 | 1 | 0 | f | t | 0614+ seq7 | -2 | 2 | -2 | 2 | -2 | 1 | 0 | f | t | 0 | f
615(1 row)615(1 row)
616 616 
617select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';617select current_value, is_exhausted, last_used_value from sys.sequences where name = 'seq7';
@@ -657,7 +657,8 @@ static bool get_seed(Oid seqid, int128* start, int128* res, bool* success)
657 int128 minvalue = 0;657 int128 minvalue = 0;
658 int128 cachevalue = 0;658 int128 cachevalue = 0;
659 bool cycle = false;659 bool cycle = false;
660- bool large = (get_rel_relkind(seqid) == RELKIND_LARGE_SEQUENCE);660+ char relkind = get_rel_relkind(seqid);
661+ bool large = (relkind == RELKIND_LARGE_SEQUENCE || relkind == RELKIND_LARGE_SEQUENCE_GSC);
661 662 
662 Relation relseq = relation_open(seqid, AccessShareLock);663 Relation relseq = relation_open(seqid, AccessShareLock);
663 get_sequence_params(relseq, &uuid, start, &increment, &maxvalue,664 get_sequence_params(relseq, &uuid, start, &increment, &maxvalue,
@@ -976,7 +976,7 @@ select
976from pg_class c976from pg_class c
977inner join pg_namespace s on s.oid = c.relnamespace977inner join pg_namespace s on s.oid = c.relnamespace
978inner join pg_object o on o.object_oid = c.oid978inner join pg_object o on o.object_oid = c.oid
979-where relkind in ('S', 'L')979+where relkind in ('S', 'L', 'z', 'Z')
980and has_table_privilege(quote_ident(s.nspname) ||'.'||quote_ident(c.relname), 'SELECT')980and has_table_privilege(quote_ident(s.nspname) ||'.'||quote_ident(c.relname), 'SELECT')
981union all981union all
982select982select
@@ -1128,7 +1128,7 @@ select
1128from pg_class c1128from pg_class c
1129inner join pg_namespace s on s.oid = c.relnamespace1129inner join pg_namespace s on s.oid = c.relnamespace
1130inner join pg_object o on o.object_oid = c.oid1130inner join pg_object o on o.object_oid = c.oid
1131-where relkind in ('S', 'L')1131+where relkind in ('S', 'L', 'z', 'Z')
1132and s.nspname not in ('information_schema', 'pg_catalog')1132and s.nspname not in ('information_schema', 'pg_catalog')
1133and has_table_privilege(quote_ident(s.nspname) ||'.'||quote_ident(c.relname), 'SELECT')1133and has_table_privilege(quote_ident(s.nspname) ||'.'||quote_ident(c.relname), 'SELECT')
1134union all1134union all
@@ -236,7 +236,7 @@ select
236from pg_class c236from pg_class c
237inner join pg_namespace s on s.oid = c.relnamespace237inner join pg_namespace s on s.oid = c.relnamespace
238left join pg_object o on o.object_oid = c.oid238left join pg_object o on o.object_oid = c.oid
239-where relkind in ('S', 'L')239+where relkind in ('S', 'L', 'z', 'Z')
240and has_table_privilege(c.oid, 'SELECT')240and has_table_privilege(c.oid, 'SELECT')
241union all241union all
242select242select
@@ -441,7 +441,7 @@ select
441from pg_class c441from pg_class c
442inner join pg_namespace s on s.oid = c.relnamespace442inner join pg_namespace s on s.oid = c.relnamespace
443inner join pg_object o on o.object_oid = c.oid443inner join pg_object o on o.object_oid = c.oid
444-where relkind in ('S', 'L')444+where relkind in ('S', 'L', 'z', 'Z')
445and s.nspname not in ('information_schema', 'pg_catalog', 'sys', 'information_schema_tsql')445and s.nspname not in ('information_schema', 'pg_catalog', 'sys', 'information_schema_tsql')
446and has_table_privilege(c.oid, 'SELECT')446and has_table_privilege(c.oid, 'SELECT')
447union all447union all
@@ -618,7 +618,7 @@ select
618from pg_class t618from pg_class t
619inner join pg_namespace s on s.oid = t.relnamespace619inner join pg_namespace s on s.oid = t.relnamespace
620where t.relpersistence in ('p', 'u', 't')620where t.relpersistence in ('p', 'u', 't')
621-and t.relkind in ('r', 'v', 'm', 'S')621+and t.relkind in ('r', 'v', 'm', 'S', 'L', 'z', 'Z')
622and has_table_privilege(t.oid, 'SELECT')622and has_table_privilege(t.oid, 'SELECT')
623union all623union all
624select 624select
@@ -1600,6 +1600,8 @@ SELECT
1600 CASE relkind1600 CASE relkind
1601 WHEN 'S' THEN 201601 WHEN 'S' THEN 20
1602 WHEN 'L' THEN 341602 WHEN 'L' THEN 34
1603+ WHEN 'z' THEN 20
1604+ WHEN 'Z' THEN 34
1603 ELSE -11605 ELSE -1
1604 END AS TINYINT1606 END AS TINYINT
1605 ) AS system_type_id,1607 ) AS system_type_id,
@@ -1607,6 +1609,8 @@ SELECT
1607 CASE relkind1609 CASE relkind
1608 WHEN 'S' THEN 201610 WHEN 'S' THEN 20
1609 WHEN 'L' THEN 341611 WHEN 'L' THEN 34
1612+ WHEN 'z' THEN 20
1613+ WHEN 'Z' THEN 34
1610 ELSE -11614 ELSE -1
1611 END AS INT1615 END AS INT
1612 ) AS user_type_id,1616 ) AS user_type_id,
@@ -1614,6 +1618,8 @@ SELECT
1614 CASE relkind1618 CASE relkind
1615 WHEN 'S' THEN 191619 WHEN 'S' THEN 19
1616 WHEN 'L' THEN 391620 WHEN 'L' THEN 39
1621+ WHEN 'z' THEN 19
1622+ WHEN 'Z' THEN 39
1617 ELSE -11623 ELSE -1
1618 END AS TINYINT1624 END AS TINYINT
1619 ) AS precision,1625 ) AS precision,
@@ -1642,7 +1648,7 @@ SELECT
1642FROM pg_class c1648FROM pg_class c
1643INNER JOIN pg_namespace s ON s.oid = c.relnamespace1649INNER JOIN pg_namespace s ON s.oid = c.relnamespace
1644INNER JOIN pg_object o ON o.object_oid = c.oid1650INNER JOIN pg_object o ON o.object_oid = c.oid
1645-WHERE relkind IN ('S', 'L')1651+WHERE relkind IN ('S', 'L', 'z', 'Z')
1646AND s.nspname NOT IN ('information_schema', 'pg_catalog', 'sys', 'information_schema_tsql')1652AND s.nspname NOT IN ('information_schema', 'pg_catalog', 'sys', 'information_schema_tsql')
1647AND (pg_catalog.pg_has_role(c.relowner, 'USAGE') OR pg_catalog.has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE'));1653AND (pg_catalog.pg_has_role(c.relowner, 'USAGE') OR pg_catalog.has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE'));
1648 1654 
@@ -20,6 +20,7 @@
20<synopsis>20<synopsis>
21ALTER [ LARGE ] SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> 21ALTER [ LARGE ] SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
22 [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE | NOMAXVALUE ]22 [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE | NOMAXVALUE ]
23+ [ SESSION | GLOBAL ]
23 [ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ];24 [ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ];
24ALTER [ LARGE ] SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>;25ALTER [ LARGE ] SEQUENCE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>;
25 26 
@@ -18,7 +18,7 @@
18<synopsis>18<synopsis>
19CREATE [ LARGE ] SEQUENCE [ IF NOT EXISTS ] <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]19CREATE [ LARGE ] SEQUENCE [ IF NOT EXISTS ] <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
20 [ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE | NOMINVALUE] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE | NOMAXVALUE]20 [ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE | NOMINVALUE] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE | NOMAXVALUE]
21- [ START [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE | NOCYCLE]21+ [ START [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE | NOCYCLE] [ GLOBAL | SESSION ]
22 [ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ];22 [ OWNED BY { <replaceable class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable> | NONE } ];
23 23 
24NOTICE: '[ LARGE ]' is only avaliable in CENTRALIZED mode!24NOTICE: '[ LARGE ]' is only avaliable in CENTRALIZED mode!
@@ -2469,10 +2469,12 @@ static void expand_table_name_patterns(
2469 "SELECT c.oid"2469 "SELECT c.oid"
2470 "\nFROM pg_catalog.pg_class c"2470 "\nFROM pg_catalog.pg_class c"
2471 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace"2471 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace"
2472- "\nWHERE c.relkind in ('%c', '%c', '%c', '%c', '%c','%c', '%c', '%c')\n",2472+ "\nWHERE c.relkind in ('%c', '%c', '%c', '%c', '%c','%c', '%c', '%c', '%c', '%c')\n",
2473 RELKIND_RELATION,2473 RELKIND_RELATION,
2474 RELKIND_SEQUENCE,2474 RELKIND_SEQUENCE,
2475 RELKIND_LARGE_SEQUENCE,2475 RELKIND_LARGE_SEQUENCE,
2476+ RELKIND_SEQUENCE_GSC,
2477+ RELKIND_LARGE_SEQUENCE_GSC,
2476 RELKIND_VIEW,2478 RELKIND_VIEW,
2477 RELKIND_MATVIEW,2479 RELKIND_MATVIEW,
2478 RELKIND_CONTQUERY,2480 RELKIND_CONTQUERY,
@@ -3711,8 +3713,8 @@ static void guessConstraintInheritance(TableInfo* tblinfo, int numTables)
3711 TableInfo* parent = NULL;3713 TableInfo* parent = NULL;
3712 3714 
3713 /* Sequences and views never have parents */3715 /* Sequences and views never have parents */
3714- if (tbinfo->relkind == RELKIND_SEQUENCE || tbinfo->relkind == RELKIND_VIEW || 3716+ if (RELKIND_IS_SEQUENCE(tbinfo->relkind) || tbinfo->relkind == RELKIND_VIEW ||
3715- tbinfo->relkind == RELKIND_CONTQUERY || tbinfo->relkind == RELKIND_LARGE_SEQUENCE)3717+ tbinfo->relkind == RELKIND_CONTQUERY)
3716 continue;3718 continue;
3717 3719 
3718 /* Don't bother computing anything for non-target tables, either */3720 /* Don't bother computing anything for non-target tables, either */
@@ -7514,6 +7516,8 @@ static SimpleOidList getDependObjectOid(Archive* fout, SimpleOidList* inputList)
7514 7516 
7515 case RELKIND_SEQUENCE:7517 case RELKIND_SEQUENCE:
7516 case RELKIND_LARGE_SEQUENCE:7518 case RELKIND_LARGE_SEQUENCE:
7519+ case RELKIND_SEQUENCE_GSC:
7520+ case RELKIND_LARGE_SEQUENCE_GSC:
7517 /*7521 /*
7518 1. sequence -> table/partition table7522 1. sequence -> table/partition table
7519 2. sequence -> foreign table(default values on foreign tables are not supported)7523 2. sequence -> foreign table(default values on foreign tables are not supported)
@@ -7923,7 +7927,7 @@ TableInfo* getTables(Archive* fout, int* numTables)
7923 "FROM pg_catalog.unnest(tc.reloptions) x), ', ') AS toast_reloptions "7927 "FROM pg_catalog.unnest(tc.reloptions) x), ', ') AS toast_reloptions "
7924 "FROM pg_class c "7928 "FROM pg_class c "
7925 "LEFT JOIN pg_depend d ON "7929 "LEFT JOIN pg_depend d ON "
7926- "(c.relkind in ('%c','%c') AND "7930+ "(c.relkind in ('%c','%c', '%c', '%c') AND "
7927 "d.classid = c.tableoid AND d.objid = c.oid AND "7931 "d.classid = c.tableoid AND d.objid = c.oid AND "
7928 "d.objsubid = 0 AND "7932 "d.objsubid = 0 AND "
7929 "d.refclassid = c.tableoid AND d.deptype = 'a') "7933 "d.refclassid = c.tableoid AND d.deptype = 'a') "
@@ -7931,7 +7935,9 @@ TableInfo* getTables(Archive* fout, int* numTables)
7931 "WHERE c.oid = %u "7935 "WHERE c.oid = %u "
7932 "ORDER BY c.oid",7936 "ORDER BY c.oid",
7933 RELKIND_SEQUENCE,7937 RELKIND_SEQUENCE,
7938+ RELKIND_SEQUENCE_GSC,
7934 RELKIND_LARGE_SEQUENCE,7939 RELKIND_LARGE_SEQUENCE,
7940+ RELKIND_LARGE_SEQUENCE_GSC,
7935 table_include_oids.head->val);7941 table_include_oids.head->val);
7936 } else {7942 } else {
7937 appendPQExpBuffer(query,7943 appendPQExpBuffer(query,
@@ -7980,18 +7986,22 @@ TableInfo* getTables(Archive* fout, int* numTables)
7980 "FROM pg_catalog.unnest(tc.reloptions) x), ', ') AS toast_reloptions "7986 "FROM pg_catalog.unnest(tc.reloptions) x), ', ') AS toast_reloptions "
7981 "FROM pg_class c "7987 "FROM pg_class c "
7982 "LEFT JOIN pg_depend d ON "7988 "LEFT JOIN pg_depend d ON "
7983- "(c.relkind in ('%c', '%c') AND "7989+ "(c.relkind in ('%c', '%c', '%c', '%c') AND "
7984 "d.classid = c.tableoid AND d.objid = c.oid AND "7990 "d.classid = c.tableoid AND d.objid = c.oid AND "
7985 "d.objsubid = 0 AND "7991 "d.objsubid = 0 AND "
7986 "d.refclassid = c.tableoid AND d.deptype = 'a') "7992 "d.refclassid = c.tableoid AND d.deptype = 'a') "
7987 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) "7993 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) "
7988- "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c', '%c', '%c', '%c') AND c.relnamespace != %d "7994+ "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c', '%c', '%c', '%c', '%c', '%c') AND c.relnamespace != %d "
7989 "ORDER BY c.oid",7995 "ORDER BY c.oid",
7990 RELKIND_SEQUENCE,7996 RELKIND_SEQUENCE,
7991 RELKIND_LARGE_SEQUENCE,7997 RELKIND_LARGE_SEQUENCE,
7998+ RELKIND_SEQUENCE_GSC,
7999+ RELKIND_LARGE_SEQUENCE_GSC,
7992 RELKIND_RELATION,8000 RELKIND_RELATION,
7993 RELKIND_SEQUENCE,8001 RELKIND_SEQUENCE,
7994 RELKIND_LARGE_SEQUENCE,8002 RELKIND_LARGE_SEQUENCE,
8003+ RELKIND_SEQUENCE_GSC,
8004+ RELKIND_LARGE_SEQUENCE_GSC,
7995 RELKIND_VIEW,8005 RELKIND_VIEW,
7996 RELKIND_MATVIEW,8006 RELKIND_MATVIEW,
7997 RELKIND_CONTQUERY,8007 RELKIND_CONTQUERY,
@@ -8271,13 +8281,15 @@ TableInfo* getTables(Archive* fout, int* numTables)
8271 "NULL AS reloptions, "8281 "NULL AS reloptions, "
8272 "NULL AS toast_reloptions "8282 "NULL AS toast_reloptions "
8273 "FROM pg_class c "8283 "FROM pg_class c "
8274- "WHERE relkind IN ('%c', '%c', '%c') "8284+ "WHERE relkind IN ('%c', '%c', '%c', '%c', '%c') "
8275 "ORDER BY oid",8285 "ORDER BY oid",
8276 RELKIND_VIEW,8286 RELKIND_VIEW,
8277 username_subquery,8287 username_subquery,
8278 RELKIND_RELATION,8288 RELKIND_RELATION,
8279 RELKIND_SEQUENCE,8289 RELKIND_SEQUENCE,
8280- RELKIND_LARGE_SEQUENCE);8290+ RELKIND_LARGE_SEQUENCE,
8291+ RELKIND_SEQUENCE_GSC,
8292+ RELKIND_LARGE_SEQUENCE_GSC);
8281 }8293 }
8282 8294 
8283 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);8295 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
@@ -12171,10 +12183,13 @@ static void dumpDumpableObject(Archive* fout, DumpableObject* dobj)
12171 }12183 }
12172 }12184 }
12173 12185 
12174- if (RELKIND_IS_SEQUENCE(tbinfo->relkind))12186+ if (RELKIND_IS_SEQUENCE(tbinfo->relkind)) {
12175- dumpSequenceData(fout, (TableDataInfo*)dobj, tbinfo->relkind == RELKIND_LARGE_SEQUENCE);12187+ bool isLarge =
12176- else12188+ tbinfo->relkind == RELKIND_LARGE_SEQUENCE || tbinfo->relkind == RELKIND_LARGE_SEQUENCE_GSC;
12189+ dumpSequenceData(fout, (TableDataInfo*)dobj, isLarge);
12190+ } else {
12177 dumpTableData(fout, (TableDataInfo*)dobj);12191 dumpTableData(fout, (TableDataInfo*)dobj);
12192+ }
12178 break;12193 break;
12179 }12194 }
12180 case DO_TSPARSER:12195 case DO_TSPARSER:
@@ -17754,9 +17769,11 @@ static void dumpDefaultACL(Archive* fout, DefaultACLInfo* daclinfo)
17754 type = "TABLES";17769 type = "TABLES";
17755 break;17770 break;
17756 case DEFACLOBJ_SEQUENCE:17771 case DEFACLOBJ_SEQUENCE:
17772+ case DEFACLOBJ_SEQUENCE_GSC:
17757 type = "SEQUENCES";17773 type = "SEQUENCES";
17758 break;17774 break;
17759 case DEFACLOBJ_LARGE_SEQUENCE:17775 case DEFACLOBJ_LARGE_SEQUENCE:
17776+ case DEFACLOBJ_LARGE_SEQUENCE_GSC:
17760 type = "LARGE SEQUENCES";17777 type = "LARGE SEQUENCES";
17761 break;17778 break;
17762 case DEFACLOBJ_FUNCTION:17779 case DEFACLOBJ_FUNCTION:
@@ -18254,16 +18271,18 @@ static void dumpTable(Archive* fout, TableInfo* tbinfo)
18254 if (tbinfo->dobj.dump && !dataOnly) {18271 if (tbinfo->dobj.dump && !dataOnly) {
18255 char* namecopy = NULL;18272 char* namecopy = NULL;
18256 18273 
18257- if (RELKIND_IS_SEQUENCE(tbinfo->relkind))18274+ if (RELKIND_IS_SEQUENCE(tbinfo->relkind)) {
18258- dumpSequence(fout, tbinfo, tbinfo->relkind == RELKIND_LARGE_SEQUENCE);18275+ bool isLarge = tbinfo->relkind == RELKIND_LARGE_SEQUENCE || tbinfo->relkind == RELKIND_LARGE_SEQUENCE_GSC;
18259- else18276+ dumpSequence(fout, tbinfo, isLarge);
18277+ } else {
18260 dumpTableSchema(fout, tbinfo);18278 dumpTableSchema(fout, tbinfo);
18261- 18279+ }
18262 /* Handle the ACL here */18280 /* Handle the ACL here */
18263 namecopy = gs_strdup(fmtId(tbinfo->dobj.name));18281 namecopy = gs_strdup(fmtId(tbinfo->dobj.name));
18264- const char* kind = RELKIND_IS_SEQUENCE(tbinfo->relkind) ?18282+ const char* kind =
18265- (tbinfo->relkind == RELKIND_SEQUENCE ? "SEQUENCE" : "LARGE SEQUENCE") :18283+ RELKIND_IS_SEQUENCE(tbinfo->relkind) ?
18266- "TABLE";18284+ ((tbinfo->relkind == RELKIND_SEQUENCE || tbinfo->relkind == RELKIND_SEQUENCE_GSC) ?
18285+ "SEQUENCE" : "LARGE SEQUENCE") : "TABLE";
18267 dumpACL(fout,18286 dumpACL(fout,
18268 tbinfo->dobj.catId,18287 tbinfo->dobj.catId,
18269 tbinfo->dobj.dumpId,18288 tbinfo->dobj.dumpId,
@@ -22885,8 +22904,11 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large)
22885 char bufm[100] = {0};22904 char bufm[100] = {0};
22886 char bufx[100] = {0};22905 char bufx[100] = {0};
22887 bool cycled = false;22906 bool cycled = false;
22907+ bool isGlobal = false, isNewVer = false;
22888 int nRet = 0;22908 int nRet = 0;
22889 const char* optLarge = large ? "LARGE" : "";22909 const char* optLarge = large ? "LARGE" : "";
22910+ char *isGlobalStr = " ";
22911+ 
22890 PQExpBuffer query = createPQExpBuffer();22912 PQExpBuffer query = createPQExpBuffer();
22891 PQExpBuffer delqry = createPQExpBuffer();22913 PQExpBuffer delqry = createPQExpBuffer();
22892 PQExpBuffer labelq = createPQExpBuffer();22914 PQExpBuffer labelq = createPQExpBuffer();
@@ -22903,7 +22925,10 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large)
22903 securec_check_ss_c(nRet, "\0", "\0");22925 securec_check_ss_c(nRet, "\0", "\0");
22904 nRet = snprintf_s(bufx, sizeof(bufx) / sizeof(char), sizeof(bufx) / sizeof(char) - 1, INT64_FORMAT, SEQ_MAXVALUE);22926 nRet = snprintf_s(bufx, sizeof(bufx) / sizeof(char), sizeof(bufx) / sizeof(char) - 1, INT64_FORMAT, SEQ_MAXVALUE);
22905 securec_check_ss_c(nRet, "\0", "\0");22927 securec_check_ss_c(nRet, "\0", "\0");
22906- 22928+ if (tbinfo->relkind == RELKIND_SEQUENCE_GSC || tbinfo->relkind == RELKIND_LARGE_SEQUENCE_GSC) {
22929+ isGlobalStr = ", is_global";
22930+ isNewVer = true;
22931+ }
22907 if (fout->remoteVersion >= 80400) {22932 if (fout->remoteVersion >= 80400) {
22908 appendPQExpBuffer(query,22933 appendPQExpBuffer(query,
22909 "SELECT sequence_name, "22934 "SELECT sequence_name, "
@@ -22916,9 +22941,10 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large)
22916 " WHEN increment_by < 0 AND min_value = %s THEN NULL "22941 " WHEN increment_by < 0 AND min_value = %s THEN NULL "
22917 " ELSE min_value "22942 " ELSE min_value "
22918 "END AS min_value, "22943 "END AS min_value, "
22919- "cache_value, is_cycled FROM %s",22944+ "cache_value, is_cycled%s FROM %s",
22920 bufx,22945 bufx,
22921 bufm,22946 bufm,
22947+ isGlobalStr,
22922 fmtId(tbinfo->dobj.name));22948 fmtId(tbinfo->dobj.name));
22923 } else {22949 } else {
22924 appendPQExpBuffer(query,22950 appendPQExpBuffer(query,
@@ -22932,9 +22958,10 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large)
22932 " WHEN increment_by < 0 AND min_value = %s THEN NULL "22958 " WHEN increment_by < 0 AND min_value = %s THEN NULL "
22933 " ELSE min_value "22959 " ELSE min_value "
22934 "END AS min_value, "22960 "END AS min_value, "
22935- "cache_value, is_cycled FROM %s",22961+ "cache_value, is_cycled%s FROM %s",
22936 bufx,22962 bufx,
22937 bufm,22963 bufm,
22964+ isGlobalStr,
22938 fmtId(tbinfo->dobj.name));22965 fmtId(tbinfo->dobj.name));
22939 }22966 }
22940 22967 
@@ -22977,6 +23004,9 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large)
22977 minv = PQgetvalue(res, 0, 4);23004 minv = PQgetvalue(res, 0, 4);
22978 cache = PQgetvalue(res, 0, 5);23005 cache = PQgetvalue(res, 0, 5);
22979 cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);23006 cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);
23007+ if (isNewVer) {
23008+ isGlobal = (strcmp(PQgetvalue(res, 0, 7), "t") == 0);
23009+ }
22980 23010 
22981 /*23011 /*
22982 * DROP must be fully qualified in case same name appears in pg_catalog23012 * DROP must be fully qualified in case same name appears in pg_catalog
@@ -23018,6 +23048,9 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large)
23018 appendPQExpBuffer(query, " NO MAXVALUE\n");23048 appendPQExpBuffer(query, " NO MAXVALUE\n");
23019 23049 
23020 appendPQExpBuffer(query, " CACHE %s%s", cache, (cycled ? "\n CYCLE" : ""));23050 appendPQExpBuffer(query, " CACHE %s%s", cache, (cycled ? "\n CYCLE" : ""));
23051+ if (isNewVer) {
23052+ appendPQExpBuffer(query, "\n %s", isGlobal ? "GLOBAL" : "SESSION");
23053+ }
23021 23054 
23022 appendPQExpBuffer(query, ";\n");23055 appendPQExpBuffer(query, ";\n");
23023 23056 
@@ -25129,9 +25162,9 @@ static void dumpTableAutoIncrement(Archive* fout, PQExpBuffer sqlbuf, TableInfo*
25129 "pg_class c left join pg_namespace n on c.relnamespace = n.oid "25162 "pg_class c left join pg_namespace n on c.relnamespace = n.oid "
25130 "left join pg_depend d on c.oid = d.objid "25163 "left join pg_depend d on c.oid = d.objid "
25131 "where classid = %u and deptype = '%c' and refobjid = %u and refobjsubid = %u "25164 "where classid = %u and deptype = '%c' and refobjid = %u and refobjsubid = %u "
25132- "and c.relkind in ('%c', '%c')"25165+ "and c.relkind in ('%c', '%c', '%c', '%c')"
25133 ,RelationRelationId, DEPENDENCY_AUTO, tbinfo->dobj.catId.oid, tbinfo->autoinc_attnum25166 ,RelationRelationId, DEPENDENCY_AUTO, tbinfo->dobj.catId.oid, tbinfo->autoinc_attnum
25134- ,RELKIND_SEQUENCE, RELKIND_LARGE_SEQUENCE);25167+ ,RELKIND_SEQUENCE, RELKIND_LARGE_SEQUENCE, RELKIND_SEQUENCE_GSC, RELKIND_LARGE_SEQUENCE_GSC);
25135 25168 
25136 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);25169 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
25137 if (PQntuples(res) != 1) {25170 if (PQntuples(res) != 1) {
@@ -781,7 +781,8 @@ bool permissionsList(const char* pattern)
781 "SELECT n.nspname as \"%s\",\n"781 "SELECT n.nspname as \"%s\",\n"
782 " c.relname as \"%s\",\n"782 " c.relname as \"%s\",\n"
783 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'm' THEN '%s'"783 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'm' THEN '%s'"
784- " WHEN 'S' THEN '%s' WHEN 'L' THEN '%s' WHEN 'f' THEN '%s' END as \"%s\",\n"784+ " WHEN 'S' THEN '%s' WHEN 'z' THEN '%s' WHEN 'L' THEN '%s' WHEN 'Z' THEN '%s'"
785+ " WHEN 'f' THEN '%s' END as \"%s\",\n"
785 " ",786 " ",
786 gettext_noop("Schema"),787 gettext_noop("Schema"),
787 gettext_noop("Name"),788 gettext_noop("Name"),
@@ -789,6 +790,8 @@ bool permissionsList(const char* pattern)
789 gettext_noop("view"),790 gettext_noop("view"),
790 gettext_noop("materialized view"),791 gettext_noop("materialized view"),
791 gettext_noop("sequence"),792 gettext_noop("sequence"),
793+ gettext_noop("sequence"),
794+ gettext_noop("large sequence"),
792 gettext_noop("large sequence"),795 gettext_noop("large sequence"),
793 gettext_noop("foreign table"),796 gettext_noop("foreign table"),
794 gettext_noop("Type"));797 gettext_noop("Type"));
@@ -807,7 +810,7 @@ bool permissionsList(const char* pattern)
807 appendPQExpBuffer(&buf,810 appendPQExpBuffer(&buf,
808 "\nFROM pg_catalog.pg_class c\n"811 "\nFROM pg_catalog.pg_class c\n"
809 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"812 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
810- "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f')\n");813+ "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'z', 'f')\n");
811 814 
812 /*815 /*
813 * Unless a schema pattern is specified, we suppress system and temp816 * Unless a schema pattern is specified, we suppress system and temp
@@ -881,7 +884,7 @@ bool listDefaultACLs(const char* pattern)
881 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"884 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
882 " n.nspname AS \"%s\",\n"885 " n.nspname AS \"%s\",\n"
883 " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s'"886 " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s'"
884- " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS "887+ " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s'END AS "
885 "\"%s\",\n"888 "\"%s\",\n"
886 " ",889 " ",
887 gettext_noop("Owner"),890 gettext_noop("Owner"),
@@ -892,6 +895,10 @@ bool listDefaultACLs(const char* pattern)
892 gettext_noop("sequence"),895 gettext_noop("sequence"),
893 DEFACLOBJ_LARGE_SEQUENCE,896 DEFACLOBJ_LARGE_SEQUENCE,
894 gettext_noop("large sequence"),897 gettext_noop("large sequence"),
898+ DEFACLOBJ_SEQUENCE_GSC,
899+ gettext_noop("sequence"),
900+ DEFACLOBJ_LARGE_SEQUENCE_GSC,
901+ gettext_noop("large sequence"),
895 DEFACLOBJ_FUNCTION,902 DEFACLOBJ_FUNCTION,
896 gettext_noop("function"),903 gettext_noop("function"),
897 DEFACLOBJ_TYPE,904 DEFACLOBJ_TYPE,
@@ -1620,7 +1627,7 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
1620 * If it's a sequence, fetch its values and store into an array that will1627 * If it's a sequence, fetch its values and store into an array that will
1621 * be used later.1628 * be used later.
1622 */1629 */
1623- if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L') {1630+ if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L' || tableinfo.relkind == 'z' || tableinfo.relkind == 'Z') {
1624 printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));1631 printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
1625 /* must be separate because fmtId isn't reentrant */1632 /* must be separate because fmtId isn't reentrant */
1626 appendPQExpBuffer(&buf, ".%s;", fmtId(relationname));1633 appendPQExpBuffer(&buf, ".%s;", fmtId(relationname));
@@ -1793,9 +1800,11 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
1793 printfPQExpBuffer(&title, _("View \"%s.%s\""), schemaname, relationname);1800 printfPQExpBuffer(&title, _("View \"%s.%s\""), schemaname, relationname);
1794 break;1801 break;
1795 case 'S':1802 case 'S':
1803+ case 'z':
1796 printfPQExpBuffer(&title, _("Sequence \"%s.%s\""), schemaname, relationname);1804 printfPQExpBuffer(&title, _("Sequence \"%s.%s\""), schemaname, relationname);
1797 break;1805 break;
1798 case 'L':1806 case 'L':
1807+ case 'Z':
1799 printfPQExpBuffer(&title, _("Large Sequence \"%s.%s\""), schemaname, relationname);1808 printfPQExpBuffer(&title, _("Large Sequence \"%s.%s\""), schemaname, relationname);
1800 break;1809 break;
1801 case 'i':1810 case 'i':
@@ -1846,7 +1855,7 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
1846 modifiers = (char**)pg_malloc_zero((unsigned long)(numrows + 1) * sizeof(*modifiers));1855 modifiers = (char**)pg_malloc_zero((unsigned long)(numrows + 1) * sizeof(*modifiers));
1847 }1856 }
1848 1857 
1849- if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L')1858+ if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L' || tableinfo.relkind == 'z' || tableinfo.relkind == 'Z')
1850 headers[cols++] = gettext_noop("Value");1859 headers[cols++] = gettext_noop("Value");
1851 1860 
1852 if (tableinfo.relkind == 'i' || tableinfo.relkind == 'I')1861 if (tableinfo.relkind == 'i' || tableinfo.relkind == 'I')
@@ -2019,7 +2028,8 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
2019 }2028 }
2020 2029 
2021 /* Value: for sequences only */2030 /* Value: for sequences only */
2022- if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L')2031+ if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L' ||
2032+ tableinfo.relkind == 'z' || tableinfo.relkind == 'Z')
2023 printTableAddCell(&cont, seq_values[i], false, false);2033 printTableAddCell(&cont, seq_values[i], false, false);
2024 2034 
2025 /* Expression for index column */2035 /* Expression for index column */
@@ -2210,7 +2220,8 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
2210 }2220 }
2211 PQclear(result);2221 PQclear(result);
2212 }2222 }
2213- } else if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L') {2223+ } else if (tableinfo.relkind == 'S' || tableinfo.relkind == 'L' ||
2224+ tableinfo.relkind == 'z' || tableinfo.relkind == 'Z') {
2214 /* Footer information about a sequence */2225 /* Footer information about a sequence */
2215 PGresult* result = NULL;2226 PGresult* result = NULL;
2216 2227 
@@ -2245,7 +2256,7 @@ static bool describeOneTableDetails(const char* schemaname, const char* relation
2245 * don't print anything.2256 * don't print anything.
2246 */2257 */
2247 PQclear(result);2258 PQclear(result);
2248- } else if (tableinfo.relkind == 'r' || tableinfo.relkind == 'f' || tableinfo.relkind == 'm' || 2259+ } else if (tableinfo.relkind == 'r' || tableinfo.relkind == 'f' || tableinfo.relkind == 'm' ||
2249 tableinfo.relkind == 'e') {2260 tableinfo.relkind == 'e') {
2250 /* Footer information about a table */2261 /* Footer information about a table */
2251 PGresult* result = NULL;2262 PGresult* result = NULL;
@@ -3694,8 +3705,8 @@ bool listTables(const char* tabtypes, const char* pattern, bool verbose, bool sh
3694 "SELECT n.nspname as \"%s\",\n"3705 "SELECT n.nspname as \"%s\",\n"
3695 " c.relname as \"%s\",\n"3706 " c.relname as \"%s\",\n"
3696 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'I' THEN '%s' "3707 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'I' THEN '%s' "
3697- "WHEN 'S' THEN '%s' WHEN 'L' THEN '%s' WHEN 'f' THEN '%s' WHEN 'm' THEN '%s' WHEN 'e' THEN '%s' "3708+ "WHEN 'S' THEN '%s' WHEN 'z' THEN '%s' WHEN 'L' THEN '%s' WHEN 'Z' THEN '%s' WHEN 'f' THEN '%s' "
3698- "WHEN 'o' THEN '%s' END as \"%s\",\n"3709+ "WHEN 'm' THEN '%s' WHEN 'e' THEN '%s' WHEN 'o' THEN '%s' END as \"%s\",\n"
3699 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",3710 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3700 gettext_noop("Schema"),3711 gettext_noop("Schema"),
3701 gettext_noop("Name"),3712 gettext_noop("Name"),
@@ -3704,6 +3715,8 @@ bool listTables(const char* tabtypes, const char* pattern, bool verbose, bool sh
3704 gettext_noop("index"),3715 gettext_noop("index"),
3705 gettext_noop("global partition index"),3716 gettext_noop("global partition index"),
3706 gettext_noop("sequence"),3717 gettext_noop("sequence"),
3718+ gettext_noop("sequence"),
3719+ gettext_noop("large sequence"),
3707 gettext_noop("large sequence"),3720 gettext_noop("large sequence"),
3708 gettext_noop("foreign table"),3721 gettext_noop("foreign table"),
3709 gettext_noop("materialized view"),3722 gettext_noop("materialized view"),
@@ -3755,7 +3768,7 @@ bool listTables(const char* tabtypes, const char* pattern, bool verbose, bool sh
3755 if (showIndexes)3768 if (showIndexes)
3756 appendPQExpBuffer(&buf, "'i','I',");3769 appendPQExpBuffer(&buf, "'i','I',");
3757 if (showSeq)3770 if (showSeq)
3758- appendPQExpBuffer(&buf, "'S','L',");3771+ appendPQExpBuffer(&buf, "'S','L','z','Z',");
3759 if (showSystem || NULL != pattern)3772 if (showSystem || NULL != pattern)
3760 appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <=3773 appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <=
3761 * 8.1 */3774 * 8.1 */
@@ -245,7 +245,7 @@ static const SchemaQuery Query_for_list_of_sequences = {
245 /* catname */245 /* catname */
246 "pg_catalog.pg_class c",246 "pg_catalog.pg_class c",
247 /* selcondition */247 /* selcondition */
248- "c.relkind IN ('S')",248+ "c.relkind IN ('S', 'z')",
249 /* viscondition */249 /* viscondition */
250 "pg_catalog.pg_table_is_visible(c.oid)",250 "pg_catalog.pg_table_is_visible(c.oid)",
251 /* namespace */251 /* namespace */
@@ -356,7 +356,7 @@ static const SchemaQuery Query_for_list_of_tsvmf = {
356 /* catname */356 /* catname */
357 "pg_catalog.pg_class c",357 "pg_catalog.pg_class c",
358 /* selcondition */358 /* selcondition */
359- "c.relkind IN ('r', 'S', 'v', 'm', 'f')",359+ "c.relkind IN ('r', 'S', 'z', 'v', 'm', 'f')",
360 /* viscondition */360 /* viscondition */
361 "pg_catalog.pg_table_is_visible(c.oid)",361 "pg_catalog.pg_table_is_visible(c.oid)",
362 /* namespace */362 /* namespace */
@@ -1017,8 +1017,12 @@ static List* objectsInSchemaToOids(GrantObjectType objtype, List* nspnames)
1017 case ACL_OBJECT_SEQUENCE:1017 case ACL_OBJECT_SEQUENCE:
1018 objs = getRelationsInNamespace(namespaceId, RELKIND_SEQUENCE);1018 objs = getRelationsInNamespace(namespaceId, RELKIND_SEQUENCE);
1019 objects = list_concat(objects, objs);1019 objects = list_concat(objects, objs);
1020+ objs = getRelationsInNamespace(namespaceId, RELKIND_SEQUENCE_GSC);
1021+ objects = list_concat(objects, objs);
1020 objs = getRelationsInNamespace(namespaceId, RELKIND_LARGE_SEQUENCE);1022 objs = getRelationsInNamespace(namespaceId, RELKIND_LARGE_SEQUENCE);
1021 objects = list_concat(objects, objs);1023 objects = list_concat(objects, objs);
1024+ objs = getRelationsInNamespace(namespaceId, RELKIND_LARGE_SEQUENCE_GSC);
1025+ objects = list_concat(objects, objs);
1022 break;1026 break;
1023 case ACL_OBJECT_FUNCTION: {1027 case ACL_OBJECT_FUNCTION: {
1024 ScanKeyData key[1];1028 ScanKeyData key[1];
@@ -2220,6 +2224,8 @@ void ExecGrant_Relation(InternalGrant* istmt)
2220 switch (pg_class_tuple->relkind) {2224 switch (pg_class_tuple->relkind) {
2221 case RELKIND_SEQUENCE:2225 case RELKIND_SEQUENCE:
2222 case RELKIND_LARGE_SEQUENCE:2226 case RELKIND_LARGE_SEQUENCE:
2227+ case RELKIND_SEQUENCE_GSC:
2228+ case RELKIND_LARGE_SEQUENCE_GSC:
2223 old_acl = acldefault(ACL_OBJECT_SEQUENCE, ownerId);2229 old_acl = acldefault(ACL_OBJECT_SEQUENCE, ownerId);
2224 break;2230 break;
2225 default:2231 default:
@@ -2269,6 +2275,8 @@ void ExecGrant_Relation(InternalGrant* istmt)
2269 switch (pg_class_tuple->relkind) {2275 switch (pg_class_tuple->relkind) {
2270 case RELKIND_SEQUENCE:2276 case RELKIND_SEQUENCE:
2271 case RELKIND_LARGE_SEQUENCE:2277 case RELKIND_LARGE_SEQUENCE:
2278+ case RELKIND_SEQUENCE_GSC:
2279+ case RELKIND_LARGE_SEQUENCE_GSC:
2272 aclkind = ACL_KIND_SEQUENCE;2280 aclkind = ACL_KIND_SEQUENCE;
2273 break;2281 break;
2274 default:2282 default:
@@ -5042,6 +5050,8 @@ static AclMode check_dml_privilege(Form_pg_class classForm, AclMode mask, Oid ro
5042 break;5050 break;
5043 case RELKIND_SEQUENCE:5051 case RELKIND_SEQUENCE:
5044 case RELKIND_LARGE_SEQUENCE:5052 case RELKIND_LARGE_SEQUENCE:
5053+ case RELKIND_SEQUENCE_GSC:
5054+ case RELKIND_LARGE_SEQUENCE_GSC:
5045 if (HasSpecAnyPriv(roleid, SELECT_ANY_SEQUENCE, false)) {5055 if (HasSpecAnyPriv(roleid, SELECT_ANY_SEQUENCE, false)) {
5046 result |= ACL_USAGE | ACL_SELECT | ACL_UPDATE;5056 result |= ACL_USAGE | ACL_SELECT | ACL_UPDATE;
5047 }5057 }
@@ -5084,6 +5094,8 @@ static AclMode check_ddl_privilege(char relkind, AclMode mask, Oid roleid, AclMo
5084 break;5094 break;
5085 case RELKIND_LARGE_SEQUENCE:5095 case RELKIND_LARGE_SEQUENCE:
5086 case RELKIND_SEQUENCE:5096 case RELKIND_SEQUENCE:
5097+ case RELKIND_SEQUENCE_GSC:
5098+ case RELKIND_LARGE_SEQUENCE_GSC:
5087 if ((mask & ACL_ALTER) && !(result & ACL_ALTER)) {5099 if ((mask & ACL_ALTER) && !(result & ACL_ALTER)) {
5088 if (HasSpecAnyPriv(roleid, ALTER_ANY_SEQUENCE, false)) {5100 if (HasSpecAnyPriv(roleid, ALTER_ANY_SEQUENCE, false)) {
5089 result |= ACL_ALTER;5101 result |= ACL_ALTER;
@@ -5253,6 +5265,8 @@ AclMode pg_class_aclmask(Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how
5253 switch (classForm->relkind) {5265 switch (classForm->relkind) {
5254 case RELKIND_SEQUENCE:5266 case RELKIND_SEQUENCE:
5255 case RELKIND_LARGE_SEQUENCE:5267 case RELKIND_LARGE_SEQUENCE:
5268+ case RELKIND_SEQUENCE_GSC:
5269+ case RELKIND_LARGE_SEQUENCE_GSC:
5256 acl = acldefault(ACL_OBJECT_SEQUENCE, ownerId);5270 acl = acldefault(ACL_OBJECT_SEQUENCE, ownerId);
5257 break;5271 break;
5258 default:5272 default:
@@ -9045,11 +9045,11 @@
9045 ),9045 ),
9046 AddFuncGroup(9046 AddFuncGroup(
9047 "pg_sequence_parameters", 1, 9047 "pg_sequence_parameters", 1,
9048- AddBuiltinFunc(_0(3078), _1("pg_sequence_parameters"), _2(1), _3(true), _4(false), _5(pg_sequence_parameters), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 26), _21(6, 26, 34, 34, 34, 34, 16), _22(6, 'i', 'o', 'o', 'o', 'o', 'o'), _23(6, "sequence_oid", "start_value", "minimum_value", "maximum_value", "increment", "cycle_option"), _24(NULL), _25("pg_sequence_parameters"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33("sequence parameters, for use by information schema"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))9048+ AddBuiltinFunc(_0(3078), _1("pg_sequence_parameters"), _2(1), _3(true), _4(false), _5(pg_sequence_parameters), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 26), _21(7, 26, 34, 34, 34, 34, 16, 16), _22(7, 'i', 'o', 'o', 'o', 'o', 'o', 'o'), _23(7, "sequence_oid", "start_value", "minimum_value", "maximum_value", "increment", "cycle_option", "is_global_cache"), _24(NULL), _25("pg_sequence_parameters"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33("sequence parameters, for use by information schema"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
9049 ),9049 ),
9050 AddFuncGroup(9050 AddFuncGroup(
9051 "pg_sequence_all_parameters", 1,9051 "pg_sequence_all_parameters", 1,
9052- AddBuiltinFunc(_0(8930), _1("pg_sequence_all_parameters"), _2(1), _3(true), _4(false), _5(pg_sequence_all_parameters), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 25), _21(13, 25, 34, 34, 34, 34, 16, 34, 34, 16, 20, 20, 34, 16), _22(13, 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(13, "sequence_name", "start_value", "minimum_value", "maximum_value", "increment", "cycle_option", "cache_size", "last_value", "is_called", "log_cnt", "uuid", "last_used_value", "is_exhausted"), _24(NULL), _25("pg_sequence_all_parameters"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33("sequence all parameters"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))9052+ AddBuiltinFunc(_0(8930), _1("pg_sequence_all_parameters"), _2(1), _3(true), _4(false), _5(pg_sequence_all_parameters), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(1, 25), _21(14, 25, 34, 34, 34, 34, 16, 34, 34, 16, 20, 20, 34, 16, 16), _22(14, 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(14, "sequence_name", "start_value", "minimum_value", "maximum_value", "increment", "cycle_option", "cache_size", "last_value", "is_called", "log_cnt", "uuid", "last_used_value", "is_exhausted", "is_global_cache"), _24(NULL), _25("pg_sequence_all_parameters"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33("sequence all parameters"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0))
9053 ),9053 ),
9054 AddFuncGroup(9054 AddFuncGroup(
9055 "pg_shared_memctx_detail", 1, 9055 "pg_shared_memctx_detail", 1,
@@ -1474,6 +1474,8 @@ static void doDeletion(const ObjectAddress* object, int flags)
1474 switch (relKind) {1474 switch (relKind) {
1475 case RELKIND_SEQUENCE:1475 case RELKIND_SEQUENCE:
1476 case RELKIND_LARGE_SEQUENCE:1476 case RELKIND_LARGE_SEQUENCE:
1477+ case RELKIND_SEQUENCE_GSC:
1478+ case RELKIND_LARGE_SEQUENCE_GSC:
1477 /*1479 /*
1478 * Drop the sequence on GTM.1480 * Drop the sequence on GTM.
1479 * Sequence is dropped on GTM by a remote Coordinator only1481 * Sequence is dropped on GTM by a remote Coordinator only
@@ -3574,9 +3576,11 @@ static void getRelationDescription(StringInfo buffer, Oid relid)
3574 appendStringInfo(buffer, _("index %s"), relname);3576 appendStringInfo(buffer, _("index %s"), relname);
3575 break;3577 break;
3576 case RELKIND_SEQUENCE:3578 case RELKIND_SEQUENCE:
3579+ case RELKIND_SEQUENCE_GSC:
3577 appendStringInfo(buffer, _("sequence %s"), relname);3580 appendStringInfo(buffer, _("sequence %s"), relname);
3578 break;3581 break;
3579 case RELKIND_LARGE_SEQUENCE:3582 case RELKIND_LARGE_SEQUENCE:
3583+ case RELKIND_LARGE_SEQUENCE_GSC:
3580 appendStringInfo(buffer, _("large sequence %s"), relname);3584 appendStringInfo(buffer, _("large sequence %s"), relname);
3581 break;3585 break;
3582 case RELKIND_TOASTVALUE:3586 case RELKIND_TOASTVALUE:
@@ -596,6 +596,8 @@ Relation heap_create(const char* relname, Oid relnamespace, Oid reltablespace, O
596 break;596 break;
597 case RELKIND_SEQUENCE:597 case RELKIND_SEQUENCE:
598 case RELKIND_LARGE_SEQUENCE:598 case RELKIND_LARGE_SEQUENCE:
599+ case RELKIND_SEQUENCE_GSC:
600+ case RELKIND_LARGE_SEQUENCE_GSC:
599 create_storage = true;601 create_storage = true;
600 602 
601 /*603 /*
@@ -1363,6 +1365,8 @@ static void AddNewRelationTuple(Relation pg_class_desc, Relation new_rel_desc, O
1363 break;1365 break;
1364 case RELKIND_SEQUENCE:1366 case RELKIND_SEQUENCE:
1365 case RELKIND_LARGE_SEQUENCE:1367 case RELKIND_LARGE_SEQUENCE:
1368+ case RELKIND_SEQUENCE_GSC:
1369+ case RELKIND_LARGE_SEQUENCE_GSC:
1366 /* Sequences always have a known size */1370 /* Sequences always have a known size */
1367 new_rel_reltup->relpages = 1;1371 new_rel_reltup->relpages = 1;
1368 new_rel_reltup->reltuples = 1;1372 new_rel_reltup->reltuples = 1;
@@ -2858,6 +2862,8 @@ Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltable
2858 break;2862 break;
2859 case RELKIND_SEQUENCE:2863 case RELKIND_SEQUENCE:
2860 case RELKIND_LARGE_SEQUENCE: // tbf2864 case RELKIND_LARGE_SEQUENCE: // tbf
2865+ case RELKIND_SEQUENCE_GSC:
2866+ case RELKIND_LARGE_SEQUENCE_GSC:
2861 relacl = get_user_default_acl(ACL_OBJECT_SEQUENCE, ownerid, relnamespace);2867 relacl = get_user_default_acl(ACL_OBJECT_SEQUENCE, ownerid, relnamespace);
2862 break;2868 break;
2863 default:2869 default:
@@ -1635,10 +1635,11 @@ CREATE VIEW sequences AS
1635 CAST((pg_catalog.pg_sequence_parameters(c.oid)).minimum_value AS character_data) AS minimum_value,1635 CAST((pg_catalog.pg_sequence_parameters(c.oid)).minimum_value AS character_data) AS minimum_value,
1636 CAST((pg_catalog.pg_sequence_parameters(c.oid)).maximum_value AS character_data) AS maximum_value,1636 CAST((pg_catalog.pg_sequence_parameters(c.oid)).maximum_value AS character_data) AS maximum_value,
1637 CAST((pg_catalog.pg_sequence_parameters(c.oid)).increment AS character_data) AS increment,1637 CAST((pg_catalog.pg_sequence_parameters(c.oid)).increment AS character_data) AS increment,
1638- CAST(CASE WHEN (pg_catalog.pg_sequence_parameters(c.oid)).cycle_option THEN 'YES' ELSE 'NO' END AS yes_or_no) AS cycle_option1638+ CAST(CASE WHEN (pg_catalog.pg_sequence_parameters(c.oid)).cycle_option THEN 'YES' ELSE 'NO' END AS yes_or_no) AS cycle_option,
1639+ CAST(CASE WHEN (pg_catalog.pg_sequence_parameters(c.oid)).is_global_cache THEN 'YES' ELSE 'NO' END AS yes_or_no) AS global_cache_option
1639 FROM pg_namespace nc, pg_class c1640 FROM pg_namespace nc, pg_class c
1640 WHERE c.relnamespace = nc.oid1641 WHERE c.relnamespace = nc.oid
1641- AND (c.relkind = 'L' or c.relkind = 'S')1642+ AND (c.relkind = 'L' or c.relkind = 'S' or c.relkind = 'z' or c.relkind = 'Z')
totaj
totajtotaj2月25日

要在升级脚本里面适配,使用create or replace替换视图定义

likedislike
sunquancheng
sunquancheng
6月24日 评论:
1642 AND (NOT pg_catalog.pg_is_other_temp_schema(nc.oid))1643 AND (NOT pg_catalog.pg_is_other_temp_schema(nc.oid))
1643 AND (pg_catalog.pg_has_role(c.relowner, 'USAGE')1644 AND (pg_catalog.pg_has_role(c.relowner, 'USAGE')
1644 OR pg_catalog.has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE') );1645 OR pg_catalog.has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE') );
@@ -2421,7 +2422,7 @@ CREATE VIEW usage_privileges AS
2421 ) AS grantee (oid, rolname)2422 ) AS grantee (oid, rolname)
2422 2423 
2423 WHERE c.relnamespace = n.oid2424 WHERE c.relnamespace = n.oid
2424- AND (c.relkind = 'S' or c.relkind = 'L')2425+ AND (c.relkind = 'S' or c.relkind = 'L' or c.relkind = 'z' or c.relkind = 'Z')
2425 AND c.grantee = grantee.oid2426 AND c.grantee = grantee.oid
2426 AND c.grantor = u_grantor.oid2427 AND c.grantor = u_grantor.oid
2427 AND c.prtype IN ('USAGE')2428 AND c.prtype IN ('USAGE')
@@ -532,6 +532,8 @@ bool CheckRelationCreateAnyPrivilege(Oid userId, char relkind)
532 /* sequence object */532 /* sequence object */
533 case RELKIND_SEQUENCE:533 case RELKIND_SEQUENCE:
534 case RELKIND_LARGE_SEQUENCE:534 case RELKIND_LARGE_SEQUENCE:
535+ case RELKIND_SEQUENCE_GSC:
536+ case RELKIND_LARGE_SEQUENCE_GSC:
535 if (HasSpecAnyPriv(userId, CREATE_ANY_SEQUENCE, false)) {537 if (HasSpecAnyPriv(userId, CREATE_ANY_SEQUENCE, false)) {
536 aclResult = ACLCHECK_OK;538 aclResult = ACLCHECK_OK;
537 }539 }
@@ -754,6 +754,8 @@ ObjectAddress get_object_address(
754 case OBJECT_INDEX:754 case OBJECT_INDEX:
755 case OBJECT_SEQUENCE:755 case OBJECT_SEQUENCE:
756 case OBJECT_LARGE_SEQUENCE:756 case OBJECT_LARGE_SEQUENCE:
757+ case OBJECT_SEQUENCE_GSC:
758+ case OBJECT_LARGE_SEQUENCE_GSC:
757 case OBJECT_TABLE:759 case OBJECT_TABLE:
758 case OBJECT_VIEW:760 case OBJECT_VIEW:
759 case OBJECT_CONTQUERY:761 case OBJECT_CONTQUERY:
@@ -1200,16 +1202,18 @@ static ObjectAddress get_relation_by_qualified_name(
1200 errmsg("\"%s\" is not an index", RelationGetRelationName(relation))));1202 errmsg("\"%s\" is not an index", RelationGetRelationName(relation))));
1201 break;1203 break;
1202 case OBJECT_SEQUENCE:1204 case OBJECT_SEQUENCE:
1203- if (relation->rd_rel->relkind != RELKIND_SEQUENCE)1205+ case OBJECT_SEQUENCE_GSC:
S
Ssuperlchf2月26日

这里应该分开写,这里逻辑合不到一起。原本逻辑是OBJECT_SEQUENCE情况下,relkind ==RELKIND_SEQUENCE 那如果现在OBJECT_SEQUENCE情况下,relkind ==RELKIND_SEQUENCE_GSC是走不进这个error的 后面代码也有这个问题

likedislike
sunquancheng
sunquancheng
5月28日 评论:
1206+ if (relation->rd_rel->relkind != RELKIND_SEQUENCE_GSC && relation->rd_rel->relkind != RELKIND_SEQUENCE)
1204 ereport(ERROR,1207 ereport(ERROR,
1205 (errcode(ERRCODE_WRONG_OBJECT_TYPE),1208 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1206 errmsg("\"%s\" is not a sequence", RelationGetRelationName(relation))));1209 errmsg("\"%s\" is not a sequence", RelationGetRelationName(relation))));
1207 break;1210 break;
1208 case OBJECT_LARGE_SEQUENCE:1211 case OBJECT_LARGE_SEQUENCE:
1209- if (relation->rd_rel->relkind != RELKIND_LARGE_SEQUENCE)1212+ case OBJECT_LARGE_SEQUENCE_GSC:
1210- ereport(ERROR,1213+ if (relation->rd_rel->relkind != RELKIND_LARGE_SEQUENCE_GSC &&
1211- (errcode(ERRCODE_WRONG_OBJECT_TYPE),1214+ relation->rd_rel->relkind != RELKIND_LARGE_SEQUENCE)
1212- errmsg("\"%s\" is not a large sequence", RelationGetRelationName(relation))));1215+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1216+ errmsg("\"%s\" is not a large sequence", RelationGetRelationName(relation))));
1213 break;1217 break;
1214 case OBJECT_TABLE:1218 case OBJECT_TABLE:
1215 if (relation->rd_rel->relkind != RELKIND_RELATION)1219 if (relation->rd_rel->relkind != RELKIND_RELATION)
@@ -1695,6 +1699,8 @@ void check_object_ownership(
1695 case OBJECT_INDEX:1699 case OBJECT_INDEX:
1696 case OBJECT_SEQUENCE:1700 case OBJECT_SEQUENCE:
1697 case OBJECT_LARGE_SEQUENCE:1701 case OBJECT_LARGE_SEQUENCE:
1702+ case OBJECT_SEQUENCE_GSC:
1703+ case OBJECT_LARGE_SEQUENCE_GSC:
1698 case OBJECT_TABLE:1704 case OBJECT_TABLE:
1699 case OBJECT_VIEW:1705 case OBJECT_VIEW:
1700 case OBJECT_CONTQUERY:1706 case OBJECT_CONTQUERY:
@@ -2239,8 +2245,13 @@ static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objec
2239 appendStringInfoString(buffer, "index");2245 appendStringInfoString(buffer, "index");
2240 break;2246 break;
2241 case RELKIND_SEQUENCE:2247 case RELKIND_SEQUENCE:
2248+ case RELKIND_SEQUENCE_GSC:
2242 appendStringInfoString(buffer, "sequence");2249 appendStringInfoString(buffer, "sequence");
2243 break;2250 break;
2251+ case RELKIND_LARGE_SEQUENCE:
2252+ case RELKIND_LARGE_SEQUENCE_GSC:
2253+ appendStringInfoString(buffer, "large sequence");
2254+ break;
2244 case RELKIND_TOASTVALUE:2255 case RELKIND_TOASTVALUE:
2245 appendStringInfoString(buffer, "toast table");2256 appendStringInfoString(buffer, "toast table");
2246 break;2257 break;
@@ -2278,6 +2289,8 @@ get_relkind_objtype(char relkind)
2278 return OBJECT_INDEX;2289 return OBJECT_INDEX;
2279 case RELKIND_SEQUENCE:2290 case RELKIND_SEQUENCE:
2280 return OBJECT_SEQUENCE;2291 return OBJECT_SEQUENCE;
2292+ case RELKIND_SEQUENCE_GSC:
2293+ return OBJECT_SEQUENCE_GSC;
2281 case RELKIND_VIEW:2294 case RELKIND_VIEW:
2282 return OBJECT_VIEW;2295 return OBJECT_VIEW;
2283 case RELKIND_MATVIEW:2296 case RELKIND_MATVIEW:
@@ -1223,7 +1223,7 @@ CREATE VIEW dbe_perf.statio_all_sequences AS
1223 pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_hit1223 pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_hit
1224 FROM pg_class C1224 FROM pg_class C
1225 LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)1225 LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
1226- WHERE C.relkind = 'S' or C.relkind = 'L';1226+ WHERE C.relkind = 'S' or C.relkind = 'L' or C.relkind = 'z' or C.relkind = 'Z';
totaj
totajtotaj2月25日

要在升级脚本里面适配,使用create or replace替换视图定义

likedislike
sunquancheng
sunquancheng
6月24日 评论:
1227 1227 
1228CREATE OR REPLACE FUNCTION dbe_perf.get_global_statio_all_sequences1228CREATE OR REPLACE FUNCTION dbe_perf.get_global_statio_all_sequences
1229 (OUT node_name name, OUT relid oid, OUT schemaname name, 1229 (OUT node_name name, OUT relid oid, OUT schemaname name,
@@ -462,9 +462,15 @@ PgObjectType GetPgObjectTypePgClass(char relkind)
462 case RELKIND_SEQUENCE:462 case RELKIND_SEQUENCE:
463 objectType = OBJECT_TYPE_SEQUENCE;463 objectType = OBJECT_TYPE_SEQUENCE;
464 break;464 break;
465+ case RELKIND_SEQUENCE_GSC:
466+ objectType = OBJECT_TYPE_SEQUENCE_GSC;
467+ break;
465 case RELKIND_LARGE_SEQUENCE:468 case RELKIND_LARGE_SEQUENCE:
466 objectType = OBJECT_TYPE_LARGE_SEQUENCE;469 objectType = OBJECT_TYPE_LARGE_SEQUENCE;
467 break;470 break;
471+ case RELKIND_LARGE_SEQUENCE_GSC:
472+ objectType = OBJECT_TYPE_LARGE_SEQUENCE_GSC;
473+ break;
468 case RELKIND_INDEX:474 case RELKIND_INDEX:
469 case RELKIND_GLOBAL_INDEX:475 case RELKIND_GLOBAL_INDEX:
470 objectType = OBJECT_TYPE_INDEX;476 objectType = OBJECT_TYPE_INDEX;
@@ -510,6 +516,8 @@ void recordCommentObjectTime(ObjectAddress addr, Relation rel, ObjectType objTyp
510 case OBJECT_INDEX:516 case OBJECT_INDEX:
511 case OBJECT_SEQUENCE:517 case OBJECT_SEQUENCE:
512 case OBJECT_LARGE_SEQUENCE:518 case OBJECT_LARGE_SEQUENCE:
519+ case OBJECT_SEQUENCE_GSC:
520+ case OBJECT_LARGE_SEQUENCE_GSC:
513 case OBJECT_TABLE:521 case OBJECT_TABLE:
514 case OBJECT_VIEW:522 case OBJECT_VIEW:
515 case OBJECT_CONTQUERY:523 case OBJECT_CONTQUERY:
@@ -571,6 +571,8 @@ char* CheckReferencedObject(Oid relOid, RangeVar* objVar, const char* synName)
571 break;571 break;
572 case RELKIND_SEQUENCE:572 case RELKIND_SEQUENCE:
573 case RELKIND_LARGE_SEQUENCE:573 case RELKIND_LARGE_SEQUENCE:
574+ case RELKIND_SEQUENCE_GSC:
575+ case RELKIND_LARGE_SEQUENCE_GSC:
574 appendStringInfo(&detail,576 appendStringInfo(&detail,
575 _("Maybe you want to use synonym to reference a (large) sequence object, "577 _("Maybe you want to use synonym to reference a (large) sequence object, "
576 "but it is not yet supported."));578 "but it is not yet supported."));
@@ -346,7 +346,7 @@ CREATE VIEW pg_catalog.pg_gtt_attached_pids WITH (security_barrier) AS
346 FROM346 FROM
347 pg_class c347 pg_class c
348 LEFT JOIN pg_namespace n ON n.oid = c.relnamespace348 LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
349- WHERE c.relpersistence='g' AND c.relkind in('r', 'S', 'L');349+ WHERE c.relpersistence='g' AND c.relkind in('r', 'S', 'L', 'z', 'Z');
totaj
totajtotaj2月25日

要在升级脚本里面适配,使用create or replace替换视图定义

likedislike
sunquancheng
sunquancheng
6月24日 评论:
350 350 
351CREATE VIEW pg_catalog.pg_gtt_stats WITH (security_barrier) AS351CREATE VIEW pg_catalog.pg_gtt_stats WITH (security_barrier) AS
352SELECT s.nspname AS schemaname,352SELECT s.nspname AS schemaname,
@@ -586,6 +586,8 @@ SELECT
586 WHEN rel.relkind = 'm' THEN 'materialized view'::text586 WHEN rel.relkind = 'm' THEN 'materialized view'::text
587 WHEN rel.relkind = 'S' THEN 'sequence'::text587 WHEN rel.relkind = 'S' THEN 'sequence'::text
588 WHEN rel.relkind = 'L' THEN 'large sequence'::text588 WHEN rel.relkind = 'L' THEN 'large sequence'::text
589+ WHEN rel.relkind = 'z' THEN 'sequence'::text
590+ WHEN rel.relkind = 'Z' THEN 'large sequence'::text
589 WHEN rel.relkind = 'f' THEN 'foreign table'::text END AS objtype,591 WHEN rel.relkind = 'f' THEN 'foreign table'::text END AS objtype,
590 rel.relnamespace AS objnamespace,592 rel.relnamespace AS objnamespace,
591 CASE WHEN pg_catalog.pg_table_is_visible(rel.oid)593 CASE WHEN pg_catalog.pg_table_is_visible(rel.oid)
@@ -928,7 +930,7 @@ CREATE VIEW pg_statio_all_sequences AS
928 pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_hit930 pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_hit
929 FROM pg_class C931 FROM pg_class C
930 LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)932 LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
931- WHERE C.relkind = 'S' or C.relkind = 'L';933+ WHERE C.relkind = 'S' or C.relkind = 'L' or C.relkind = 'z' or C.relkind = 'Z';
932 934 
933CREATE VIEW pg_statio_sys_sequences AS935CREATE VIEW pg_statio_sys_sequences AS
934 SELECT * FROM pg_statio_all_sequences936 SELECT * FROM pg_statio_all_sequences
@@ -596,6 +596,35 @@ static Query* TransformCompositeTypeStmt(ParseState* pstate, CompositeTypeStmt*
596 return result;596 return result;
597}597}
598 598 
599+static void rewriteSequenceObject(DropStmt* stmt)
600+{
601+ ListCell* cell = NULL;
602+ foreach (cell, stmt->objects) {
603+ List* names = (List*)lfirst(cell);
604+ RangeVar* relrv = makeRangeVarFromNameList(names);
605+ 
606+ if (relrv == NULL) {
607+ continue;
608+ }
609+ 
610+ Oid namespaceId = RangeVarGetCreationNamespace(relrv);
611+ HeapTuple relTuple =
612+ SearchSysCache2(RELNAMENSP, PointerGetDatum(relrv->relname), ObjectIdGetDatum(namespaceId));
613+ if (!HeapTupleIsValid(relTuple)) {
614+ pfree(relrv);
615+ continue;
616+ }
617+ Form_pg_class classForm = (Form_pg_class)GETSTRUCT(relTuple);
618+ if (classForm->relkind == RELKIND_SEQUENCE) {
619+ stmt->removeType = OBJECT_SEQUENCE;
620+ } else if (classForm->relkind == RELKIND_LARGE_SEQUENCE) {
621+ stmt->removeType = OBJECT_LARGE_SEQUENCE;
622+ }
623+ ReleaseSysCache(relTuple);
624+ pfree(relrv);
625+ }
626+}
627+ 
599/*628/*
600 * transformStmt -629 * transformStmt -
601 * recursively transform a Parse tree into a Query tree.630 * recursively transform a Parse tree into a Query tree.
@@ -716,7 +745,12 @@ Query* transformStmt(ParseState* pstate, Node* parseTree, bool isFirstNode, bool
716 result = transformCallStmt(pstate, (DolphinCallStmt*) parseTree);745 result = transformCallStmt(pstate, (DolphinCallStmt*) parseTree);
717 break;746 break;
718 default:747 default:
719- 748+ if (nodeTag(parseTree) == T_DropStmt) {
S
Ssuperlchf6月25日

这个要放在前面的case T_DropStmt:增加一个分支

likedislike
749+ DropStmt *stmt = (DropStmt*)parseTree;
750+ if (stmt->removeType == OBJECT_SEQUENCE_GSC || stmt->removeType == OBJECT_LARGE_SEQUENCE_GSC) {
751+ rewriteSequenceObject(stmt);
752+ }
753+ }
720 /*754 /*
721 * other statements don't require any transformation; just return755 * other statements don't require any transformation; just return
722 * the original parsetree with a Query node plastered on top.756 * the original parsetree with a Query node plastered on top.
@@ -4031,7 +4031,7 @@ AlterTableStmt:
4031 AlterTableStmt *n = makeNode(AlterTableStmt);4031 AlterTableStmt *n = makeNode(AlterTableStmt);
4032 n->relation = $3;4032 n->relation = $3;
4033 n->cmds = $4;4033 n->cmds = $4;
4034- n->relkind = OBJECT_SEQUENCE;4034+ n->relkind = OBJECT_SEQUENCE_GSC;
4035 n->missing_ok = false;4035 n->missing_ok = false;
4036 $$ = (Node *)n;4036 $$ = (Node *)n;
4037 }4037 }
@@ -4040,7 +4040,7 @@ AlterTableStmt:
4040 AlterTableStmt *n = makeNode(AlterTableStmt);4040 AlterTableStmt *n = makeNode(AlterTableStmt);
4041 n->relation = $4;4041 n->relation = $4;
4042 n->cmds = $5;4042 n->cmds = $5;
4043- n->relkind = OBJECT_LARGE_SEQUENCE;4043+ n->relkind = OBJECT_LARGE_SEQUENCE_GSC;
4044 n->missing_ok = false;4044 n->missing_ok = false;
4045 $$ = (Node *)n;4045 $$ = (Node *)n;
4046 }4046 }
@@ -4049,7 +4049,7 @@ AlterTableStmt:
4049 AlterTableStmt *n = makeNode(AlterTableStmt);4049 AlterTableStmt *n = makeNode(AlterTableStmt);
4050 n->relation = $5;4050 n->relation = $5;
4051 n->cmds = $6;4051 n->cmds = $6;
4052- n->relkind = OBJECT_SEQUENCE;4052+ n->relkind = OBJECT_SEQUENCE_GSC;
4053 n->missing_ok = true;4053 n->missing_ok = true;
4054 $$ = (Node *)n;4054 $$ = (Node *)n;
4055 }4055 }
@@ -4058,7 +4058,7 @@ AlterTableStmt:
4058 AlterTableStmt *n = makeNode(AlterTableStmt);4058 AlterTableStmt *n = makeNode(AlterTableStmt);
4059 n->relation = $6;4059 n->relation = $6;
4060 n->cmds = $7;4060 n->cmds = $7;
4061- n->relkind = OBJECT_LARGE_SEQUENCE;4061+ n->relkind = OBJECT_LARGE_SEQUENCE_GSC;
4062 n->missing_ok = true;4062 n->missing_ok = true;
4063 $$ = (Node *)n;4063 $$ = (Node *)n;
4064 }4064 }
@@ -10579,6 +10579,14 @@ SeqOptElem: CACHE NumericOnly
10579 {10579 {
10580 $$ = makeDefElem("minvalue", NULL);10580 $$ = makeDefElem("minvalue", NULL);
10581 }10581 }
10582+ | GLOBAL
10583+ {
10584+ $$ = makeDefElem("is_global", (Node *)makeInteger(TRUE));
10585+ }
10586+ | SESSION
10587+ {
10588+ $$ = makeDefElem("is_global", (Node *)makeInteger(FALSE));
10589+ }
10582 ;10590 ;
10583 10591 
10584opt_by: BY {}10592opt_by: BY {}
@@ -11130,7 +11138,7 @@ AlterExtensionContentsStmt:
11130 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);11138 AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
11131 n->extname = $3;11139 n->extname = $3;
11132 n->action = $4;11140 n->action = $4;
11133- n->objtype = OBJECT_SEQUENCE;11141+ n->objtype = OBJECT_SEQUENCE_GSC;
11134 n->objname = $6;11142 n->objname = $6;
11135 $$ = (Node *)n;11143 $$ = (Node *)n;
11136 }11144 }
@@ -14573,8 +14581,8 @@ opt_purge:
14573drop_type: TABLE { $$ = OBJECT_TABLE; }14581drop_type: TABLE { $$ = OBJECT_TABLE; }
14574 | CONTVIEW { $$ = OBJECT_CONTQUERY; }14582 | CONTVIEW { $$ = OBJECT_CONTQUERY; }
14575 | STREAM { $$ = OBJECT_STREAM; }14583 | STREAM { $$ = OBJECT_STREAM; }
14576- | SEQUENCE { $$ = OBJECT_SEQUENCE; }14584+ | SEQUENCE { $$ = OBJECT_SEQUENCE_GSC; }
14577- | LARGE_P SEQUENCE { $$ = OBJECT_LARGE_SEQUENCE; }14585+ | LARGE_P SEQUENCE { $$ = OBJECT_LARGE_SEQUENCE_GSC; }
14578 | VIEW { $$ = OBJECT_VIEW; }14586 | VIEW { $$ = OBJECT_VIEW; }
14579 | INDEX { $$ = OBJECT_INDEX; }14587 | INDEX { $$ = OBJECT_INDEX; }
14580 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }14588 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
@@ -14838,8 +14846,8 @@ comment_type:
14838 | DATABASE { $$ = OBJECT_DATABASE; }14846 | DATABASE { $$ = OBJECT_DATABASE; }
14839 | SCHEMA { $$ = OBJECT_SCHEMA; }14847 | SCHEMA { $$ = OBJECT_SCHEMA; }
14840 | INDEX { $$ = OBJECT_INDEX; }14848 | INDEX { $$ = OBJECT_INDEX; }
14841- | SEQUENCE { $$ = OBJECT_SEQUENCE; }14849+ | SEQUENCE { $$ = OBJECT_SEQUENCE_GSC; }
14842- | LARGE_P SEQUENCE { $$ = OBJECT_LARGE_SEQUENCE; }14850+ | LARGE_P SEQUENCE { $$ = OBJECT_LARGE_SEQUENCE_GSC; }
14843 | TABLE { $$ = OBJECT_TABLE; }14851 | TABLE { $$ = OBJECT_TABLE; }
14844 | DOMAIN_P { $$ = OBJECT_DOMAIN; }14852 | DOMAIN_P { $$ = OBJECT_DOMAIN; }
14845 | TYPE_P { $$ = OBJECT_TYPE; }14853 | TYPE_P { $$ = OBJECT_TYPE; }
@@ -14941,7 +14949,7 @@ security_label_type:
14941 | EVENT_TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }14949 | EVENT_TRIGGER { $$ = OBJECT_EVENT_TRIGGER; }
14942 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }14950 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
14943 | SCHEMA { $$ = OBJECT_SCHEMA; }14951 | SCHEMA { $$ = OBJECT_SCHEMA; }
14944- | SEQUENCE { $$ = OBJECT_SEQUENCE; }14952+ | SEQUENCE { $$ = OBJECT_SEQUENCE_GSC; }
14945 | TABLE { $$ = OBJECT_TABLE; }14953 | TABLE { $$ = OBJECT_TABLE; }
14946 | DOMAIN_P { $$ = OBJECT_TYPE; }14954 | DOMAIN_P { $$ = OBJECT_TYPE; }
14947 | ROLE { $$ = OBJECT_ROLE; }14955 | ROLE { $$ = OBJECT_ROLE; }
@@ -19552,7 +19560,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
19552 | ALTER SEQUENCE qualified_name RENAME TO name19560 | ALTER SEQUENCE qualified_name RENAME TO name
19553 {19561 {
19554 RenameStmt *n = makeNode(RenameStmt);19562 RenameStmt *n = makeNode(RenameStmt);
19555- n->renameType = OBJECT_SEQUENCE;19563+ n->renameType = OBJECT_SEQUENCE_GSC;
19556 n->relation = $3;19564 n->relation = $3;
19557 n->subname = NULL;19565 n->subname = NULL;
19558 n->newname = $6;19566 n->newname = $6;
@@ -19562,7 +19570,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
19562 | ALTER LARGE_P SEQUENCE qualified_name RENAME TO name19570 | ALTER LARGE_P SEQUENCE qualified_name RENAME TO name
19563 {19571 {
19564 RenameStmt *n = makeNode(RenameStmt);19572 RenameStmt *n = makeNode(RenameStmt);
19565- n->renameType = OBJECT_LARGE_SEQUENCE;19573+ n->renameType = OBJECT_LARGE_SEQUENCE_GSC;
19566 n->relation = $4;19574 n->relation = $4;
19567 n->subname = NULL;19575 n->subname = NULL;
19568 n->newname = $7;19576 n->newname = $7;
@@ -19572,7 +19580,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
19572 | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name19580 | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
19573 {19581 {
19574 RenameStmt *n = makeNode(RenameStmt);19582 RenameStmt *n = makeNode(RenameStmt);
19575- n->renameType = OBJECT_SEQUENCE;19583+ n->renameType = OBJECT_SEQUENCE_GSC;
19576 n->relation = $5;19584 n->relation = $5;
19577 n->subname = NULL;19585 n->subname = NULL;
19578 n->newname = $8;19586 n->newname = $8;
@@ -19582,7 +19590,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
19582 | ALTER LARGE_P SEQUENCE IF_P EXISTS qualified_name RENAME TO name19590 | ALTER LARGE_P SEQUENCE IF_P EXISTS qualified_name RENAME TO name
19583 {19591 {
19584 RenameStmt *n = makeNode(RenameStmt);19592 RenameStmt *n = makeNode(RenameStmt);
19585- n->renameType = OBJECT_LARGE_SEQUENCE;19593+ n->renameType = OBJECT_LARGE_SEQUENCE_GSC;
19586 n->relation = $6;19594 n->relation = $6;
19587 n->subname = NULL;19595 n->subname = NULL;
19588 n->newname = $9;19596 n->newname = $9;
@@ -20231,7 +20239,7 @@ AlterObjectSchemaStmt:
20231 | ALTER SEQUENCE qualified_name SET SCHEMA name20239 | ALTER SEQUENCE qualified_name SET SCHEMA name
20232 {20240 {
20233 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);20241 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
20234- n->objectType = OBJECT_SEQUENCE;20242+ n->objectType = OBJECT_SEQUENCE_GSC;
20235 n->relation = $3;20243 n->relation = $3;
20236 n->newschema = $6;20244 n->newschema = $6;
20237 n->missing_ok = false;20245 n->missing_ok = false;
@@ -20240,7 +20248,7 @@ AlterObjectSchemaStmt:
20240 | ALTER LARGE_P SEQUENCE qualified_name SET SCHEMA name20248 | ALTER LARGE_P SEQUENCE qualified_name SET SCHEMA name
20241 {20249 {
20242 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);20250 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
20243- n->objectType = OBJECT_LARGE_SEQUENCE;20251+ n->objectType = OBJECT_LARGE_SEQUENCE_GSC;
20244 n->relation = $4;20252 n->relation = $4;
20245 n->newschema = $7;20253 n->newschema = $7;
20246 n->missing_ok = false;20254 n->missing_ok = false;
@@ -20249,7 +20257,7 @@ AlterObjectSchemaStmt:
20249 | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name20257 | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
20250 {20258 {
20251 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);20259 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
20252- n->objectType = OBJECT_SEQUENCE;20260+ n->objectType = OBJECT_SEQUENCE_GSC;
20253 n->relation = $5;20261 n->relation = $5;
20254 n->newschema = $8;20262 n->newschema = $8;
20255 n->missing_ok = true;20263 n->missing_ok = true;
@@ -20258,7 +20266,7 @@ AlterObjectSchemaStmt:
20258 | ALTER LARGE_P SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name20266 | ALTER LARGE_P SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
20259 {20267 {
20260 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);20268 AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
20261- n->objectType = OBJECT_LARGE_SEQUENCE;20269+ n->objectType = OBJECT_LARGE_SEQUENCE_GSC;
20262 n->relation = $6;20270 n->relation = $6;
20263 n->newschema = $9;20271 n->newschema = $9;
20264 n->missing_ok = true;20272 n->missing_ok = true;
@@ -2318,7 +2318,8 @@ static void transformTableLikeClause(
2318 if (seqs != NULL && list_member_oid(seqs, DatumGetObjectId(seqId))) {2318 if (seqs != NULL && list_member_oid(seqs, DatumGetObjectId(seqId))) {
2319 /* is serial type */2319 /* is serial type */
2320 def->is_serial = true;2320 def->is_serial = true;
2321- bool large = (get_rel_relkind(seqId) == RELKIND_LARGE_SEQUENCE);2321+ char relkind = get_rel_relkind(seqId);
2322+ bool large = (relkind == RELKIND_LARGE_SEQUENCE || relkind == RELKIND_LARGE_SEQUENCE_GSC);
2322 /* Special actions for SERIAL pseudo-types, treat serial and identity differently */2323 /* Special actions for SERIAL pseudo-types, treat serial and identity differently */
2323 bool isForIdentity = DB_IS_CMPT(D_FORMAT) &&2324 bool isForIdentity = DB_IS_CMPT(D_FORMAT) &&
2324 StrEndWith(get_rel_name(seqId), "_seq_identity");2325 StrEndWith(get_rel_name(seqId), "_seq_identity");
@@ -8735,14 +8736,13 @@ static void DropModifyColumnAutoIncrement(CreateStmtContext* cxt, Relation rel,
8735 return;8736 return;
8736 }8737 }
8737 DropStmt *drop = makeNode(DropStmt);8738 DropStmt *drop = makeNode(DropStmt);
8738- drop->removeType = OBJECT_LARGE_SEQUENCE;8739+ drop->removeType = OBJECT_LARGE_SEQUENCE_GSC;
8739 drop->missing_ok = true;8740 drop->missing_ok = true;
8740 drop->objects = list_make1(list_make1(makeString(seqname)));8741 drop->objects = list_make1(list_make1(makeString(seqname)));
8741 drop->arguments = NIL;8742 drop->arguments = NIL;
8742 drop->behavior = DROP_RESTRICT;8743 drop->behavior = DROP_RESTRICT;
8743 drop->concurrent = false;8744 drop->concurrent = false;
8744 drop->purge = false;8745 drop->purge = false;
8745-
8746 cxt->alist = lappend(cxt->alist, drop);8746 cxt->alist = lappend(cxt->alist, drop);
8747}8747}
8748 8748
@@ -2003,6 +2003,8 @@ Datum pg_relation_filenode(PG_FUNCTION_ARGS)
2003 case RELKIND_GLOBAL_INDEX:2003 case RELKIND_GLOBAL_INDEX:
2004 case RELKIND_SEQUENCE:2004 case RELKIND_SEQUENCE:
2005 case RELKIND_LARGE_SEQUENCE:2005 case RELKIND_LARGE_SEQUENCE:
2006+ case RELKIND_SEQUENCE_GSC:
2007+ case RELKIND_LARGE_SEQUENCE_GSC:
2006 case RELKIND_TOASTVALUE:2008 case RELKIND_TOASTVALUE:
2007 /* okay, these have storage */2009 /* okay, these have storage */
2008 if (relform->relfilenode)2010 if (relform->relfilenode)
@@ -2181,6 +2183,8 @@ Datum pg_relation_filepath(PG_FUNCTION_ARGS)
2181 case RELKIND_GLOBAL_INDEX:2183 case RELKIND_GLOBAL_INDEX:
2182 case RELKIND_SEQUENCE:2184 case RELKIND_SEQUENCE:
2183 case RELKIND_LARGE_SEQUENCE:2185 case RELKIND_LARGE_SEQUENCE:
2186+ case RELKIND_SEQUENCE_GSC:
2187+ case RELKIND_LARGE_SEQUENCE_GSC:
2184 case RELKIND_TOASTVALUE:2188 case RELKIND_TOASTVALUE:
2185 /* okay, these have storage */2189 /* okay, these have storage */
2186 2190 
@@ -13577,6 +13577,11 @@ static void deparse_sequence_options(List* options, StringInfoData& str, bool ow
13577 13577 
13578 appendStringInfo(&str, "%s.%s", quote_identifier(rel->relname), quote_identifier(attrname));13578 appendStringInfo(&str, "%s.%s", quote_identifier(rel->relname), quote_identifier(attrname));
13579 }13579 }
13580+ } else if (strcmp(defel->defname, "is_global") == 0) {
13581+ if (defGetBoolean(defel))
13582+ appendStringInfo(&str, " GLOBAL");
13583+ else
13584+ appendStringInfo(&str, " SESSION");
13580 } else {13585 } else {
13581 ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("option \"%s\" not recognized", defel->defname)));13586 ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("option \"%s\" not recognized", defel->defname)));
13582 }13587 }
@@ -5250,7 +5250,7 @@ void RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid, Multi
5250 classform->relfilenode = newrelfilenode;5250 classform->relfilenode = newrelfilenode;
5251 5251 
5252 /* relpages etc. never change for sequences */5252 /* relpages etc. never change for sequences */
5253- if (relation->rd_rel->relkind != RELKIND_SEQUENCE) {5253+ if (!RELKIND_IS_SEQUENCE(relation->rd_rel->relkind)) {
S
Ssuperlchf2月26日

这个逻辑再想想,就算RELKIND_IS_SEQUENCE不修改。他代表意思是 RELKIND_SEQUEN和RELKIND_LARGE_SEQUENCE的两个判断,左边表达式是只有对 RELKIND_SEQUEN的判断。显然本次修改增加了RELKIND_LARGE_SEQUENCE。

likedislike
sunquancheng
sunquancheng
6月24日 评论:
5254 classform->relpages = 0; /* it's empty until further notice */5254 classform->relpages = 0; /* it's empty until further notice */
5255 classform->reltuples = 0;5255 classform->reltuples = 0;
5256 classform->relallvisible = 0;5256 classform->relallvisible = 0;
@@ -5391,7 +5391,7 @@ DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
5391 ;5391 ;
5392 5392 
5393drop_type: TABLE { $$ = OBJECT_TABLE; }5393drop_type: TABLE { $$ = OBJECT_TABLE; }
5394- | SEQUENCE { $$ = OBJECT_SEQUENCE; }5394+ | SEQUENCE { $$ = OBJECT_SEQUENCE; }
5395 | VIEW { $$ = OBJECT_VIEW; }5395 | VIEW { $$ = OBJECT_VIEW; }
5396 | INDEX { $$ = OBJECT_INDEX; }5396 | INDEX { $$ = OBJECT_INDEX; }
5397 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }5397 | FOREIGN TABLE { $$ = OBJECT_FOREIGN_TABLE; }
@@ -398,6 +398,8 @@ ExecRenameStmt(RenameStmt *stmt)
398 case OBJECT_TABLE:398 case OBJECT_TABLE:
399 case OBJECT_SEQUENCE:399 case OBJECT_SEQUENCE:
400 case OBJECT_LARGE_SEQUENCE:400 case OBJECT_LARGE_SEQUENCE:
401+ case OBJECT_SEQUENCE_GSC:
402+ case OBJECT_LARGE_SEQUENCE_GSC:
401 case OBJECT_VIEW:403 case OBJECT_VIEW:
402 case OBJECT_CONTQUERY:404 case OBJECT_CONTQUERY:
403 case OBJECT_MATVIEW:405 case OBJECT_MATVIEW:
@@ -480,6 +482,8 @@ ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt* stmt, ObjectAddre
480 break;482 break;
481 case OBJECT_SEQUENCE:483 case OBJECT_SEQUENCE:
482 case OBJECT_LARGE_SEQUENCE:484 case OBJECT_LARGE_SEQUENCE:
485+ case OBJECT_SEQUENCE_GSC:
486+ case OBJECT_LARGE_SEQUENCE_GSC:
483 case OBJECT_TABLE:487 case OBJECT_TABLE:
484 case OBJECT_VIEW:488 case OBJECT_VIEW:
485 case OBJECT_CONTQUERY:489 case OBJECT_CONTQUERY:
@@ -58,6 +58,8 @@ static AclResult CheckObjectCommentPrivilege(const CommentStmt* stmt, Oid object
58 switch (stmt->objtype) {58 switch (stmt->objtype) {
59 case OBJECT_SEQUENCE:59 case OBJECT_SEQUENCE:
60 case OBJECT_LARGE_SEQUENCE:60 case OBJECT_LARGE_SEQUENCE:
61+ case OBJECT_SEQUENCE_GSC:
62+ case OBJECT_LARGE_SEQUENCE_GSC:
61 case OBJECT_TABLE:63 case OBJECT_TABLE:
62 case OBJECT_VIEW:64 case OBJECT_VIEW:
63 case OBJECT_MATVIEW:65 case OBJECT_MATVIEW:
@@ -201,6 +201,7 @@ static inline ObjElem* deparse_Seq_Minvalue(sequence_values *seqdata, bool alter
201static inline ObjElem* deparse_Seq_Maxvalue(sequence_values *seqdata, bool alter_table);201static inline ObjElem* deparse_Seq_Maxvalue(sequence_values *seqdata, bool alter_table);
202static inline ObjElem* deparse_Seq_Restart(char *last_value);202static inline ObjElem* deparse_Seq_Restart(char *last_value);
203static inline ObjElem* deparse_Seq_Startwith(sequence_values *seqdata, bool alter_table);203static inline ObjElem* deparse_Seq_Startwith(sequence_values *seqdata, bool alter_table);
204+static inline ObjElem* deparse_Seq_Global(sequence_values *seqdata, bool alter_table);
204static ObjElem* deparse_Seq_OwnedBy(Oid sequenceId);205static ObjElem* deparse_Seq_OwnedBy(Oid sequenceId);
205static inline ObjElem* deparse_Seq_Order(DefElem *elem);206static inline ObjElem* deparse_Seq_Order(DefElem *elem);
206static inline ObjElem* deparse_Seq_As(DefElem *elem);207static inline ObjElem* deparse_Seq_As(DefElem *elem);
@@ -948,8 +949,10 @@ const char* string_objtype(ObjectType objtype, bool isgrant)
948 case OBJECT_SCHEMA:949 case OBJECT_SCHEMA:
949 return "SCHEMA";950 return "SCHEMA";
950 case OBJECT_SEQUENCE:951 case OBJECT_SEQUENCE:
952+ case OBJECT_SEQUENCE_GSC:
951 return "SEQUENCE";953 return "SEQUENCE";
952 case OBJECT_LARGE_SEQUENCE:954 case OBJECT_LARGE_SEQUENCE:
955+ case OBJECT_LARGE_SEQUENCE_GSC:
953 return "LARGE SEQUENCE";956 return "LARGE SEQUENCE";
954 case OBJECT_TABLE:957 case OBJECT_TABLE:
955 return "TABLE";958 return "TABLE";
@@ -1997,6 +2000,29 @@ static inline ObjElem* deparse_Seq_Cycle(sequence_values *seqdata, bool alter_ta
1997 return new_object_object(ret);2000 return new_object_object(ret);
1998}2001}
1999 2002 
2003+/*
2004+ * Deparse the sequence GLOBAL option.
2005+ *
2006+ * Verbose syntax
2007+ * SET %{no}s GLOBAL
2008+ * OR
2009+ * %{no}s GLOBAL
2010+ */
2011+static inline ObjElem* deparse_Seq_Global(sequence_values *seqdata, bool alter_table)
2012+{
2013+ ObjTree *ret;
2014+ const char *fmt;
2015+ 
2016+ fmt = alter_table ? "SET %{no}s GLOBAL" : "%{no}s GLOBAL";
2017+ 
2018+ ret = new_objtree_VA(fmt, 2,
2019+ "clause", ObjTypeString, "cycle",
2020+ "no", ObjTypeString,
2021+ seqdata->is_global ? "" : "NO");
2022+ 
2023+ return new_object_object(ret);
2024+}
2025+ 
2000/*2026/*
2001 * Deparse the sequence INCREMENT BY option.2027 * Deparse the sequence INCREMENT BY option.
2002 *2028 *
@@ -2338,6 +2364,7 @@ static ObjTree* deparse_CreateSeqStmt(Oid objectId, Node *parsetree)
2338 elems = lappend(elems, deparse_Seq_Maxvalue(seqvalues, false));2364 elems = lappend(elems, deparse_Seq_Maxvalue(seqvalues, false));
2339 elems = lappend(elems, deparse_Seq_Startwith(seqvalues, false));2365 elems = lappend(elems, deparse_Seq_Startwith(seqvalues, false));
2340 elems = lappend(elems, deparse_Seq_Restart(seqvalues->last_value));2366 elems = lappend(elems, deparse_Seq_Restart(seqvalues->last_value));
2367+ elems = lappend(elems, deparse_Seq_Global(seqvalues, false));
2341 2368 
2342 /* We purposefully do not emit OWNED BY here */2369 /* We purposefully do not emit OWNED BY here */
2343 2370 
@@ -2406,6 +2433,8 @@ static ObjTree* deparse_AlterSeqStmt(Oid objectId, Node *parsetree)
2406 newelm = deparse_Seq_As(elem);2433 newelm = deparse_Seq_As(elem);
2407 else if (strcmp(elem->defname, "order") == 0)2434 else if (strcmp(elem->defname, "order") == 0)
2408 newelm = deparse_Seq_Order(elem);2435 newelm = deparse_Seq_Order(elem);
2436+ else if (strcmp(elem->defname, "is_global") == 0)
2437+ newelm = deparse_Seq_Global(seqvalues, false);
2409 else2438 else
2410 elog(WARNING, "unsupport sequence option %s for replication", elem->defname);2439 elog(WARNING, "unsupport sequence option %s for replication", elem->defname);
2411 2440 
@@ -2532,6 +2561,8 @@ static ObjTree* deparse_RenameStmt(ObjectAddress address, Node *parsetree)
2532 case OBJECT_INDEX:2561 case OBJECT_INDEX:
2533 case OBJECT_SEQUENCE:2562 case OBJECT_SEQUENCE:
2534 case OBJECT_LARGE_SEQUENCE:2563 case OBJECT_LARGE_SEQUENCE:
2564+ case OBJECT_SEQUENCE_GSC:
2565+ case OBJECT_LARGE_SEQUENCE_GSC:
2535 case OBJECT_VIEW:2566 case OBJECT_VIEW:
2536 case OBJECT_MATVIEW:2567 case OBJECT_MATVIEW:
2537 relation = relation_open(address.objectId, AccessShareLock);2568 relation = relation_open(address.objectId, AccessShareLock);
@@ -3904,9 +3935,11 @@ static ObjTree* deparse_AlterRelation(CollectedCommand *cmd, ddl_deparse_context
3904 break;3935 break;
3905 3936 
3906 case RELKIND_SEQUENCE:3937 case RELKIND_SEQUENCE:
3938+ case RELKIND_SEQUENCE_GSC:
3907 reltype = "SEQUENCE";3939 reltype = "SEQUENCE";
3908 break;3940 break;
3909 case RELKIND_LARGE_SEQUENCE:3941 case RELKIND_LARGE_SEQUENCE:
3942+ case RELKIND_LARGE_SEQUENCE_GSC:
3910 reltype = "LARGE SEQUENCE";3943 reltype = "LARGE SEQUENCE";
3911 break;3944 break;
3912 default:3945 default:
@@ -1058,6 +1058,7 @@ bool EventTriggerSupportsObjectType(ObjectType obtype)
1058 case OBJECT_LANGUAGE:1058 case OBJECT_LANGUAGE:
1059 case OBJECT_LARGEOBJECT:1059 case OBJECT_LARGEOBJECT:
1060 case OBJECT_LARGE_SEQUENCE:1060 case OBJECT_LARGE_SEQUENCE:
1061+ case OBJECT_LARGE_SEQUENCE_GSC:
1061 case OBJECT_MATVIEW:1062 case OBJECT_MATVIEW:
1062 case OBJECT_OPCLASS:1063 case OBJECT_OPCLASS:
1063 case OBJECT_OPERATOR:1064 case OBJECT_OPERATOR:
@@ -1065,8 +1066,9 @@ bool EventTriggerSupportsObjectType(ObjectType obtype)
1065 case OBJECT_RULE:1066 case OBJECT_RULE:
1066 case OBJECT_SCHEMA:1067 case OBJECT_SCHEMA:
1067 case OBJECT_SEQUENCE:1068 case OBJECT_SEQUENCE:
1069+ case OBJECT_SEQUENCE_GSC:
1068 case OBJECT_TABLE:1070 case OBJECT_TABLE:
1069- case OBJECT_TABCONSTRAINT: 1071+ case OBJECT_TABCONSTRAINT:
1070 case OBJECT_TRIGGER:1072 case OBJECT_TRIGGER:
1071 case OBJECT_TSCONFIGURATION:1073 case OBJECT_TSCONFIGURATION:
1072 case OBJECT_TSDICTIONARY:1074 case OBJECT_TSDICTIONARY:
@@ -213,6 +213,9 @@ static void AddAllDDLReplicaEventTriggers(List *end_commands)
213 end_commands = lappend(end_commands, makeString("CREATE SEQUENCE"));213 end_commands = lappend(end_commands, makeString("CREATE SEQUENCE"));
214 end_commands = lappend(end_commands, makeString("ALTER SEQUENCE"));214 end_commands = lappend(end_commands, makeString("ALTER SEQUENCE"));
215 end_commands = lappend(end_commands, makeString("DROP SEQUENCE"));215 end_commands = lappend(end_commands, makeString("DROP SEQUENCE"));
216+ end_commands = lappend(end_commands, makeString("CREATE LARGE SEQUENCE"));
217+ end_commands = lappend(end_commands, makeString("ALTER LARGE SEQUENCE"));
218+ end_commands = lappend(end_commands, makeString("DROP LARGE SEQUENCE"));
216 end_commands = lappend(end_commands, makeString("CREATE SCHEMA"));219 end_commands = lappend(end_commands, makeString("CREATE SCHEMA"));
217 end_commands = lappend(end_commands, makeString("ALTER SCHEMA"));220 end_commands = lappend(end_commands, makeString("ALTER SCHEMA"));
218 end_commands = lappend(end_commands, makeString("DROP SCHEMA"));221 end_commands = lappend(end_commands, makeString("DROP SCHEMA"));
@@ -137,7 +137,10 @@ void ResetvalGlobal(Oid relid)
137 GlobalSeqInfoHashBucket* bucket = NULL;137 GlobalSeqInfoHashBucket* bucket = NULL;
138 uint32 hash = RelidGetHash(relid);138 uint32 hash = RelidGetHash(relid);
139 139 
140- bucket = &g_instance.global_seq[hash];140+ if (g_instance.seqHtbl == NULL || !g_instance.global_seq_inited) {
141+ return;
142+ }
143+ bucket = &g_instance.seqHtbl->global_seq[hash];
141 144 
142 (void)LWLockAcquire(GetMainLWLockByIndex(bucket->lock_id), LW_EXCLUSIVE);145 (void)LWLockAcquire(GetMainLWLockByIndex(bucket->lock_id), LW_EXCLUSIVE);
143 146 
@@ -234,6 +237,163 @@ void init_sequence(Oid relid, SeqTable* p_elm, Relation* p_rel)
234 *p_rel = seqrel;237 *p_rel = seqrel;
235}238}
236 239 
240+SeqTable searchGlobalSequenceCacheFromHashTab(GSCKey* key, uint32 hashCode, uint32 bucket_id)
241+{
242+ GSCEntry *entry = NULL;
243+ Assert (bucket_id >= 0 && bucket_id < NUM_GSC_SINGLENODE_PARTITIONS);
244+ bool found = false;
245+ entry = (GSCEntry *)hash_search_with_hash_value(g_instance.seqHtbl->global_seqtab[bucket_id].hash_tbl,
246+ (const void*)key, hashCode, HASH_ENTER, &found);
247+ if (entry == NULL) {
248+ ereport(ERROR,
249+ (errcode(ERRCODE_UNDEFINED_PSTATEMENT),
250+ errmsg("store global sequence cache failed due to memory allocation failed")));
251+ }
252+ 
253+ if (found == false) {
254+ errno_t rc = EOK;
255+ rc = memset_s(entry, sizeof(GSCEntry), 0, sizeof(GSCEntry));
256+ securec_check(rc, "\0", "\0");
257+ entry->key.dbOid = key->dbOid;
258+ entry->key.relid = key->relid;
259+ entry->val.elm.relid = key->relid;
260+ entry->val.elm.dbOid = key->dbOid;
261+ entry->val.elm.is_global_cache = true;
262+ 
263+ /*
264+ * Open the sequence relation.
265+ */
266+ Relation seqrel = lock_and_open_seq(&(entry->val.elm));
267+ if (!RELKIND_IS_SEQUENCE(seqrel->rd_rel->relkind)) {
268+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
269+ errmsg("\"%s.%s\" is not a sequence", get_namespace_name(RelationGetNamespace(seqrel)),
270+ RelationGetRelationName(seqrel))));
271+ } else {
272+ entry->val.elm.seqkind = seqrel->rd_rel->relkind;
273+ }
274+ relation_close(seqrel, NoLock);
275+ }
276+ return &(entry->val.elm);
277+}
278+ 
279+/*
280+ * Given a relation OID, open and lock the sequence. p_elm and p_rel are
281+ * output parameters, and p_elm is global sequence cache elm.
282+ */
283+void init_sequence_single_node_global_cache(Oid relid, SeqTable* elm, Relation* rel, GSCKey* key, uint32 hashCode,
284+ uint32 bucketId)
285+{
286+ SeqTable tbl = NULL;
287+ Relation seqrel;
288+ 
289+ tbl = searchGlobalSequenceCacheFromHashTab(key, hashCode, bucketId);
290+ if (rel != NULL) {
291+ /*
292+ * Open the sequence relation.
293+ */
294+ seqrel = lock_and_open_seq(tbl);
295+ if (!RELKIND_IS_SEQUENCE(seqrel->rd_rel->relkind)) {
296+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
297+ errmsg("\"%s.%s\" is not a sequence", get_namespace_name(RelationGetNamespace(seqrel)),
298+ RelationGetRelationName(seqrel))));
299+ }
300+ *rel = seqrel;
301+ }
302+ 
303+ *elm = tbl;
304+}
305+ 
306+/*
307+ * Given a relation OID, open and lock the sequence. p_elm and p_rel are
308+ * output parameters, and p_elm is global sequence cache elm for currval.
309+ */
310+void init_sequence_single_node_global_cache_for_currval(Oid relid, SeqTable* elm, Relation* rel)
311+{
312+ SeqTable tbl = NULL;
313+ Relation seqrel;
314+ DListCell* elem_tmp = NULL;
315+ SeqTable currseq = NULL;
316+ 
317+ dlist_foreach_cell(elem_tmp, u_sess->cmd_cxt.global_currval_seq)
318+ {
319+ currseq = (SeqTable)lfirst(elem_tmp);
320+ if (currseq->relid == relid && currseq->dbOid == u_sess->proc_cxt.MyDatabaseId) {
321+ tbl = currseq;
322+ break;
323+ }
324+ }
325+ 
326+ /*
327+ * Allocate new seqtable entry if we didn't find one.
328+ *
329+ * NOTE: seqtable entries remain in the list for the life of a backend. If
330+ * the sequence itself is deleted then the entry becomes wasted memory,
331+ * but it's small enough that this should not matter.
332+ */
333+ if (tbl == NULL) {
334+ /*
335+ * Time to make a new seqtable entry. These entries live as long as
336+ * the backend does, so we use plain malloc for them.
337+ */
338+ tbl = (SeqTable)MemoryContextAlloc(
339+ SESS_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_OPTIMIZER), sizeof(SeqTableData));
340+ errno_t rc = EOK;
341+ rc = memset_s(tbl, sizeof(SeqTableData), 0, sizeof(SeqTableData));
342+ securec_check(rc, "\0", "\0");
343+ tbl->relid = relid;
344+ tbl->dbOid = u_sess->proc_cxt.MyDatabaseId;
345+ 
346+ MemoryContext oldcontext = MemoryContextSwitchTo(SESS_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_OPTIMIZER));
347+ u_sess->cmd_cxt.global_currval_seq = dlappend(u_sess->cmd_cxt.global_currval_seq, tbl);
348+ (void)MemoryContextSwitchTo(oldcontext);
349+ }
350+ 
351+ /*
352+ * Open the sequence relation.
353+ */
354+ seqrel = lock_and_open_seq(tbl);
355+ if (!RELKIND_IS_SEQUENCE(seqrel->rd_rel->relkind)) {
356+ if (seqrel->rd_rel->relpersistence == RELPERSISTENCE_TEMP) {
357+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
358+ errmsg("\"%s.%s\" is not a sequence", get_namespace_name(RelationGetNamespace(seqrel)),
359+ RelationGetRelationName(seqrel)),
360+ errdetail("Please make sure using the correct schema")));
361+ } else {
362+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
363+ errmsg("\"%s.%s\" is not a sequence", get_namespace_name(RelationGetNamespace(seqrel)),
364+ RelationGetRelationName(seqrel))));
365+ }
366+ }
367+ /*
368+ * If the sequence has been transactionally replaced since we last saw it,
369+ * discard any cached-but-unissued values. We do not touch the currval()
370+ * state, however.
371+ */
372+ if (seqrel->rd_rel->relfilenode != tbl->filenode) {
373+ tbl->filenode = seqrel->rd_rel->relfilenode;
374+ errno_t rc = memcpy_s(&(tbl->cached), sizeof(int128), &(tbl->last), sizeof(int128));
375+ securec_check(rc, "\0", "\0");
376+ }
377+ 
378+ /* Return results */
379+ *elm = tbl;
380+ *rel = seqrel;
381+}
382+ 
383+/* for global sequence cache record currval elm */
384+void global_sequence_cache_set_currval_elm(Oid relid, int128 value)
385+{
386+ SeqTable elm = NULL;
387+ Relation seqrel;
388+ 
389+ /* open and lock sequence */
390+ init_sequence_single_node_global_cache_for_currval(relid, &elm, &seqrel);
391+ 
392+ elm->last = value;
393+ elm->last_valid = true;
394+ relation_close(seqrel, NoLock);
395+}
396+ 
237SeqTable GetSessSeqElm(Oid relid)397SeqTable GetSessSeqElm(Oid relid)
238{398{
239 SeqTable elm = NULL;399 SeqTable elm = NULL;
@@ -357,12 +517,43 @@ bool IsTempSequence(Oid relid)
357 Relation seqrel;517 Relation seqrel;
358 bool res = false;518 bool res = false;
359 SeqTable elm = NULL;519 SeqTable elm = NULL;
520+ uint32 hashCode;
521+ GSCKey key;
522+ uint32 bucket_id;
360 523 
361- /* open and lock sequence */524+ bool isGlobalCache = is_global_level_sequence_cache(relid);
362- init_sequence(relid, &elm, &seqrel);525+ if (isGlobalCache) {
526+ /* lock the destination bucket to obtain the global cache */
527+ key.dbOid = u_sess->proc_cxt.MyDatabaseId;
528+ key.relid = relid;
529+ hashCode = GSCHashFunc<GSCKey>((const void *) &key, sizeof(GSCKey));
530+ bucket_id = GetGSCBucket(hashCode);
531+ (void)LWLockAcquire(GetMainLWLockByIndex(g_instance.seqHtbl->global_seqtab[bucket_id].lock_id), LW_EXCLUSIVE);
532+ }
363 533 
364- res = RelationIsLocalTemp(seqrel);534+ PG_TRY();
365- relation_close(seqrel, NoLock);535+ {
536+ if (isGlobalCache) {
537+ init_sequence_single_node_global_cache(relid, &elm, &seqrel, &key, hashCode, bucket_id);
538+ } else {
539+ init_sequence(relid, &elm, &seqrel);
540+ }
541+ 
542+ res = RelationIsLocalTemp(seqrel);
543+ relation_close(seqrel, NoLock);
544+ 
545+ if (isGlobalCache) {
546+ LWLockRelease(GetMainLWLockByIndex(g_instance.seqHtbl->global_seqtab[bucket_id].lock_id));
547+ }
548+ }
549+ PG_CATCH();
550+ {
551+ if (isGlobalCache) {
552+ LWLockRelease(GetMainLWLockByIndex(g_instance.seqHtbl->global_seqtab[bucket_id].lock_id));
553+ }
554+ PG_RE_THROW();
555+ }
556+ PG_END_TRY();
366 return res;557 return res;
367}558}
368#endif559#endif
@@ -286,12 +286,24 @@ static const struct dropmsgstrings dropmsgstringarray[] = {{RELKIND_RELATION,
286 gettext_noop("sequence \"%s\" does not exist, skipping"),286 gettext_noop("sequence \"%s\" does not exist, skipping"),
287 gettext_noop("\"%s\" is not a sequence"),287 gettext_noop("\"%s\" is not a sequence"),
288 gettext_noop("Use DROP SEQUENCE to remove a sequence.")},288 gettext_noop("Use DROP SEQUENCE to remove a sequence.")},
289+ {RELKIND_SEQUENCE_GSC,
290+ ERRCODE_UNDEFINED_TABLE,
291+ gettext_noop("sequence \"%s\" does not exist"),
292+ gettext_noop("sequence \"%s\" does not exist, skipping"),
293+ gettext_noop("\"%s\" is not a sequence"),
294+ gettext_noop("Use DROP SEQUENCE to remove a sequence.")},
289 {RELKIND_LARGE_SEQUENCE,295 {RELKIND_LARGE_SEQUENCE,
290 ERRCODE_UNDEFINED_TABLE,296 ERRCODE_UNDEFINED_TABLE,
291 gettext_noop("large sequence \"%s\" does not exist"),297 gettext_noop("large sequence \"%s\" does not exist"),
292 gettext_noop("large sequence \"%s\" does not exist, skipping"),298 gettext_noop("large sequence \"%s\" does not exist, skipping"),
293 gettext_noop("\"%s\" is not a large sequence"),299 gettext_noop("\"%s\" is not a large sequence"),
294 gettext_noop("Use DROP LARGE SEQUENCE to remove a large sequence.")},300 gettext_noop("Use DROP LARGE SEQUENCE to remove a large sequence.")},
301+ {RELKIND_LARGE_SEQUENCE_GSC,
302+ ERRCODE_UNDEFINED_TABLE,
303+ gettext_noop("large sequence \"%s\" does not exist"),
304+ gettext_noop("large sequence \"%s\" does not exist, skipping"),
305+ gettext_noop("\"%s\" is not a large sequence"),
306+ gettext_noop("Use DROP LARGE SEQUENCE to remove a large sequence.")},
295 {RELKIND_VIEW,307 {RELKIND_VIEW,
296 ERRCODE_UNDEFINED_TABLE,308 ERRCODE_UNDEFINED_TABLE,
297 gettext_noop("view \"%s\" does not exist"),309 gettext_noop("view \"%s\" does not exist"),
@@ -398,7 +410,7 @@ typedef OldToNewChunkIdMappingData* OldToNewChunkIdMapping;
398#define MLOG_MAP_SUPPORT_AT_CMD(cmd) ((cmd) == AT_SubCluster)410#define MLOG_MAP_SUPPORT_AT_CMD(cmd) ((cmd) == AT_SubCluster)
399 411 
400#define HDFS_TBLSPC_SUPPORT_CREATE_LOGIC_OBJECT(kind) \412#define HDFS_TBLSPC_SUPPORT_CREATE_LOGIC_OBJECT(kind) \
401- ((kind) == RELKIND_VIEW || (kind) == RELKIND_FOREIGN_TABLE || (kind) == RELKIND_SEQUENCE || \413+ ((kind) == RELKIND_VIEW || (kind) == RELKIND_FOREIGN_TABLE || (kind) == RELKIND_SEQUENCE || (kind) == RELKIND_SEQUENCE_GSC || \
402 (kind) == RELKIND_COMPOSITE_TYPE || (kind) == RELKIND_STREAM || (kind) == RELKIND_CONTQUERY)414 (kind) == RELKIND_COMPOSITE_TYPE || (kind) == RELKIND_STREAM || (kind) == RELKIND_CONTQUERY)
403 415 
404#define PARTITION_DDL_CMD(cmd) \416#define PARTITION_DDL_CMD(cmd) \
@@ -2402,8 +2414,7 @@ ObjectAddress DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId, Object
2402 if (aclresult != ACLCHECK_OK)2414 if (aclresult != ACLCHECK_OK)
2403 aclcheck_error(aclresult, ACL_KIND_TABLESPACE, get_tablespace_name(tablespaceId));2415 aclcheck_error(aclresult, ACL_KIND_TABLESPACE, get_tablespace_name(tablespaceId));
2404 /* view and sequence are not related to tablespace, so no need to check permissions */2416 /* view and sequence are not related to tablespace, so no need to check permissions */
2405- if (isalter && relkind != RELKIND_VIEW && relkind != RELKIND_CONTQUERY &&2417+ if (isalter && relkind != RELKIND_VIEW && relkind != RELKIND_CONTQUERY && !RELKIND_IS_SEQUENCE(relkind)) {
2406- relkind != RELKIND_SEQUENCE && relkind != RELKIND_LARGE_SEQUENCE) {
2407 aclresult = pg_tablespace_aclcheck(tablespaceId, ownerId, ACL_CREATE);2418 aclresult = pg_tablespace_aclcheck(tablespaceId, ownerId, ACL_CREATE);
2408 if (aclresult != ACLCHECK_OK)2419 if (aclresult != ACLCHECK_OK)
2409 aclcheck_error(aclresult, ACL_KIND_TABLESPACE, get_tablespace_name(tablespaceId));2420 aclcheck_error(aclresult, ACL_KIND_TABLESPACE, get_tablespace_name(tablespaceId));
@@ -3479,11 +3490,19 @@ ObjectAddresses* PreCheckforRemoveRelation(DropStmt* drop, StringInfo tmp_queryS
3479 relkind = RELKIND_SEQUENCE;3490 relkind = RELKIND_SEQUENCE;
3480 relkind_s = "SEQUENCE";3491 relkind_s = "SEQUENCE";
3481 break;3492 break;
3493+ case OBJECT_SEQUENCE_GSC:
3494+ relkind = RELKIND_SEQUENCE_GSC;
3495+ relkind_s = "SEQUENCE";
3496+ break;
3482 3497 
3483 case OBJECT_LARGE_SEQUENCE:3498 case OBJECT_LARGE_SEQUENCE:
3484 relkind = RELKIND_LARGE_SEQUENCE;3499 relkind = RELKIND_LARGE_SEQUENCE;
3485 relkind_s = "LARGE SEQUENCE";3500 relkind_s = "LARGE SEQUENCE";
3486 break;3501 break;
3502+ case OBJECT_LARGE_SEQUENCE_GSC:
3503+ relkind = RELKIND_LARGE_SEQUENCE_GSC;
3504+ relkind_s = "LARGE SEQUENCE";
3505+ break;
3487 3506 
3488 case OBJECT_VIEW:3507 case OBJECT_VIEW:
3489 relkind = RELKIND_VIEW;3508 relkind = RELKIND_VIEW;
@@ -3719,6 +3738,7 @@ void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExec
3719 StringInfo relation_namelist = makeStringInfo();3738 StringInfo relation_namelist = makeStringInfo();
3720 char relPersistence;3739 char relPersistence;
3721 List *typlist = NULL;3740 List *typlist = NULL;
3741+ List *seqOids = NIL;
3722 3742 
3723 /* DROP CONCURRENTLY uses a weaker lock, and has some restrictions */3743 /* DROP CONCURRENTLY uses a weaker lock, and has some restrictions */
3724 if (drop->concurrent) {3744 if (drop->concurrent) {
@@ -3754,11 +3774,19 @@ void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExec
3754 relkind = RELKIND_SEQUENCE;3774 relkind = RELKIND_SEQUENCE;
3755 relkind_s = "SEQUENCE";3775 relkind_s = "SEQUENCE";
3756 break;3776 break;
3777+ case OBJECT_SEQUENCE_GSC:
3778+ relkind = RELKIND_SEQUENCE_GSC;
3779+ relkind_s = "SEQUENCE";
3780+ break;
3757 3781 
3758 case OBJECT_LARGE_SEQUENCE:3782 case OBJECT_LARGE_SEQUENCE:
3759 relkind = RELKIND_LARGE_SEQUENCE;3783 relkind = RELKIND_LARGE_SEQUENCE;
3760 relkind_s = "LARGE SEQUENCE";3784 relkind_s = "LARGE SEQUENCE";
3761 break;3785 break;
3786+ case OBJECT_LARGE_SEQUENCE_GSC:
3787+ relkind = RELKIND_LARGE_SEQUENCE_GSC;
3788+ relkind_s = "LARGE SEQUENCE";
3789+ break;
3762 3790 
3763 case OBJECT_VIEW:3791 case OBJECT_VIEW:
3764 relkind = RELKIND_VIEW;3792 relkind = RELKIND_VIEW;
@@ -3864,6 +3892,14 @@ void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExec
3864 relOid = RangeVarGetRelidExtended(3892 relOid = RangeVarGetRelidExtended(
3865 rel, lockmode, true, false, false, false, RangeVarCallbackForDropRelation, (void*)&state);3893 rel, lockmode, true, false, false, false, RangeVarCallbackForDropRelation, (void*)&state);
3866 3894 
3895+ /* record sequence reloid if drop sequence */
3896+ if (OBJECT_IS_SEQUENCE(drop->removeType)) {
3897+ SeqDropCacheInfo *info = (SeqDropCacheInfo*)palloc(sizeof(SeqDropCacheInfo));
3898+ info->relid = relOid;
3899+ info->is_global_cache = is_global_level_sequence_cache(relOid);
3900+ seqOids = lappend(seqOids, info);
3901+ }
3902+ 
3867 /*3903 /*
3868 * Relation not found.3904 * Relation not found.
3869 *3905 *
@@ -3907,9 +3943,10 @@ void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExec
3907#endif /* ENABLE_MULTIPLE_NODES */3943#endif /* ENABLE_MULTIPLE_NODES */
3908 if (relkind == RELKIND_RELATION) {3944 if (relkind == RELKIND_RELATION) {
3909 DeleteUidEntry(relOid);3945 DeleteUidEntry(relOid);
3910- } else if (relkind == RELKIND_LARGE_SEQUENCE && CheckSeqOwnedByAutoInc(relOid)) {3946+ } else if ((relkind == RELKIND_LARGE_SEQUENCE || relkind == RELKIND_LARGE_SEQUENCE_GSC) &&
3947+ CheckSeqOwnedByAutoInc(relOid)) {
3911 ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),3948 ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3912- errmsg("cannot drop sequence owned by auto_increment column")));3949+ errmsg("cannot drop sequence owned by auto_increment column")));
3913 }3950 }
3914 3951 
3915 delrel = try_relation_open(relOid, NoLock);3952 delrel = try_relation_open(relOid, NoLock);
@@ -4009,6 +4046,12 @@ void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExec
4009 performMultipleDeletions(objects, drop->behavior, flags);4046 performMultipleDeletions(objects, drop->behavior, flags);
4010 }4047 }
4011 4048 
4049+ /* drop global sequence cache after drop sequence */
4050+ if (seqOids != NULL && OBJECT_IS_SEQUENCE(drop->removeType)) {
4051+ removeSequenceCacheOfRelOid(seqOids);
wofanzheng
wofanzhengwofanzheng5月14日

【问题】这里把 removeSequenceCacheOfRelOid(seqOids) 放在 performMultipleDeletions() 之后。对“从未调用过 nextval/currval/alter 的 global sequence”,relid2cachelevel 里还没有缓存项,removeSequenceCacheOfRelOid() 会再次调用 is_global_level_sequence_cache(relOid),继续走到 get_cache_level_from_oid(relOid) 打开已经删除的 relation。这样 DROP SEQUENCE 会在对象已经删除后因为清理路径再次报错。 【建议】建议在真正删除前先把每个 sequence 的 cache level 记录下来,或者把 sequence cache 清理移动到 performMultipleDeletions() 之前执行;总之不要在 post-drop 阶段再依赖 relOid 回查 catalog。 代码参考:

typedef struct SeqDropCacheInfo {
    Oid relid;
    bool is_global_cache;
} SeqDropCacheInfo;

/* performMultipleDeletions() 之前 */
info->is_global_cache = is_global_level_sequence_cache(relOid);

/* performMultipleDeletions() 之后 */
if (info->is_global_cache) {
    removeGlobalSeqCache_internal(info->relid);
    removeGlobalSeqCacheForCurrval_internal(info->relid);
} else {
    removeSessionSeqScache_internal(info->relid);
}
likedislike
sunquancheng
sunquancheng
5月25日 评论:
4052+ list_free(seqOids);
4053+ }
4054+ 
4012 free_object_addresses(objects);4055 free_object_addresses(objects);
4013 pfree_ext(relation_namelist->data);4056 pfree_ext(relation_namelist->data);
4014 pfree_ext(relation_namelist);4057 pfree_ext(relation_namelist);
@@ -11194,7 +11237,9 @@ static void ATSimplePermissions(Relation rel, int allowed_targets)
11194 actual_target = ATT_FOREIGN_TABLE;11237 actual_target = ATT_FOREIGN_TABLE;
11195 break;11238 break;
11196 case RELKIND_SEQUENCE:11239 case RELKIND_SEQUENCE:
11197- case RELKIND_LARGE_SEQUENCE: {11240+ case RELKIND_LARGE_SEQUENCE:
11241+ case RELKIND_SEQUENCE_GSC:
11242+ case RELKIND_LARGE_SEQUENCE_GSC: {
11198 if (u_sess->attr.attr_common.IsInplaceUpgrade) {11243 if (u_sess->attr.attr_common.IsInplaceUpgrade) {
11199 actual_target = ATT_SEQUENCE;11244 actual_target = ATT_SEQUENCE;
11200 } else11245 } else
@@ -19367,6 +19412,8 @@ void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE
19367 break;19412 break;
19368 case RELKIND_SEQUENCE:19413 case RELKIND_SEQUENCE:
19369 case RELKIND_LARGE_SEQUENCE:19414 case RELKIND_LARGE_SEQUENCE:
19415+ case RELKIND_SEQUENCE_GSC:
19416+ case RELKIND_LARGE_SEQUENCE_GSC:
19370 if (!recursing && tuple_class->relowner != newOwnerId) {19417 if (!recursing && tuple_class->relowner != newOwnerId) {
19371 /* if it's an owned sequence, disallow changing it by itself */19418 /* if it's an owned sequence, disallow changing it by itself */
19372 Oid tableId;19419 Oid tableId;
@@ -24372,10 +24419,16 @@ static void RangeVarCallbackForAlterRelation(
24372 if (reltype == OBJECT_SEQUENCE && relkind != RELKIND_SEQUENCE) {24419 if (reltype == OBJECT_SEQUENCE && relkind != RELKIND_SEQUENCE) {
24373 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a sequence", rv->relname)));24420 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a sequence", rv->relname)));
24374 }24421 }
24422+ if (reltype == OBJECT_SEQUENCE_GSC && relkind != RELKIND_SEQUENCE_GSC) {
24423+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a sequence", rv->relname)));
24424+ }
24375 24425 
24376 if (reltype == OBJECT_LARGE_SEQUENCE && relkind != RELKIND_LARGE_SEQUENCE) {24426 if (reltype == OBJECT_LARGE_SEQUENCE && relkind != RELKIND_LARGE_SEQUENCE) {
24377 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a large sequence", rv->relname)));24427 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a large sequence", rv->relname)));
24378 }24428 }
24429+ if (reltype == OBJECT_LARGE_SEQUENCE_GSC && relkind != RELKIND_LARGE_SEQUENCE_GSC) {
24430+ ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a large sequence", rv->relname)));
24431+ }
24379 24432 
24380 if (reltype == OBJECT_VIEW && relkind != RELKIND_VIEW && relkind != RELKIND_CONTQUERY) {24433 if (reltype == OBJECT_VIEW && relkind != RELKIND_VIEW && relkind != RELKIND_CONTQUERY) {
24381 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a view", rv->relname)));24434 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a view", rv->relname)));
@@ -32428,10 +32481,16 @@ void DropTableThrowErrorExternal(RangeVar* relation, ObjectType removeType, bool
32428 case OBJECT_SEQUENCE:32481 case OBJECT_SEQUENCE:
32429 relkind = RELKIND_SEQUENCE;32482 relkind = RELKIND_SEQUENCE;
32430 break;32483 break;
32484+ case OBJECT_SEQUENCE_GSC:
32485+ relkind = RELKIND_SEQUENCE_GSC;
32486+ break;
32431 32487 
32432 case OBJECT_LARGE_SEQUENCE:32488 case OBJECT_LARGE_SEQUENCE:
32433 relkind = RELKIND_LARGE_SEQUENCE;32489 relkind = RELKIND_LARGE_SEQUENCE;
32434 break;32490 break;
32491+ case OBJECT_LARGE_SEQUENCE_GSC:
32492+ relkind = RELKIND_LARGE_SEQUENCE_GSC;
32493+ break;
32435 32494 
32436 case OBJECT_VIEW:32495 case OBJECT_VIEW:
32437 relkind = RELKIND_VIEW;32496 relkind = RELKIND_VIEW;
@@ -34353,9 +34412,6 @@ void CheckDropViewValidity(ObjectType stmtType, char relKind, const char* relnam
34353 case OBJECT_SEQUENCE:34412 case OBJECT_SEQUENCE:
34354 expectedRelKind = RELKIND_SEQUENCE;34413 expectedRelKind = RELKIND_SEQUENCE;
34355 break;34414 break;
34356- case OBJECT_LARGE_SEQUENCE:
34357- expectedRelKind = RELKIND_LARGE_SEQUENCE;
34358- break;
34359 case OBJECT_MATVIEW:34415 case OBJECT_MATVIEW:
34360 expectedRelKind = RELKIND_MATVIEW;34416 expectedRelKind = RELKIND_MATVIEW;
34361 break;34417 break;
@@ -34440,7 +34496,11 @@ int128 EvaluateAutoIncrement(Relation rel, TupleDesc desc, AttrNumber attnum, Da
34440 if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP) {34496 if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP) {
34441 autoinc = tmptable_autoinc_nextval(rel->rd_rel->relfilenode, cons_autoinc->next);34497 autoinc = tmptable_autoinc_nextval(rel->rd_rel->relfilenode, cons_autoinc->next);
34442 } else {34498 } else {
34443- autoinc = nextval_internal(cons_autoinc->seqoid);34499+ if (is_global_level_sequence_cache(cons_autoinc->seqoid)) {
34500+ autoinc = nextval_internal_for_global_seq_cache(cons_autoinc->seqoid);
34501+ } else {
34502+ autoinc = nextval_internal(cons_autoinc->seqoid);
34503+ }
34444 }34504 }
34445 if (modify_value) {34505 if (modify_value) {
34446 *is_null = false;34506 *is_null = false;
@@ -5541,7 +5541,8 @@ char* GetCreateTableStmt(Query* parsetree, CreateTableAsStmt* stmt)
5541 bool cycle = false;5541 bool cycle = false;
5542 5542 
5543 Relation relseq = relation_open(seqId, AccessShareLock);5543 Relation relseq = relation_open(seqId, AccessShareLock);
5544- bool large = (get_rel_relkind(seqId) == RELKIND_LARGE_SEQUENCE);5544+ char relkind = get_rel_relkind(seqId);
5545+ bool large = (relkind == RELKIND_LARGE_SEQUENCE || relkind == RELKIND_LARGE_SEQUENCE_GSC);
5545 get_sequence_params(relseq, &uuid, &start, &increment,5546 get_sequence_params(relseq, &uuid, &start, &increment,
5546 &maxvalue, &minvalue, &cachevalue, &cycle, large);5547 &maxvalue, &minvalue, &cachevalue, &cycle, large);
5547 relation_close(relseq, AccessShareLock);5548 relation_close(relseq, AccessShareLock);
@@ -971,6 +971,18 @@ void get_relation_info(PlannerInfo* root, RangeTblEntry* rte, RelOptInfo* rel)
971 971 
972bool is_table_vacuumed_or_analyzed(Oid relid)972bool is_table_vacuumed_or_analyzed(Oid relid)
973{973{
974+ /*
975+ * Safety guard: if pg_statistic_history hasn't been created yet
976+ * (e.g. upgrade path skipped version 93_033, or inplace upgrade in progress),
977+ * return false to avoid "could not open relation with OID 4885" errors.
978+ */
979+ if (u_sess->attr.attr_common.IsInplaceUpgrade)
980+ return false;
981+ HeapTuple reltup = SearchSysCache1(RELOID, ObjectIdGetDatum(StatisticHistoryRelationId));
982+ if (!HeapTupleIsValid(reltup))
983+ return false;
984+ ReleaseSysCache(reltup);
985+ 
974 Relation pgstahis = NULL;986 Relation pgstahis = NULL;
975 SysScanDesc scan = NULL;987 SysScanDesc scan = NULL;
976 ScanKeyData key[1];988 ScanKeyData key[1];
@@ -1213,6 +1225,8 @@ void estimate_rel_size(Relation rel, int32* attr_widths, RelPageType* pages, dou
1213 break;1225 break;
1214 case RELKIND_SEQUENCE:1226 case RELKIND_SEQUENCE:
1215 case RELKIND_LARGE_SEQUENCE:1227 case RELKIND_LARGE_SEQUENCE:
1228+ case RELKIND_SEQUENCE_GSC:
1229+ case RELKIND_LARGE_SEQUENCE_GSC:
1216 /* Sequences always have a known size */1230 /* Sequences always have a known size */
1217 *pages = 1;1231 *pages = 1;
1218 *tuples = 1;1232 *tuples = 1;
@@ -1195,7 +1195,9 @@ static void pgaudit_process_drop_objects(Node* node, const char* querystring)
1195 pgaudit_ddl_textsearch(objectname, querystring);1195 pgaudit_ddl_textsearch(objectname, querystring);
1196 } break;1196 } break;
1197 case OBJECT_SEQUENCE:1197 case OBJECT_SEQUENCE:
1198- case OBJECT_LARGE_SEQUENCE: {1198+ case OBJECT_LARGE_SEQUENCE:
1199+ case OBJECT_SEQUENCE_GSC:
1200+ case OBJECT_LARGE_SEQUENCE_GSC: {
1199 objectname = strVal(lfirst(list_tail(names)));1201 objectname = strVal(lfirst(list_tail(names)));
1200 pgaudit_ddl_sequence(objectname, querystring);1202 pgaudit_ddl_sequence(objectname, querystring);
1201 } break;1203 } break;
@@ -1459,7 +1461,7 @@ static void pgaudit_ProcessUtility(processutility_context* processutility_cxt,
1459 } break;1461 } break;
1460 case T_AlterTableStmt: {1462 case T_AlterTableStmt: {
1461 AlterTableStmt* altertablestmt = (AlterTableStmt*)(parsetree); /* Audit alter table */1463 AlterTableStmt* altertablestmt = (AlterTableStmt*)(parsetree); /* Audit alter table */
1462- if (OBJECT_SEQUENCE == altertablestmt->relkind || OBJECT_LARGE_SEQUENCE == altertablestmt->relkind) {1464+ if (OBJECT_IS_SEQUENCE(altertablestmt->relkind)) {
1463 pgaudit_ddl_sequence(altertablestmt->relation->relname, queryString);1465 pgaudit_ddl_sequence(altertablestmt->relation->relname, queryString);
1464 } else {1466 } else {
1465 pgaudit_ddl_table(altertablestmt->relation->relname, queryString);1467 pgaudit_ddl_table(altertablestmt->relation->relname, queryString);
@@ -1671,7 +1671,9 @@ bool isAllTempObjects(Node* parse_tree, const char* query_string, bool sent_to_r
1671 case OBJECT_VIEW:1671 case OBJECT_VIEW:
1672 case OBJECT_CONTQUERY:1672 case OBJECT_CONTQUERY:
1673 case OBJECT_SEQUENCE:1673 case OBJECT_SEQUENCE:
1674- case OBJECT_LARGE_SEQUENCE: {1674+ case OBJECT_LARGE_SEQUENCE:
1675+ case OBJECT_SEQUENCE_GSC:
1676+ case OBJECT_LARGE_SEQUENCE_GSC: {
1675 bool is_all_temp = false;1677 bool is_all_temp = false;
1676 RemoteQueryExecType exec_type = EXEC_ON_ALL_NODES;1678 RemoteQueryExecType exec_type = EXEC_ON_ALL_NODES;
1677 DropStmt* new_stmt = (DropStmt*)copyObject(parse_tree);1679 DropStmt* new_stmt = (DropStmt*)copyObject(parse_tree);
@@ -7134,6 +7136,8 @@ ExecDropStmt(DropStmt *parse_tree, const char *query_string,
7134 /* fall through */7136 /* fall through */
7135 case OBJECT_SEQUENCE:7137 case OBJECT_SEQUENCE:
7136 case OBJECT_LARGE_SEQUENCE:7138 case OBJECT_LARGE_SEQUENCE:
7139+ case OBJECT_SEQUENCE_GSC:
7140+ case OBJECT_LARGE_SEQUENCE_GSC:
7137 case OBJECT_VIEW:7141 case OBJECT_VIEW:
7138 case OBJECT_CONTQUERY:7142 case OBJECT_CONTQUERY:
7139#ifdef PGXC7143#ifdef PGXC
@@ -8171,6 +8175,8 @@ static RemoteQueryExecType ExecUtilityFindNodes(ObjectType object_type, Oid obje
8171 switch (object_type) {8175 switch (object_type) {
8172 case OBJECT_SEQUENCE:8176 case OBJECT_SEQUENCE:
8173 case OBJECT_LARGE_SEQUENCE:8177 case OBJECT_LARGE_SEQUENCE:
8178+ case OBJECT_SEQUENCE_GSC:
8179+ case OBJECT_LARGE_SEQUENCE_GSC:
8174 exec_type = set_exec_type(object_id, is_temp);8180 exec_type = set_exec_type(object_id, is_temp);
8175 break;8181 break;
8176 8182 
@@ -8246,6 +8252,8 @@ static RemoteQueryExecType exec_utility_find_nodes_relkind(Oid rel_id, bool* is_
8246 switch (relkind_str) {8252 switch (relkind_str) {
8247 case RELKIND_SEQUENCE:8253 case RELKIND_SEQUENCE:
8248 case RELKIND_LARGE_SEQUENCE:8254 case RELKIND_LARGE_SEQUENCE:
8255+ case RELKIND_SEQUENCE_GSC:
8256+ case RELKIND_LARGE_SEQUENCE_GSC:
8249 *is_temp = IsTempTable(rel_id);8257 *is_temp = IsTempTable(rel_id);
8250 exec_type = CHOOSE_EXEC_NODES(*is_temp);8258 exec_type = CHOOSE_EXEC_NODES(*is_temp);
8251 break;8259 break;
@@ -8610,9 +8618,11 @@ static const char* AlterObjectTypeCommandTag(ObjectType obj_type)
8610 tag = "ALTER SCHEMA";8618 tag = "ALTER SCHEMA";
8611 break;8619 break;
8612 case OBJECT_SEQUENCE:8620 case OBJECT_SEQUENCE:
8621+ case OBJECT_SEQUENCE_GSC:
8613 tag = "ALTER SEQUENCE";8622 tag = "ALTER SEQUENCE";
8614 break;8623 break;
8615 case OBJECT_LARGE_SEQUENCE:8624 case OBJECT_LARGE_SEQUENCE:
8625+ case OBJECT_LARGE_SEQUENCE_GSC:
8616 tag = "ALTER LARGE SEQUENCE";8626 tag = "ALTER LARGE SEQUENCE";
8617 break;8627 break;
8618 case OBJECT_TABLE:8628 case OBJECT_TABLE:
@@ -8949,9 +8959,11 @@ const char* CreateCommandTag(Node* parse_tree)
8949 tag = "DROP TABLE";8959 tag = "DROP TABLE";
8950 break;8960 break;
8951 case OBJECT_SEQUENCE:8961 case OBJECT_SEQUENCE:
8962+ case OBJECT_SEQUENCE_GSC:
8952 tag = "DROP SEQUENCE";8963 tag = "DROP SEQUENCE";
8953 break;8964 break;
8954 case OBJECT_LARGE_SEQUENCE:8965 case OBJECT_LARGE_SEQUENCE:
8966+ case OBJECT_LARGE_SEQUENCE_GSC:
8955 tag = "DROP LARGE SEQUENCE";8967 tag = "DROP LARGE SEQUENCE";
8956 break;8968 break;
8957 case OBJECT_VIEW:8969 case OBJECT_VIEW:
@@ -10906,6 +10918,8 @@ static void drop_stmt_pre_treatment(
10906 case OBJECT_TABLE:10918 case OBJECT_TABLE:
10907 case OBJECT_SEQUENCE:10919 case OBJECT_SEQUENCE:
10908 case OBJECT_LARGE_SEQUENCE:10920 case OBJECT_LARGE_SEQUENCE:
10921+ case OBJECT_SEQUENCE_GSC:
10922+ case OBJECT_LARGE_SEQUENCE_GSC:
10909 case OBJECT_VIEW:10923 case OBJECT_VIEW:
10910 case OBJECT_MATVIEW:10924 case OBJECT_MATVIEW:
10911 case OBJECT_CONTQUERY:10925 case OBJECT_CONTQUERY:
@@ -32,6 +32,7 @@
32#include "catalog/pg_object.h"32#include "catalog/pg_object.h"
33#include "catalog/pg_proc.h"33#include "catalog/pg_proc.h"
34#include "commands/tablespace.h"34#include "commands/tablespace.h"
35+#include "commands/sequence.h"
35#include "executor/instrument.h"36#include "executor/instrument.h"
36#include "gssignal/gs_signal.h"37#include "gssignal/gs_signal.h"
37#include "mb/pg_wchar.h"38#include "mb/pg_wchar.h"
@@ -771,6 +772,7 @@ void knl_u_commands_init(knl_u_commands_context* cmd_cxt)
771 772 
772 cmd_cxt->seqtab = NULL;773 cmd_cxt->seqtab = NULL;
773 cmd_cxt->last_used_seq = NULL;774 cmd_cxt->last_used_seq = NULL;
775+ cmd_cxt->global_currval_seq = NULL;
774 776 
775 cmd_cxt->TypeCreateType = '\0';777 cmd_cxt->TypeCreateType = '\0';
776 778 
@@ -1682,6 +1682,8 @@ void CheckValidResultRel(Relation resultRel, CmdType operation)
1682 break;1682 break;
1683 case RELKIND_SEQUENCE:1683 case RELKIND_SEQUENCE:
1684 case RELKIND_LARGE_SEQUENCE:1684 case RELKIND_LARGE_SEQUENCE:
1685+ case RELKIND_SEQUENCE_GSC:
1686+ case RELKIND_LARGE_SEQUENCE_GSC:
1685 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),1687 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1686 errmsg("cannot change (large) sequence \"%s\"", RelationGetRelationName(resultRel))));1688 errmsg("cannot change (large) sequence \"%s\"", RelationGetRelationName(resultRel))));
1687 break;1689 break;
@@ -1797,6 +1799,8 @@ static void CheckValidRowMarkRel(Relation rel, RowMarkType markType)
1797 break;1799 break;
1798 case RELKIND_SEQUENCE:1800 case RELKIND_SEQUENCE:
1799 case RELKIND_LARGE_SEQUENCE:1801 case RELKIND_LARGE_SEQUENCE:
1802+ case RELKIND_SEQUENCE_GSC:
1803+ case RELKIND_LARGE_SEQUENCE_GSC:
1800 /* Must disallow this because we don't vacuum sequences */1804 /* Must disallow this because we don't vacuum sequences */
1801 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),1805 ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1802 errmsg("cannot lock rows in (large) sequence \"%s\"", RelationGetRelationName(rel))));1806 errmsg("cannot lock rows in (large) sequence \"%s\"", RelationGetRelationName(rel))));
@@ -1797,7 +1797,11 @@ Tuple ExecAutoIncrement(Relation rel, EState* estate, TupleTableSlot* slot, Tupl
1797 autoinc = estate->next_autoinc;1797 autoinc = estate->next_autoinc;
1798 estate->next_autoinc = 0;1798 estate->next_autoinc = 0;
1799 } else {1799 } else {
1800- autoinc = nextval_internal(cons_autoinc->seqoid);1800+ if (is_global_level_sequence_cache(cons_autoinc->seqoid)) {
1801+ autoinc = nextval_internal_for_global_seq_cache(cons_autoinc->seqoid);
1802+ } else {
1803+ autoinc = nextval_internal(cons_autoinc->seqoid);
1804+ }
1801 }1805 }
1802 }1806 }
1803 1807 
@@ -229,7 +229,10 @@ static const char *BuiltinTrancheNames[] = {
229 "CRBufAssignLock",229 "CRBufAssignLock",
230 "CRBufMappingLock",230 "CRBufMappingLock",
231 "CRBufLruLock",231 "CRBufLruLock",
232- "ATFGlobalTaskLock"232+ "ATFGlobalTaskLock",
233+ "GlobalSequenceCacheLock",
234+ "SequenceOidMapCacheLevelLock",
235+ "AlterSequneceCacheLevelLock"
233};236};
234 237 
235static void RegisterLWLockTranches(void);238static void RegisterLWLockTranches(void);
@@ -724,6 +727,11 @@ static void InitializeLWLocks(int numLocks)
724 LWLockInitialize(&lock->lock, LWTRANCHE_CR_BUF_MAPPING, id);727 LWLockInitialize(&lock->lock, LWTRANCHE_CR_BUF_MAPPING, id);
725 }728 }
726#endif729#endif
730+ 
731+ for (id = 0; id < NUM_GSC_SINGLENODE_PARTITIONS; id++, lock++) {
732+ LWLockInitialize(&lock->lock, LWTRANCHE_GLOBAL_SEQ_CACHE);
733+ }
734+ 
727 Assert((lock - t_thrd.shemem_ptr_cxt.mainLWLockArray) == NumFixedLWLocks);735 Assert((lock - t_thrd.shemem_ptr_cxt.mainLWLockArray) == NumFixedLWLocks);
728 736 
729 for (id = NumFixedLWLocks; id < numLocks; id++, lock++) {737 for (id = NumFixedLWLocks; id < numLocks; id++, lock++) {
@@ -1038,7 +1038,7 @@ static void AreaDecodingChange(ReorderBufferChange *change, LogicalDecodingConte
1038 * understand, so it doesn't make sense to handle the1038 * understand, so it doesn't make sense to handle the
1039 * few cases we do.1039 * few cases we do.
1040 */1040 */
1041- if (relation->rd_rel->relkind != RELKIND_SEQUENCE &&1041+ if (!RELKIND_IS_SEQUENCE(relation->rd_rel->relkind) &&
1042 !IsToastRelation(relation)) {1042 !IsToastRelation(relation)) {
1043 ctx->reorder->apply_change(ctx->reorder, NULL, relation, change);1043 ctx->reorder->apply_change(ctx->reorder, NULL, relation, change);
1044 }1044 }
@@ -285,8 +285,8 @@ bool CheckToastTuple(ParallelReorderBufferChange *change, ParallelLogicalDecodin
285 * understand, so it doesn't make sense to handle the285 * understand, so it doesn't make sense to handle the
286 * few cases we do.286 * few cases we do.
287 */287 */
288- 288+ 
289- if (relation->rd_rel->relkind == RELKIND_SEQUENCE) {289+ if (RELKIND_IS_SEQUENCE(relation->rd_rel->relkind)) {
290 } else if (!IsToastRelation(relation)) { /* user-triggered change */290 } else if (!IsToastRelation(relation)) { /* user-triggered change */
291 return false;291 return false;
292 } else if (change->action == PARALLEL_REORDER_BUFFER_CHANGE_INSERT ||292 } else if (change->action == PARALLEL_REORDER_BUFFER_CHANGE_INSERT ||
@@ -828,7 +828,7 @@ logicalLog* getIUDLogicalLog(ParallelReorderBufferChange* change, ParallelLogica
828 * few cases we do.828 * few cases we do.
829 */829 */
830 830
831- if (relation->rd_rel->relkind == RELKIND_SEQUENCE) {831+ if (RELKIND_IS_SEQUENCE(RelationGetRelkind(relation))) {
832 } else if (!IsToastRelation(relation)) { /* user-triggered change */832 } else if (!IsToastRelation(relation)) { /* user-triggered change */
833 logChange = GetLogicalLog(worker);833 logChange = GetLogicalLog(worker);
834 g_Logicaldispatcher[slotId].pOptions.decode_change(relation, change, logChange, ctx, slotId);834 g_Logicaldispatcher[slotId].pOptions.decode_change(relation, change, logChange, ctx, slotId);
@@ -557,6 +557,7 @@ static bool is_object_published_ddl(LogicalDecodingContext *ctx, Oid objid)
557 break;557 break;
558 558 
559 case RELKIND_SEQUENCE:559 case RELKIND_SEQUENCE:
560+ case RELKIND_SEQUENCE_GSC:
560 /* Send sequences */561 /* Send sequences */
561 return NeedPublicationDDL(data, false);562 return NeedPublicationDDL(data, false);
562 default:563 default:
@@ -779,6 +779,8 @@ TrObjType TrGetObjType(Oid nspId, char relKind)
779 break;779 break;
780 case RELKIND_SEQUENCE:780 case RELKIND_SEQUENCE:
781 case RELKIND_LARGE_SEQUENCE:781 case RELKIND_LARGE_SEQUENCE:
782+ case RELKIND_SEQUENCE_GSC:
783+ case RELKIND_LARGE_SEQUENCE_GSC:
782 type = RB_OBJ_SEQUENCE;784 type = RB_OBJ_SEQUENCE;
783 break;785 break;
784 case RELKIND_TOASTVALUE:786 case RELKIND_TOASTVALUE:
@@ -179,6 +179,8 @@ DESCR("");
179#define RELKIND_GLOBAL_INDEX 'I' /* GLOBAL partitioned index */179#define RELKIND_GLOBAL_INDEX 'I' /* GLOBAL partitioned index */
180#define RELKIND_SEQUENCE 'S' /* sequence object */180#define RELKIND_SEQUENCE 'S' /* sequence object */
181#define RELKIND_LARGE_SEQUENCE 'L' /* large sequence object that support 128-bit integer */181#define RELKIND_LARGE_SEQUENCE 'L' /* large sequence object that support 128-bit integer */
182+#define RELKIND_SEQUENCE_GSC 'z' /* new version sequence object */
183+#define RELKIND_LARGE_SEQUENCE_GSC 'Z' /* new version large sequence object that support 128-bit integer */
182#define RELKIND_TOASTVALUE 't' /* for out-of-line values */184#define RELKIND_TOASTVALUE 't' /* for out-of-line values */
183#define RELKIND_VIEW 'v' /* view */185#define RELKIND_VIEW 'v' /* view */
184#define RELKIND_MATVIEW 'm' /* materialized view */186#define RELKIND_MATVIEW 'm' /* materialized view */
@@ -211,10 +213,12 @@ DESCR("");
211 ((relkind) == RELKIND_RELATION || \213 ((relkind) == RELKIND_RELATION || \
212 (relkind) == RELKIND_INDEX || \214 (relkind) == RELKIND_INDEX || \
213 (relkind) == RELKIND_SEQUENCE || \215 (relkind) == RELKIND_SEQUENCE || \
216+ (relkind) == RELKIND_SEQUENCE_GSC || \
214 (relkind) == RELKIND_TOASTVALUE)217 (relkind) == RELKIND_TOASTVALUE)
215 218 
216-#define RELKIND_IS_SEQUENCE(relkind) \219+#define RELKIND_IS_SEQUENCE(relkind) \
217- ((relkind) == RELKIND_SEQUENCE || (relkind) == RELKIND_LARGE_SEQUENCE)220+ ((relkind) == RELKIND_SEQUENCE || (relkind) == RELKIND_LARGE_SEQUENCE || \
221+ (relkind) == RELKIND_SEQUENCE_GSC || (relkind) == RELKIND_LARGE_SEQUENCE_GSC)
218 222 
219/*223/*
220 * an explicitly chosen candidate key's columns are used as identity;224 * an explicitly chosen candidate key's columns are used as identity;
@@ -70,6 +70,8 @@ typedef FormData_pg_default_acl *Form_pg_default_acl;
70#define DEFACLOBJ_RELATION 'r' /* table, view */70#define DEFACLOBJ_RELATION 'r' /* table, view */
71#define DEFACLOBJ_SEQUENCE 'S' /* sequence */71#define DEFACLOBJ_SEQUENCE 'S' /* sequence */
72#define DEFACLOBJ_LARGE_SEQUENCE 'L' /* large sequence */72#define DEFACLOBJ_LARGE_SEQUENCE 'L' /* large sequence */
73+#define DEFACLOBJ_SEQUENCE_GSC 'z' /* new version sequence */
74+#define DEFACLOBJ_LARGE_SEQUENCE_GSC 'Z' /* new version large sequence */
73#define DEFACLOBJ_FUNCTION 'f' /* function */75#define DEFACLOBJ_FUNCTION 'f' /* function */
74#define DEFACLOBJ_PACKAGE 'p' /* package */76#define DEFACLOBJ_PACKAGE 'p' /* package */
75#define DEFACLOBJ_TYPE 'T' /* type */77#define DEFACLOBJ_TYPE 'T' /* type */
@@ -114,6 +114,8 @@ typedef FormData_pg_object* Form_pg_object;
114#define OBJECT_TYPE_INDEX 'i'114#define OBJECT_TYPE_INDEX 'i'
115#define OBJECT_TYPE_SEQUENCE 's'115#define OBJECT_TYPE_SEQUENCE 's'
116#define OBJECT_TYPE_LARGE_SEQUENCE 'l'116#define OBJECT_TYPE_LARGE_SEQUENCE 'l'
117+#define OBJECT_TYPE_SEQUENCE_GSC 'z'
118+#define OBJECT_TYPE_LARGE_SEQUENCE_GSC 'Z'
117#define OBJECT_TYPE_VIEW 'v'119#define OBJECT_TYPE_VIEW 'v'
118#define OBJECT_TYPE_CONTQUERY 'o'120#define OBJECT_TYPE_CONTQUERY 'o'
119#define OBJECT_TYPE_PROC 'P'121#define OBJECT_TYPE_PROC 'P'
@@ -85,6 +85,7 @@ DECLARE
85BEGIN85BEGIN
86select case when count(*)=1 then true else false end from (select nspname from pg_catalog.pg_namespace where nspname='coverage' limit 1) into ans;86select case when count(*)=1 then true else false end from (select nspname from pg_catalog.pg_namespace where nspname='coverage' limit 1) into ans;
87 if ans = true THEN87 if ans = true THEN
88+ --UPDATE pg_catalog.pg_class set relkind = 'z' where relname = 'proc_coverage_coverage_id_seq' AND relkind = 'S';
88 DROP table IF EXISTS coverage.proc_coverage;89 DROP table IF EXISTS coverage.proc_coverage;
89 DROP SEQUENCE IF EXISTS coverage.proc_coverage_coverage_id_seq;90 DROP SEQUENCE IF EXISTS coverage.proc_coverage_coverage_id_seq;
90 DROP SCHEMA IF EXISTS coverage cascade;91 DROP SCHEMA IF EXISTS coverage cascade;
@@ -59,3 +59,509 @@ CREATE OR REPLACE FUNCTION pg_catalog.TO_NVARCHAR2(FLOAT8)
59RETURNS NVARCHAR259RETURNS NVARCHAR2
60AS $$ select CAST(pg_catalog.float8out($1) AS NVARCHAR2) $$60AS $$ select CAST(pg_catalog.float8out($1) AS NVARCHAR2) $$
61LANGUAGE SQL STRICT IMMUTABLE NOT FENCED;61LANGUAGE SQL STRICT IMMUTABLE NOT FENCED;
62+ 
63+-- 1. 回滚 pg_sequence_parameters 至原始 6 参数版本
64+-- CASCADE 自动删除依赖此函数的 information_schema.sequences 视图
65+DROP FUNCTION IF EXISTS pg_catalog.pg_sequence_parameters(
66+ sequence_oid oid,
67+ OUT start_value int16,
68+ OUT minimum_value int16,
69+ OUT maximum_value int16,
70+ OUT increment int16,
71+ OUT cycle_option boolean,
72+ OUT is_global_cache boolean
73+) CASCADE;
74+SET LOCAL inplace_upgrade_next_system_object_oids=IUO_PROC, 3078;
75+CREATE OR REPLACE FUNCTION pg_catalog.pg_sequence_parameters(
76+ sequence_oid oid,
77+ OUT start_value int16,
78+ OUT minimum_value int16,
79+ OUT maximum_value int16,
80+ OUT increment int16,
81+ OUT cycle_option boolean
82+)
83+RETURNS record LANGUAGE internal STABLE STRICT NOT FENCED NOT SHIPPABLE
84+AS $function$pg_sequence_parameters$function$;
85+COMMENT ON FUNCTION pg_catalog.pg_sequence_parameters(oid) IS 'sequence parameters, for use by information schema';
86+ 
87+-- 2. 回滚 pg_sequence_all_parameters 至原始 13 参数版本
88+DROP FUNCTION IF EXISTS pg_catalog.pg_sequence_all_parameters(
89+ sequence_name text,
90+ OUT start_value int16,
91+ OUT minimum_value int16,
92+ OUT maximum_value int16,
93+ OUT increment int16,
94+ OUT cycle_option boolean,
95+ OUT cache_size int16,
96+ OUT last_value int16,
97+ OUT is_called boolean,
98+ OUT log_cnt int8,
99+ OUT uuid int8,
100+ OUT last_used_value int16,
101+ OUT is_exhausted boolean,
102+ OUT is_global_cache boolean
103+) CASCADE;
104+SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 8930;
105+CREATE OR REPLACE FUNCTION pg_catalog.pg_sequence_all_parameters(
ywzq1161327784

【问题描述】 这个函数的升级和回滚,需要验证下是否影响D库带shark插件的升级,因为shark插件有用到这个函数 【修改建议】 这个函数的升级和回滚,需要验证下是否影响D库带shark插件的升级,因为shark插件有用到这个函数

likedislike
sunquancheng
sunquancheng
5月28日 评论:
106+ sequence_name text,
107+ OUT start_value int16,
108+ OUT minimum_value int16,
109+ OUT maximum_value int16,
110+ OUT increment int16,
111+ OUT cycle_option boolean,
112+ OUT cache_size int16,
113+ OUT last_value int16,
114+ OUT is_called boolean,
115+ OUT log_cnt int8,
116+ OUT uuid int8,
117+ OUT last_used_value int16,
118+ OUT is_exhausted boolean
119+)
120+RETURNS record
121+LANGUAGE internal
122+STABLE STRICT NOT FENCED NOT SHIPPABLE
123+AS $function$pg_sequence_all_parameters$function$;
124+ 
125+COMMENT ON FUNCTION pg_catalog.pg_sequence_all_parameters(
126+ sequence_name text, OUT start_value int16, OUT minimum_value int16,
127+ OUT maximum_value int16, OUT increment int16, OUT cycle_option boolean,
128+ OUT cache_size int16, OUT last_value int16, OUT is_called boolean,
129+ OUT log_cnt int8, OUT uuid int8, OUT last_used_value int16,
130+ OUT is_exhausted boolean) IS 'sequence all parameters';
131+ 
132+SET LOCAL inplace_upgrade_next_system_object_oids = IUO_CATALOG, false, true, 0, 0, 0, 0;
133+ 
134+-- 3. 恢复 information_schema.sequences 视图至原始定义(只过滤 'L'、'S')
135+SET search_path TO information_schema;
136+DROP VIEW IF EXISTS information_schema.sequences;
137+CREATE VIEW information_schema.sequences AS
138+ SELECT CAST(pg_catalog.current_database() AS sql_identifier) AS sequence_catalog,
139+ CAST(nc.nspname AS sql_identifier) AS sequence_schema,
140+ CAST(c.relname AS sql_identifier) AS sequence_name,
141+ CAST('int16' AS character_data) AS data_type,
142+ CAST(128 AS cardinal_number) AS numeric_precision,
143+ CAST(2 AS cardinal_number) AS numeric_precision_radix,
144+ CAST(0 AS cardinal_number) AS numeric_scale,
145+ -- XXX: The following could be improved if we had LATERAL.
146+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).start_value AS character_data) AS start_value,
147+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).minimum_value AS character_data) AS minimum_value,
148+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).maximum_value AS character_data) AS maximum_value,
149+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).increment AS character_data) AS increment,
150+ CAST(CASE WHEN (pg_catalog.pg_sequence_parameters(c.oid)).cycle_option THEN 'YES' ELSE 'NO' END AS yes_or_no) AS cycle_option
151+ FROM pg_catalog.pg_namespace nc, pg_catalog.pg_class c
152+ WHERE c.relnamespace = nc.oid
153+ AND (c.relkind = 'L' or c.relkind = 'S')
154+ AND (NOT pg_catalog.pg_is_other_temp_schema(nc.oid))
155+ AND (pg_catalog.pg_has_role(c.relowner, 'USAGE')
156+ OR pg_catalog.has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE') );
157+GRANT SELECT ON information_schema.sequences TO PUBLIC;
158+RESET search_path;
@@ -0,0 +1,59 @@
1+DO $$
2+DECLARE
3+ ans boolean;
4+BEGIN
5+select case when count(*)=1 then true else false end from (select c.relname,c.relkind from pg_catalog.pg_class c, pg_catalog.pg_namespace n where c.relname='proc_coverage_coverage_id_seq' and n.nspname='coverage' and c.relkind ='z') into ans;
6+ if ans = true THEN
7+ UPDATE pg_catalog.pg_class SET relkind = 'S' WHERE relname='proc_coverage_coverage_id_seq';
8+ DROP table IF EXISTS coverage.proc_coverage;
9+ DROP SEQUENCE IF EXISTS coverage.proc_coverage_coverage_id_seq;
10+ DROP SCHEMA IF EXISTS coverage cascade;
11+ end if;
12+END$$;
13+ 
14+SET LOCAL inplace_upgrade_next_system_object_oids = IUO_NAMESPACE, 4994;
15+DO $$
16+DECLARE
17+ ans boolean;
18+BEGIN
19+select case when count(*)=1 then true else false end from (select c.relname,c.relkind from pg_catalog.pg_class c, pg_catalog.pg_namespace n where c.relname='proc_coverage_coverage_id_seq' and n.nspname='coverage') into ans;
20+ if ans = false THEN
21+ CREATE SCHEMA IF NOT EXISTS coverage;
22+ COMMENT ON schema coverage IS 'coverage schema';
23+ 
24+ CREATE SEQUENCE IF NOT EXISTS coverage.proc_coverage_coverage_id_seq START 1;
25+ CREATE unlogged table IF NOT EXISTS coverage.proc_coverage(
26+ coverage_id bigint NOT NULL DEFAULT nextval('coverage.proc_coverage_coverage_id_seq'::regclass),
27+ pro_oid oid NOT NULL,
28+ pro_name text NOT NULL,
29+ db_name text NOT NULL,
30+ pro_querys text NOT NULL,
31+ pro_canbreak bool[] NOT NULL,
32+ coverage int[] NOT NULL
33+ ) WITH (orientation=row, compression=no);
34+ REVOKE ALL on table coverage.proc_coverage FROM public;
35+ end if;
36+END$$;
37+ 
38+ 
39+DO $$
40+DECLARE
41+ ans boolean;
42+BEGIN
43+select case when count(*)=1 then true else false end from (select c.relname,c.relkind from pg_catalog.pg_class c, pg_catalog.pg_namespace n where c.relname='snapshot_sequence' and n.nspname='db4ai' and c.relkind ='z') into ans;
44+ if ans = true THEN
45+ UPDATE pg_catalog.pg_class SET relkind = 'S' WHERE relname='snapshot_sequence';
46+ DROP SEQUENCE IF EXISTS db4ai.snapshot_sequence;
47+ end if;
48+END$$;
49+ 
50+DO $$
51+DECLARE
52+ ans boolean;
53+BEGIN
54+select case when count(*)=1 then true else false end from (select c.relname,c.relkind from pg_catalog.pg_class c, pg_catalog.pg_namespace n where c.relname='snapshot_sequence' and n.nspname='db4ai') into ans;
55+ if ans = false THEN
56+ CREATE SEQUENCE IF NOT EXISTS db4ai.snapshot_sequence;
57+ GRANT UPDATE ON db4ai.snapshot_sequence TO PUBLIC;
58+ end if;
59+END$$;
@@ -85,6 +85,7 @@ DECLARE
85BEGIN85BEGIN
86select case when count(*)=1 then true else false end from (select nspname from pg_catalog.pg_namespace where nspname='coverage' limit 1) into ans;86select case when count(*)=1 then true else false end from (select nspname from pg_catalog.pg_namespace where nspname='coverage' limit 1) into ans;
87 if ans = true THEN87 if ans = true THEN
88+ --UPDATE pg_catalog.pg_class set relkind = 'z' where relname = 'proc_coverage_coverage_id_seq' AND relkind = 'S';
88 DROP table IF EXISTS coverage.proc_coverage;89 DROP table IF EXISTS coverage.proc_coverage;
89 DROP SEQUENCE IF EXISTS coverage.proc_coverage_coverage_id_seq;90 DROP SEQUENCE IF EXISTS coverage.proc_coverage_coverage_id_seq;
90 DROP SCHEMA IF EXISTS coverage cascade;91 DROP SCHEMA IF EXISTS coverage cascade;
@@ -84,3 +84,441 @@ CREATE OR REPLACE FUNCTION pg_catalog.TO_NVARCHAR2(FLOAT8)
84RETURNS NVARCHAR284RETURNS NVARCHAR2
85AS $$ select pg_catalog.nvarchar2in(pg_catalog.float8out($1), 0::Oid, -1) $$85AS $$ select pg_catalog.nvarchar2in(pg_catalog.float8out($1), 0::Oid, -1) $$
86LANGUAGE SQL STRICT IMMUTABLE NOT FENCED;86LANGUAGE SQL STRICT IMMUTABLE NOT FENCED;
87+ 
88+-- 1. 更新 pg_sequence_parameters,新增 is_global_cache 输出参数
89+-- CASCADE 自动删除依赖此函数的 information_schema.sequences 视图
90+DROP FUNCTION IF EXISTS pg_catalog.pg_sequence_parameters(
91+ sequence_oid oid,
92+ OUT start_value int16,
93+ OUT minimum_value int16,
94+ OUT maximum_value int16,
95+ OUT increment int16,
96+ OUT cycle_option boolean
97+) CASCADE;
98+SET LOCAL inplace_upgrade_next_system_object_oids=IUO_PROC, 3078;
99+CREATE OR REPLACE FUNCTION pg_catalog.pg_sequence_parameters(
100+ sequence_oid oid,
101+ OUT start_value int16,
102+ OUT minimum_value int16,
103+ OUT maximum_value int16,
104+ OUT increment int16,
105+ OUT cycle_option boolean,
106+ OUT is_global_cache boolean
107+)
108+RETURNS record LANGUAGE INTERNAL STABLE STRICT NOT FENCED NOT SHIPPABLE AS 'pg_sequence_parameters';
109+COMMENT ON FUNCTION pg_catalog.pg_sequence_parameters(oid) IS 'sequence parameters, for use by information schema';
110+ 
111+-- 2. 更新 pg_sequence_all_parameters,新增 is_global_cache 输出参数
112+--DROP FUNCTION IF EXISTS pg_catalog.pg_sequence_all_parameters(text) CASCADE;
113+DROP FUNCTION IF EXISTS pg_catalog.pg_sequence_all_parameters(
114+ sequence_name text, OUT start_value int16, OUT minimum_value int16, OUT maximum_value int16,
115+ OUT increment int16, OUT cycle_option boolean, OUT cache_size int16, OUT last_value int16,
116+ OUT is_called boolean, OUT log_cnt bigint, OUT uuid bigint, OUT last_used_value int16,
117+ OUT is_exhausted boolean) CASCADE;
118+SET LOCAL inplace_upgrade_next_system_object_oids=IUO_PROC, 8930;
119+CREATE OR REPLACE FUNCTION pg_catalog.pg_sequence_all_parameters(
120+ sequence_name text,
121+ OUT start_value int16,
122+ OUT minimum_value int16,
123+ OUT maximum_value int16,
124+ OUT increment int16,
125+ OUT cycle_option boolean,
126+ OUT cache_size int16,
127+ OUT last_value int16,
128+ OUT is_called boolean,
129+ OUT log_cnt int8,
130+ OUT uuid int8,
131+ OUT last_used_value int16,
132+ OUT is_exhausted boolean,
133+ OUT is_global_cache boolean
134+)
135+RETURNS record LANGUAGE internal STABLE STRICT NOT FENCED NOT SHIPPABLE
136+AS $function$pg_sequence_all_parameters$function$;
137+ 
138+COMMENT ON FUNCTION pg_catalog.pg_sequence_all_parameters(
139+ sequence_name text, OUT start_value int16, OUT minimum_value int16,
140+ OUT maximum_value int16, OUT increment int16, OUT cycle_option boolean,
141+ OUT cache_size int16, OUT last_value int16, OUT is_called boolean,
142+ OUT log_cnt int8, OUT uuid int8, OUT last_used_value int16,
143+ OUT is_exhausted boolean, OUT is_global_cache boolean) IS 'sequence all parameters';
144+ 
145+SET LOCAL inplace_upgrade_next_system_object_oids = IUO_CATALOG, false, true, 0, 0, 0, 0;
146+ 
147+-- 3. 重建 information_schema.sequences 视图,新增 'z'、'Z' relkind 以支持 GSC 序列
148+SET search_path TO information_schema;
149+CREATE OR REPLACE VIEW information_schema.sequences AS
150+ SELECT CAST(pg_catalog.current_database() AS sql_identifier) AS sequence_catalog,
151+ CAST(nc.nspname AS sql_identifier) AS sequence_schema,
152+ CAST(c.relname AS sql_identifier) AS sequence_name,
153+ CAST('int16' AS character_data) AS data_type,
154+ CAST(128 AS cardinal_number) AS numeric_precision,
155+ CAST(2 AS cardinal_number) AS numeric_precision_radix,
156+ CAST(0 AS cardinal_number) AS numeric_scale,
157+ -- XXX: The following could be improved if we had LATERAL.
158+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).start_value AS character_data) AS start_value,
159+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).minimum_value AS character_data) AS minimum_value,
160+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).maximum_value AS character_data) AS maximum_value,
161+ CAST((pg_catalog.pg_sequence_parameters(c.oid)).increment AS character_data) AS increment,
162+ CAST(CASE WHEN (pg_catalog.pg_sequence_parameters(c.oid)).cycle_option THEN 'YES' ELSE 'NO' END AS yes_or_no) AS cycle_option,
163+ CAST(CASE WHEN (pg_catalog.pg_sequence_parameters(c.oid)).is_global_cache THEN 'YES' ELSE 'NO' END AS yes_or_no) AS global_cache_option
164+ FROM pg_namespace nc, pg_class c
165+ WHERE c.relnamespace = nc.oid
166+ AND (c.relkind = 'L' or c.relkind = 'S' or c.relkind = 'z' or c.relkind = 'Z')
167+ AND (NOT pg_catalog.pg_is_other_temp_schema(nc.oid))
168+ AND (pg_catalog.pg_has_role(c.relowner, 'USAGE')
169+ OR pg_catalog.has_sequence_privilege(c.oid, 'SELECT, UPDATE, USAGE') );
170+GRANT SELECT ON information_schema.sequences TO PUBLIC;
171+RESET search_path;
172+ 
173+-- 4. upgrade views 更新 pg_catalog.pg_seclabels 视图,新增 'z'、'Z' relkind 以支持 GSC 序列
174+CREATE OR REPLACE VIEW pg_catalog.pg_seclabels AS
175+SELECT
176+ l.objoid, l.classoid, l.objsubid,
177+ CASE WHEN rel.relkind = 'r' THEN 'table'::text
178+ WHEN rel.relkind = 'v' THEN 'view'::text
179+ WHEN rel.relkind = 'm' THEN 'materialized view'::text
180+ WHEN rel.relkind = 'S' THEN 'sequence'::text
181+ WHEN rel.relkind = 'L' THEN 'large sequence'::text
182+ WHEN rel.relkind = 'z' THEN 'sequence'::text
183+ WHEN rel.relkind = 'Z' THEN 'large sequence'::text
184+ WHEN rel.relkind = 'f' THEN 'foreign table'::text END AS objtype,
185+ rel.relnamespace AS objnamespace,
186+ CASE WHEN pg_catalog.pg_table_is_visible(rel.oid)
187+ THEN pg_catalog.quote_ident(rel.relname)
188+ ELSE pg_catalog.quote_ident(nsp.nspname) || '.' || pg_catalog.quote_ident(rel.relname)
189+ END AS objname,
190+ l.provider, l.label
191+FROM
192+ pg_seclabel l
193+ JOIN pg_class rel ON l.classoid = rel.tableoid AND l.objoid = rel.oid
194+ JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
195+WHERE
196+ l.objsubid = 0
197+UNION ALL
198+SELECT
199+ l.objoid, l.classoid, l.objsubid,
200+ 'column'::text AS objtype,
201+ rel.relnamespace AS objnamespace,
202+ CASE WHEN pg_catalog.pg_table_is_visible(rel.oid)
203+ THEN pg_catalog.quote_ident(rel.relname)
204+ ELSE pg_catalog.quote_ident(nsp.nspname) || '.' || pg_catalog.quote_ident(rel.relname)
205+ END || '.' || att.attname AS objname,
206+ l.provider, l.label
207+FROM
208+ pg_seclabel l
209+ JOIN pg_class rel ON l.classoid = rel.tableoid AND l.objoid = rel.oid
210+ JOIN pg_attribute att
211+ ON rel.oid = att.attrelid AND l.objsubid = att.attnum
212+ JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
213+WHERE
214+ l.objsubid != 0
215+UNION ALL
216+SELECT
217+ l.objoid, l.classoid, l.objsubid,
218+ CASE WHEN pro.proisagg = true THEN 'aggregate'::text
219+ WHEN pro.proisagg = false THEN 'function'::text
220+ END AS objtype,
221+ pro.pronamespace AS objnamespace,
222+ CASE WHEN pg_catalog.pg_function_is_visible(pro.oid)
223+ THEN pg_catalog.quote_ident(pro.proname)
224+ ELSE pg_catalog.quote_ident(nsp.nspname) || '.' || pg_catalog.quote_ident(pro.proname)
225+ END || '(' || pg_catalog.pg_get_function_arguments(pro.oid) || ')' AS objname,
226+ l.provider, l.label
227+FROM
228+ pg_seclabel l
229+ JOIN pg_proc pro ON l.classoid = pro.tableoid AND l.objoid = pro.oid
230+ JOIN pg_namespace nsp ON pro.pronamespace = nsp.oid
231+WHERE
232+ l.objsubid = 0
233+UNION ALL
234+SELECT
235+ l.objoid, l.classoid, l.objsubid,
236+ CASE WHEN typ.typtype = 'd' THEN 'domain'::text
237+ ELSE 'type'::text END AS objtype,
238+ typ.typnamespace AS objnamespace,
239+ CASE WHEN pg_catalog.pg_type_is_visible(typ.oid)
240+ THEN pg_catalog.quote_ident(typ.typname)
241+ ELSE pg_catalog.quote_ident(nsp.nspname) || '.' || pg_catalog.quote_ident(typ.typname)
242+ END AS objname,
243+ l.provider, l.label
244+FROM
245+ pg_seclabel l
246+ JOIN pg_type typ ON l.classoid = typ.tableoid AND l.objoid = typ.oid
247+ JOIN pg_namespace nsp ON typ.typnamespace = nsp.oid
248+WHERE
249+ l.objsubid = 0
250+UNION ALL
251+SELECT
252+ l.objoid, l.classoid, l.objsubid,
253+ 'large object'::text AS objtype,
254+ NULL::oid AS objnamespace,
255+ l.objoid::text AS objname,
256+ l.provider, l.label
257+FROM
258+ pg_seclabel l
259+ JOIN pg_largeobject_metadata lom ON l.objoid = lom.oid
260+WHERE
261+ l.classoid = 'pg_catalog.pg_largeobject'::regclass AND l.objsubid = 0
262+UNION ALL
263+SELECT
264+ l.objoid, l.classoid, l.objsubid,
265+ 'language'::text AS objtype,
266+ NULL::oid AS objnamespace,
267+ pg_catalog.quote_ident(lan.lanname) AS objname,
268+ l.provider, l.label
269+FROM
270+ pg_seclabel l
271+ JOIN pg_language lan ON l.classoid = lan.tableoid AND l.objoid = lan.oid
272+WHERE
273+ l.objsubid = 0
274+UNION ALL
275+SELECT
276+ l.objoid, l.classoid, l.objsubid,
277+ 'schema'::text AS objtype,
278+ nsp.oid AS objnamespace,
279+ pg_catalog.quote_ident(nsp.nspname) AS objname,
280+ l.provider, l.label
281+FROM
282+ pg_seclabel l
283+ JOIN pg_namespace nsp ON l.classoid = nsp.tableoid AND l.objoid = nsp.oid
284+WHERE
285+ l.objsubid = 0
286+UNION ALL
287+SELECT
288+ l.objoid, l.classoid, l.objsubid,
289+ 'event trigger'::text AS objtype,
290+ NULL::oid AS objnamespace,
291+ quote_ident(evt.evtname) AS objname,
292+ l.provider, l.label
293+FROM
294+ pg_seclabel l
295+ JOIN pg_event_trigger evt ON l.classoid = evt.tableoid
296+ AND l.objoid = evt.oid
297+WHERE
298+ l.objsubid = 0
299+UNION ALL
300+SELECT
301+ l.objoid, l.classoid, 0::int4 AS objsubid,
302+ 'database'::text AS objtype,
303+ NULL::oid AS objnamespace,
304+ pg_catalog.quote_ident(dat.datname) AS objname,
305+ l.provider, l.label
306+FROM
307+ pg_shseclabel l
308+ JOIN pg_database dat ON l.classoid = dat.tableoid AND l.objoid = dat.oid
309+UNION ALL
310+SELECT
311+ l.objoid, l.classoid, 0::int4 AS objsubid,
312+ 'tablespace'::text AS objtype,
313+ NULL::oid AS objnamespace,
314+ pg_catalog.quote_ident(spc.spcname) AS objname,
315+ l.provider, l.label
316+FROM
317+ pg_shseclabel l
318+ JOIN pg_tablespace spc ON l.classoid = spc.tableoid AND l.objoid = spc.oid
319+UNION ALL
320+SELECT
321+ l.objoid, l.classoid, 0::int4 AS objsubid,
322+ 'role'::text AS objtype,
323+ NULL::oid AS objnamespace,
324+ pg_catalog.quote_ident(rol.rolname) AS objname,
325+ l.provider, l.label
326+FROM
327+ pg_shseclabel l
328+ JOIN pg_authid rol ON l.classoid = rol.tableoid AND l.objoid = rol.oid;
329+ 
330+-- 5. 更新 dbe_perf.statio_all_sequences 视图,新增 'z'、'Z' relkind 以支持 GSC 序列
331+CREATE OR REPLACE VIEW dbe_perf.statio_all_sequences AS
332+ SELECT
333+ C.oid AS relid,
334+ N.nspname AS schemaname,
335+ C.relname AS relname,
336+ pg_catalog.pg_stat_get_blocks_fetched(C.oid) -
337+ pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_read,
338+ pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_hit
339+ FROM pg_class C
340+ LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
341+ WHERE C.relkind = 'S' or C.relkind = 'L' or C.relkind = 'z' or C.relkind = 'Z';
342+ 
343+-- 5. 更新 pg_catalog.pg_gtt_attached_pids 视图,新增 'z'、'Z' relkind 以支持 GSC 序列
344+CREATE OR REPLACE VIEW pg_catalog.pg_gtt_attached_pids WITH (security_barrier) AS
345+ SELECT n.nspname AS schemaname,
346+ c.relname AS tablename,
347+ c.oid AS relid,
348+ array(select pid from pg_catalog.pg_gtt_attached_pid(c.oid)) AS pids,
349+ array(select sessionid from pg_catalog.pg_gtt_attached_pid(c.oid)) AS sessionids
350+ FROM
351+ pg_class c
352+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
353+ WHERE c.relpersistence='g' AND c.relkind in('r', 'S', 'L', 'z', 'Z');
354+ 
355+-- 6. 更新 pg_catalog.pg_statio_all_sequences 视图,新增 'z'、'Z' relkind 以支持 GSC 序列
356+CREATE OR REPLACE VIEW pg_catalog.pg_statio_all_sequences AS
357+ SELECT
358+ C.oid AS relid,
359+ N.nspname AS schemaname,
360+ C.relname AS relname,
361+ pg_catalog.pg_stat_get_blocks_fetched(C.oid) -
362+ pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_read,
363+ pg_catalog.pg_stat_get_blocks_hit(C.oid) AS blks_hit
364+ FROM pg_catalog.pg_class C
365+ LEFT JOIN pg_catalog.pg_namespace N ON (N.oid = C.relnamespace)
366+ WHERE C.relkind = 'S' or C.relkind = 'L' or C.relkind = 'z' or C.relkind = 'Z';
367+ 
368+-- 7. 更新 information_schema.usage_privileges 视图,新增 'z'、'Z' relkind 以支持 GSC 序列
369+SET search_path TO information_schema;
370+CREATE OR REPLACE VIEW information_schema.usage_privileges AS
371+ -- collations
372+ SELECT CAST(u.rolname AS sql_identifier) AS grantor,
373+ CAST('PUBLIC' AS sql_identifier) AS grantee,
374+ CAST(pg_catalog.current_database() AS sql_identifier) AS object_catalog,
375+ CAST(n.nspname AS sql_identifier) AS object_schema,
376+ CAST(c.collname AS sql_identifier) AS object_name,
377+ CAST('COLLATION' AS character_data) AS object_type,
378+ CAST('USAGE' AS character_data) AS privilege_type,
379+ CAST('NO' AS yes_or_no) AS is_grantable
380+ FROM pg_authid u,
381+ pg_namespace n,
382+ pg_collation c
383+ WHERE u.oid = c.collowner
384+ AND c.collnamespace = n.oid
385+ AND collencoding IN (-1, (SELECT encoding FROM pg_database WHERE datname = pg_catalog.current_database()))
386+ UNION ALL
387+ -- domains
388+ SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
389+ CAST(grantee.rolname AS sql_identifier) AS grantee,
390+ CAST(pg_catalog.current_database() AS sql_identifier) AS object_catalog,
391+ CAST(n.nspname AS sql_identifier) AS object_schema,
392+ CAST(t.typname AS sql_identifier) AS object_name,
393+ CAST('DOMAIN' AS character_data) AS object_type,
394+ CAST('USAGE' AS character_data) AS privilege_type,
395+ CAST(
396+ CASE WHEN
397+ pg_catalog.pg_has_role(grantee.oid, t.typowner, 'USAGE')
398+ OR t.grantable
399+ THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
400+ FROM (
401+ SELECT oid, typname, typnamespace, typtype, typowner, (pg_catalog.aclexplode(coalesce(typacl, pg_catalog.acldefault('T', typowner)))).* FROM pg_type
402+ ) AS t (oid, typname, typnamespace, typtype, typowner, grantor, grantee, prtype, grantable),
403+ pg_namespace n,
404+ pg_authid u_grantor,
405+ (
406+ SELECT oid, rolname FROM pg_authid
407+ UNION ALL
408+ SELECT 0::oid, 'PUBLIC'
409+ ) AS grantee (oid, rolname)
410+ 
411+ WHERE t.typnamespace = n.oid
412+ AND t.typtype = 'd'
413+ AND t.grantee = grantee.oid
414+ AND t.grantor = u_grantor.oid
415+ AND t.prtype IN ('USAGE')
416+ AND (pg_catalog.pg_has_role(u_grantor.oid, 'USAGE')
417+ OR pg_catalog.pg_has_role(grantee.oid, 'USAGE')
418+ OR grantee.rolname = 'PUBLIC')
419+ UNION ALL
420+ -- foreign-data wrappers
421+ SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
422+ CAST(grantee.rolname AS sql_identifier) AS grantee,
423+ CAST(pg_catalog.current_database() AS sql_identifier) AS object_catalog,
424+ CAST('' AS sql_identifier) AS object_schema,
425+ CAST(fdw.fdwname AS sql_identifier) AS object_name,
426+ CAST('FOREIGN DATA WRAPPER' AS character_data) AS object_type,
427+ CAST('USAGE' AS character_data) AS privilege_type,
428+ CAST(
429+ CASE WHEN
430+ pg_catalog.pg_has_role(grantee.oid, fdw.fdwowner, 'USAGE')
431+ OR fdw.grantable
432+ THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
433+ FROM (
434+ SELECT fdwname, fdwowner, (pg_catalog.aclexplode(coalesce(fdwacl, pg_catalog.acldefault('F', fdwowner)))).* FROM pg_foreign_data_wrapper
435+ ) AS fdw (fdwname, fdwowner, grantor, grantee, prtype, grantable),
436+ pg_authid u_grantor,
437+ (
438+ SELECT oid, rolname FROM pg_authid
439+ UNION ALL
440+ SELECT 0::oid, 'PUBLIC'
441+ ) AS grantee (oid, rolname)
442+ WHERE u_grantor.oid = fdw.grantor
443+ AND grantee.oid = fdw.grantee
444+ AND fdw.prtype IN ('USAGE')
445+ AND (pg_catalog.pg_has_role(u_grantor.oid, 'USAGE')
446+ OR pg_catalog.pg_has_role(grantee.oid, 'USAGE')
447+ OR grantee.rolname = 'PUBLIC')
448+ UNION ALL
449+ -- foreign servers
450+ SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
451+ CAST(grantee.rolname AS sql_identifier) AS grantee,
452+ CAST(pg_catalog.current_database() AS sql_identifier) AS object_catalog,
453+ CAST('' AS sql_identifier) AS object_schema,
454+ CAST(srv.srvname AS sql_identifier) AS object_name,
455+ CAST('FOREIGN SERVER' AS character_data) AS object_type,
456+ CAST('USAGE' AS character_data) AS privilege_type,
457+ CAST(
458+ CASE WHEN
459+ pg_catalog.pg_has_role(grantee.oid, srv.srvowner, 'USAGE')
460+ OR srv.grantable
461+ THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
462+ FROM (
463+ SELECT srvname, srvowner, (pg_catalog.aclexplode(coalesce(srvacl, pg_catalog.acldefault('S', srvowner)))).* FROM pg_foreign_server
464+ ) AS srv (srvname, srvowner, grantor, grantee, prtype, grantable),
465+ pg_authid u_grantor,
466+ (
467+ SELECT oid, rolname FROM pg_authid
468+ UNION ALL
469+ SELECT 0::oid, 'PUBLIC'
470+ ) AS grantee (oid, rolname)
471+ WHERE u_grantor.oid = srv.grantor
472+ AND grantee.oid = srv.grantee
473+ AND srv.prtype IN ('USAGE')
474+ AND (pg_catalog.pg_has_role(u_grantor.oid, 'USAGE')
475+ OR pg_catalog.pg_has_role(grantee.oid, 'USAGE')
476+ OR grantee.rolname = 'PUBLIC')
477+ UNION ALL
478+ -- sequences
479+ SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor,
480+ CAST(grantee.rolname AS sql_identifier) AS grantee,
481+ CAST(pg_catalog.current_database() AS sql_identifier) AS object_catalog,
482+ CAST(n.nspname AS sql_identifier) AS object_schema,
483+ CAST(c.relname AS sql_identifier) AS object_name,
484+ CAST('SEQUENCE' AS character_data) AS object_type,
485+ CAST('USAGE' AS character_data) AS privilege_type,
486+ CAST(
487+ CASE WHEN
488+ pg_catalog.pg_has_role(grantee.oid, c.relowner, 'USAGE')
489+ OR c.grantable
490+ THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_grantable
491+ FROM (
492+ SELECT oid, relname, relnamespace, relkind, relowner, (pg_catalog.aclexplode(coalesce(relacl, pg_catalog.acldefault('r', relowner)))).* FROM pg_class
493+ ) AS c (oid, relname, relnamespace, relkind, relowner, grantor, grantee, prtype, grantable),
494+ pg_namespace n,
495+ pg_authid u_grantor,
496+ (
497+ SELECT oid, rolname FROM pg_authid
498+ UNION ALL
499+ SELECT 0::oid, 'PUBLIC'
500+ ) AS grantee (oid, rolname)
501+ WHERE c.relnamespace = n.oid
502+ AND (c.relkind = 'S' or c.relkind = 'L' or c.relkind = 'z' or c.relkind = 'Z')
503+ AND c.grantee = grantee.oid
504+ AND c.grantor = u_grantor.oid
505+ AND c.prtype IN ('USAGE')
506+ AND (pg_catalog.pg_has_role(u_grantor.oid, 'USAGE')
507+ OR pg_catalog.pg_has_role(grantee.oid, 'USAGE')
508+ OR grantee.rolname = 'PUBLIC');
509+GRANT SELECT ON information_schema.usage_privileges TO PUBLIC;
510+RESET search_path;
511+ 
512+-- 8. 升级 db4ai.snapshot_sequence:将旧版 relkind='S' 的序列 DROP 后重建为 'z'
513+DO $$
514+DECLARE
515+ ans boolean;
516+BEGIN
517+ SELECT CASE WHEN count(*)=1 THEN true ELSE false END FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n
518+ WHERE c.relname='snapshot_sequence' AND n.nspname='db4ai' AND c.relnamespace=n.oid AND c.relkind='S' INTO ans;
519+ IF ans = true THEN
520+ DROP SEQUENCE IF EXISTS db4ai.snapshot_sequence;
521+ CREATE SEQUENCE IF NOT EXISTS db4ai.snapshot_sequence;
522+ GRANT UPDATE ON db4ai.snapshot_sequence TO PUBLIC;
523+ END IF;
524+END$$;
@@ -35,6 +35,11 @@
35// extern THR_LOCAL char *PGXCNodeName;35// extern THR_LOCAL char *PGXCNodeName;
36 36 
37typedef int64 GTM_UUID;37typedef int64 GTM_UUID;
38+typedef bool CACHE_LEVEL;
39+ 
40+#define SESSION_LEVEL FALSE
41+#define GLOBAL_LEVEL TRUE
42+ 
38 43 
39typedef struct FormData_pg_sequence {44typedef struct FormData_pg_sequence {
40 NameData sequence_name;45 NameData sequence_name;
@@ -48,6 +53,7 @@ typedef struct FormData_pg_sequence {
48 bool is_cycled;53 bool is_cycled;
49 bool is_called;54 bool is_called;
50 GTM_UUID uuid;55 GTM_UUID uuid;
56+ CACHE_LEVEL is_global;
51} FormData_pg_sequence;57} FormData_pg_sequence;
52 58 
53typedef FormData_pg_sequence* Form_pg_sequence;59typedef FormData_pg_sequence* Form_pg_sequence;
@@ -64,6 +70,7 @@ typedef struct FormData_pg_large_sequence {
64 bool is_cycled;70 bool is_cycled;
65 bool is_called;71 bool is_called;
66 GTM_UUID uuid;72 GTM_UUID uuid;
73+ CACHE_LEVEL is_global;
67} FormData_pg_large_sequence;74} FormData_pg_large_sequence;
68 75 
69typedef FormData_pg_large_sequence* Form_pg_large_sequence;76typedef FormData_pg_large_sequence* Form_pg_large_sequence;
@@ -83,9 +90,10 @@ typedef FormData_pg_large_sequence* Form_pg_large_sequence;
83#define SEQ_COL_CYCLE 990#define SEQ_COL_CYCLE 9
84#define SEQ_COL_CALLED 1091#define SEQ_COL_CALLED 10
85#define SEQ_COL_UUID 1192#define SEQ_COL_UUID 11
93+#define SEQ_COL_CACHELEVEL 12
86 94 
87#define SEQ_COL_FIRSTCOL SEQ_COL_NAME95#define SEQ_COL_FIRSTCOL SEQ_COL_NAME
88-#define SEQ_COL_LASTCOL SEQ_COL_UUID96+#define SEQ_COL_LASTCOL SEQ_COL_CACHELEVEL
89 97 
90#define GS_NUM_OF_BUCKETS 102498#define GS_NUM_OF_BUCKETS 1024
91 99 
@@ -122,6 +130,9 @@ typedef struct SeqTableData {
122 int128 maxval;130 int128 maxval;
123 int128 startval;131 int128 startval;
124 int64 uuid;132 int64 uuid;
133+ Oid dbOid; /* record database oid for global sequence cache */
134+ char seqkind; /* record sequence kind */
135+ bool is_global_cache; /* sequence cache level is global */
125} SeqTableData;136} SeqTableData;
126 137 
127typedef SeqTableData* SeqTable;138typedef SeqTableData* SeqTable;
@@ -151,8 +162,55 @@ typedef struct sequence_values
151 char *min_value;162 char *min_value;
152 char *cache_value;163 char *cache_value;
153 bool is_cycled;164 bool is_cycled;
165+ bool is_global;
154} sequence_values;166} sequence_values;
155 167 
168+typedef struct GSCKey
169+{
170+ Oid dbOid; /* record database oid for global sequence cache */
171+ Oid relid;
172+} GSCKey;
173+ 
174+typedef struct GSCVal
175+{
176+ SeqTableData elm;
177+} GSCVal;
178+ 
179+typedef struct GSCEntry
180+{
181+ GSCKey key;
182+ GSCVal val;
183+} GSCEntry;
184+ 
185+typedef struct GSCOid2LevelKey
186+{
187+ Oid dbOid; /* record database oid for global sequence cache */
188+ Oid relid;
189+} GSCOid2LevelKey;
190+ 
191+typedef struct GSCOid2LevelVal
192+{
193+ bool is_global_cache;
194+} GSCOid2LevelVal;
195+ 
196+typedef struct GSCOid2LevelEntry
197+{
198+ GSCOid2LevelKey key;
199+ GSCOid2LevelVal val;
200+} GSCOid2LevelEntry;
201+ 
202+struct GlobaleSeqHashTabl {
203+ struct GlobalSeqInfoHashBucket global_seq[NUM_GS_PARTITIONS];
204+ struct GSCHashCtl global_seqtab[NUM_GSC_SINGLENODE_PARTITIONS];
205+};
206+ 
207+typedef struct SeqDropCacheInfo {
208+ Oid relid;
209+ bool is_global_cache;
210+} SeqDropCacheInfo;
211+ 
212+#define GSC_HTAB_SIZE (128)
213+ 
156/*214/*
157 * We don't want to log each fetching of a value from a sequence,215 * We don't want to log each fetching of a value from a sequence,
158 * so we pre-log a few fetches in advance. In the event of216 * so we pre-log a few fetches in advance. In the event of
@@ -177,7 +235,6 @@ typedef struct sequence_magic {
177 uint32 magic;235 uint32 magic;
178} sequence_magic;236} sequence_magic;
179 237 
180- 
181extern Datum nextval(PG_FUNCTION_ARGS);238extern Datum nextval(PG_FUNCTION_ARGS);
182extern Datum nextval_oid(PG_FUNCTION_ARGS);239extern Datum nextval_oid(PG_FUNCTION_ARGS);
183extern Datum currval_oid(PG_FUNCTION_ARGS);240extern Datum currval_oid(PG_FUNCTION_ARGS);
@@ -191,6 +248,7 @@ extern Datum pg_sequence_all_parameters(PG_FUNCTION_ARGS);
191extern Datum pg_sequence_last_value(PG_FUNCTION_ARGS);248extern Datum pg_sequence_last_value(PG_FUNCTION_ARGS);
192 249 
193extern int128 nextval_internal(Oid relid);250extern int128 nextval_internal(Oid relid);
251+extern int128 nextval_internal_for_global_seq_cache(Oid relid);
194extern void autoinc_setval(Oid relid, int128 next, bool iscalled);252extern void autoinc_setval(Oid relid, int128 next, bool iscalled);
195extern int128 autoinc_get_nextval(Oid relid);253extern int128 autoinc_get_nextval(Oid relid);
196extern bool CheckSeqOwnedByAutoInc(Oid seqoid);254extern bool CheckSeqOwnedByAutoInc(Oid seqoid);
@@ -270,12 +328,21 @@ extern void fill_seq_with_data(Relation rel, HeapTuple tuple);
270extern void ResetvalGlobal(Oid relid);328extern void ResetvalGlobal(Oid relid);
271extern Relation lock_and_open_seq(SeqTable seq);329extern Relation lock_and_open_seq(SeqTable seq);
272extern void init_sequence(Oid relid, SeqTable* p_elm, Relation* p_rel);330extern void init_sequence(Oid relid, SeqTable* p_elm, Relation* p_rel);
331+extern void init_sequence_single_node_global_cache(Oid relid, SeqTable* elm, Relation* p_rel, GSCKey* key,
332+ uint32 hashCode, uint32 bucketId);
333+extern void init_sequence_single_node_global_cache_for_currval(Oid relid, SeqTable* elm, Relation* rel);
334+extern void global_sequence_cache_set_currval_elm(Oid relid, int128 value);
335+extern void removeSequenceCacheOfRelOid(List* relOids);
273extern SeqTable GetSessSeqElm(Oid relid);336extern SeqTable GetSessSeqElm(Oid relid);
274extern char* GetGlobalSeqNameForUpdate(Relation seqrel, char** dbname, char** schemaname);337extern char* GetGlobalSeqNameForUpdate(Relation seqrel, char** dbname, char** schemaname);
275extern uint32 RelidGetHash(Oid seq_relid);338extern uint32 RelidGetHash(Oid seq_relid);
339+extern uint32 GetGSCBucket(uint32 hashvalue);
276extern SeqTable GetGlobalSeqElm(Oid relid, GlobalSeqInfoHashBucket* bucket);340extern SeqTable GetGlobalSeqElm(Oid relid, GlobalSeqInfoHashBucket* bucket);
277extern Oid pg_get_serial_sequence_oid(text* tablename, text* columnname, bool find_identity = false);341extern Oid pg_get_serial_sequence_oid(text* tablename, text* columnname, bool find_identity = false);
278extern bool StrEndWith(const char *str, const char *suffix);342extern bool StrEndWith(const char *str, const char *suffix);
279typedef void (*InvokeNextvalHookType) (Oid relid, int128 val);343typedef void (*InvokeNextvalHookType) (Oid relid, int128 val);
344+template<typename T_Type>
345+extern uint32 GSCHashFunc(const void *key, Size keysize);
346+extern bool is_global_level_sequence_cache(Oid relid);
280 347 
281#endif /* SEQUENCE_H */348#endif /* SEQUENCE_H */
@@ -1239,6 +1239,11 @@ typedef struct GlobalSeqInfoHashBucket {
1239 int lock_id;1239 int lock_id;
1240} GlobalSeqInfoHashBucket;1240} GlobalSeqInfoHashBucket;
1241 1241 
1242+typedef struct GSCHashCtl {
1243+ int lock_id;
1244+ HTAB* hash_tbl;
1245+} GSCHashCtl;
1246+ 
1242typedef struct knl_g_archive_context {1247typedef struct knl_g_archive_context {
1243 XLogRecPtr barrierLsn;1248 XLogRecPtr barrierLsn;
1244 char barrierName[MAX_BARRIER_ID_LENGTH];1249 char barrierName[MAX_BARRIER_ID_LENGTH];
@@ -1624,7 +1629,12 @@ typedef struct knl_instance_context {
1624 1629 
1625 bool dummy_standby;1630 bool dummy_standby;
1626 1631 
1627- struct GlobalSeqInfoHashBucket global_seq[NUM_GS_PARTITIONS];1632+ struct GlobaleSeqHashTabl *seqHtbl;
1633+ HTAB* relid2cachelevel;
1634+ LWLock *oid_map_lock;
1635+ LWLock *alter_sequence_lock;
1636+ pthread_mutex_t glable_seq_init_lock;
1637+ bool global_seq_inited;
1628 1638 
1629 struct GlobalPlanCache* plan_cache;1639 struct GlobalPlanCache* plan_cache;
1630 1640 
@@ -858,6 +858,11 @@ typedef struct knl_u_commands_context {
858 * sequence.858 * sequence.
859 */859 */
860 struct SeqTableData* last_used_seq;860 struct SeqTableData* last_used_seq;
861+ /*
862+ * global_currval_seq is updated by nextval() to point to the current used
863+ * global sequence cache.
864+ */
865+ DList* global_currval_seq;
861 866 
862 /* Form of the type created during inplace upgrade */867 /* Form of the type created during inplace upgrade */
863 char TypeCreateType;868 char TypeCreateType;
@@ -111,11 +111,14 @@ typedef enum ObjectType {
111 OBJECT_PUBLICATION_NAMESPACE,111 OBJECT_PUBLICATION_NAMESPACE,
112 OBJECT_PUBLICATION_REL,112 OBJECT_PUBLICATION_REL,
113 OBJECT_SUBSCRIPTION,113 OBJECT_SUBSCRIPTION,
114- OBJECT_EVENT114+ OBJECT_EVENT,
115+ OBJECT_SEQUENCE_GSC,
116+ OBJECT_LARGE_SEQUENCE_GSC
115} ObjectType;117} ObjectType;
116 118 
117-#define OBJECT_IS_SEQUENCE(obj) \119+#define OBJECT_IS_SEQUENCE(obj) \
118- ((obj) == OBJECT_LARGE_SEQUENCE || (obj) == OBJECT_SEQUENCE)120+ ((obj) == OBJECT_LARGE_SEQUENCE || (obj) == OBJECT_SEQUENCE || (obj) == OBJECT_SEQUENCE_GSC || \
121+ (obj) == OBJECT_LARGE_SEQUENCE_GSC)
119 122 
120typedef enum DropBehavior {123typedef enum DropBehavior {
121 DROP_RESTRICT, /* drop fails if any dependent objects */124 DROP_RESTRICT, /* drop fails if any dependent objects */
@@ -170,6 +170,9 @@ const struct LWLOCK_PARTITION_DESC LWLockPartInfo[] = {
170/* Number of standby statement hsitory needed */170/* Number of standby statement hsitory needed */
171#define NUM_STANDBY_STMTHIST_PARTITIONS 2171#define NUM_STANDBY_STMTHIST_PARTITIONS 2
172 172 
173+/* Number of partions the global sequence cache hashtable */
174+#define NUM_GSC_SINGLENODE_PARTITIONS 1024
175+ 
173/* Number of partitions of the txnstatus mapping hashtable */176/* Number of partitions of the txnstatus mapping hashtable */
174#define NUM_TXNSTATUS_CACHE_PARTITIONS 256177#define NUM_TXNSTATUS_CACHE_PARTITIONS 256
175 178 
@@ -231,13 +234,16 @@ const struct LWLOCK_PARTITION_DESC LWLockPartInfo[] = {
231/* xlog track hashmap */234/* xlog track hashmap */
232#define FirstScanningXLOGTrackLock (FirstSSSnapshotXminCacheLock + NUM_SS_SNAPSHOT_XMIN_CACHE_PARTITIONS)235#define FirstScanningXLOGTrackLock (FirstSSSnapshotXminCacheLock + NUM_SS_SNAPSHOT_XMIN_CACHE_PARTITIONS)
233 236 
234-#define FirstCRBufMappingLock (FirstScanningXLOGTrackLock + NUM_SCANNING_XLOG_TRACK_PARTITIONS)
235-/* must be last: */
236#ifndef ENABLE_LITE_MODE237#ifndef ENABLE_LITE_MODE
237-#define NumFixedLWLocks (FirstCRBufMappingLock + NUM_BUFFER_PARTITIONS)238+#define FirstCRBufMappingLock (FirstScanningXLOGTrackLock + NUM_BUFFER_PARTITIONS)
238#else239#else
239-#define NumFixedLWLocks (FirstScanningXLOGTrackLock + NUM_SCANNING_XLOG_TRACK_PARTITIONS)240+#define FirstCRBufMappingLock FirstScanningXLOGTrackLock
240#endif241#endif
242+/* global sequence cache */
243+#define FirstGlobalSeqCacheLock (FirstCRBufMappingLock + NUM_SCANNING_XLOG_TRACK_PARTITIONS)
244+ 
245+/* must be last: */
246+#define NumFixedLWLocks (FirstGlobalSeqCacheLock + NUM_GSC_SINGLENODE_PARTITIONS)
241/*247/*
242 * WARNING----Please keep BuiltinTrancheIds and BuiltinTrancheNames consistent!!!248 * WARNING----Please keep BuiltinTrancheIds and BuiltinTrancheNames consistent!!!
243 *249 *
@@ -338,6 +344,9 @@ enum BuiltinTrancheIds
338 LWTRANCHE_CR_BUF_MAPPING,344 LWTRANCHE_CR_BUF_MAPPING,
339 LWTRANCHE_CR_BUF_LRU,345 LWTRANCHE_CR_BUF_LRU,
340 LWTRANCHE_ATF_GLOBAL_TASK,346 LWTRANCHE_ATF_GLOBAL_TASK,
347+ LWTRANCHE_GLOBAL_SEQ_CACHE,
348+ LWTRANCHE_SEQ_OID_CACHE_LEVEL_MAP,
349+ LWTRANCHE_ALTER_SEQ_CACHE_LEVEL,
341 /*350 /*
342 * Each trancheId above should have a corresponding item in BuiltinTrancheNames;351 * Each trancheId above should have a corresponding item in BuiltinTrancheNames;
343 */352 */
@@ -643,7 +643,9 @@ extern void PartitionDecrementReferenceCount(Partition part);
643 (RelationAmIsBtree(relation) && RELATION_HAS_BUCKET(relation) && RELOPTIONS_CROSSBUCKET((relation)->rd_options))643 (RelationAmIsBtree(relation) && RELATION_HAS_BUCKET(relation) && RELOPTIONS_CROSSBUCKET((relation)->rd_options))
644 644 
645#define RelationIsSequnce(relation) (RELKIND_SEQUENCE == (relation)->rd_rel->relkind || \645#define RelationIsSequnce(relation) (RELKIND_SEQUENCE == (relation)->rd_rel->relkind || \
646- RELKIND_LARGE_SEQUENCE == (relation)->rd_rel->relkind)646+ RELKIND_LARGE_SEQUENCE == (relation)->rd_rel->relkind || \
647+ RELKIND_SEQUENCE_GSC == (relation)->rd_rel->relkind || \
648+ RELKIND_LARGE_SEQUENCE_GSC == (relation)->rd_rel->relkind)
647 649 
648#define RelationIsToast(relation) (RELKIND_TOASTVALUE == (relation)->rd_rel->relkind)650#define RelationIsToast(relation) (RELKIND_TOASTVALUE == (relation)->rd_rel->relkind)
649 651 
@@ -6,45 +6,45 @@ create sequence seqa maxvalue 50;
6--test what sequence would be like before/after ALTER SEQUENCE MAXVALUE txns' rollback6--test what sequence would be like before/after ALTER SEQUENCE MAXVALUE txns' rollback
7begin;7begin;
8select * from seqa;8select * from seqa;
9- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 9+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
10----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------10+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
11- seqa | 1 | 1 | 1 | 50 | 1 | 1 | 0 | f | f | 011+ seqa | 1 | 1 | 1 | 50 | 1 | 1 | 0 | f | f | 0 | f
12(1 row)12(1 row)
13 13 
14alter sequence seqa maxvalue 40;14alter sequence seqa maxvalue 40;
15select * from seqa;15select * from seqa;
16- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 16+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
17----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------17+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
18- seqa | 1 | 1 | 1 | 40 | 1 | 1 | 0 | f | f | 018+ seqa | 1 | 1 | 1 | 40 | 1 | 1 | 0 | f | f | 0 | f
19(1 row)19(1 row)
20 20 
21rollback;21rollback;
22select * from seqa;22select * from seqa;
23- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 23+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
24----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------24+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
25- seqa | 1 | 1 | 1 | 50 | 1 | 1 | 0 | f | f | 025+ seqa | 1 | 1 | 1 | 50 | 1 | 1 | 0 | f | f | 0 | f
26(1 row)26(1 row)
27 27 
28--test what sequence would be like before/after ALTER SEQUENCE MAXVALUE txns' rollback28--test what sequence would be like before/after ALTER SEQUENCE MAXVALUE txns' rollback
29begin;29begin;
30select * from seqa;30select * from seqa;
31- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 31+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
32----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------32+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
33- seqa | 1 | 1 | 1 | 50 | 1 | 1 | 0 | f | f | 033+ seqa | 1 | 1 | 1 | 50 | 1 | 1 | 0 | f | f | 0 | f
34(1 row)34(1 row)
35 35 
36alter sequence seqa maxvalue 40;36alter sequence seqa maxvalue 40;
37select * from seqa;37select * from seqa;
38- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 38+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
39----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------39+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
40- seqa | 1 | 1 | 1 | 40 | 1 | 1 | 0 | f | f | 040+ seqa | 1 | 1 | 1 | 40 | 1 | 1 | 0 | f | f | 0 | f
41(1 row)41(1 row)
42 42 
43commit;43commit;
44select * from seqa;44select * from seqa;
45- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 45+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
46----------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------46+---------------+------------+-------------+--------------+-----------+-----------+-------------+---------+-----------+-----------+------+-----------
47- seqa | 1 | 1 | 1 | 40 | 1 | 1 | 0 | f | f | 047+ seqa | 1 | 1 | 1 | 40 | 1 | 1 | 0 | f | f | 0 | f
48(1 row)48(1 row)
49 49 
50DROP SCHEMA test_alter_seq_max_in_txn_01 CASCADE;50DROP SCHEMA test_alter_seq_max_in_txn_01 CASCADE;
@@ -259,7 +259,7 @@ FROM pg_class c WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
259 relname | relkind | hastoast 259 relname | relkind | hastoast
260----------------------+---------+----------260----------------------+---------+----------
261 clstr_tst | r | t261 clstr_tst | r | t
262- clstr_tst_a_seq | S | f262+ clstr_tst_a_seq | z | f
263 clstr_tst_b | i | f263 clstr_tst_b | i | f
264 clstr_tst_b_c | i | f264 clstr_tst_b_c | i | f
265 clstr_tst_c | i | f265 clstr_tst_c | i | f
@@ -267,7 +267,7 @@ FROM pg_class c WHERE relname LIKE 'clstr_tst%' ORDER BY relname;
267 clstr_tst_pkey | i | f267 clstr_tst_pkey | i | f
268 clstr_tst_s | r | f268 clstr_tst_s | r | f
269 clstr_tst_s_pkey | i | f269 clstr_tst_s_pkey | i | f
270- clstr_tst_s_rf_a_seq | S | f270+ clstr_tst_s_rf_a_seq | z | f
271(10 rows)271(10 rows)
272 272 
273-- Verify that indisclustered is correctly set273-- Verify that indisclustered is correctly set
@@ -187,10 +187,10 @@ SELECT * FROM information_schema.sequences WHERE sequence_name IN
187 ('sequence_test2_flt', 'sequence_test3', 'serialtest2_f3_seq',187 ('sequence_test2_flt', 'sequence_test3', 'serialtest2_f3_seq',
188 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq')188 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq')
189 ORDER BY sequence_name ASC;189 ORDER BY sequence_name ASC;
190- sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option 190+ sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option | global_cache_option
191-------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+--------------191+------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+--------------+---------------------
192- regression | public | sequence_test2_flt | int16 | 128 | 2 | 0 | 32 | 1 | 9223372036854775807 | 1 | NO192+ regression | public | sequence_test2_flt | int16 | 128 | 2 | 0 | 32 | 1 | 9223372036854775807 | 1 | NO | NO
193- regression | public | sequence_test3 | int16 | 128 | 2 | 0 | 1 | 1 | 30 | 1 | NO193+ regression | public | sequence_test3 | int16 | 128 | 2 | 0 | 1 | 1 | 30 | 1 | NO | NO
194(2 rows)194(2 rows)
195 195 
196CREATE TYPE compfoo AS (f1 int, f2 text);196CREATE TYPE compfoo AS (f1 int, f2 text);
@@ -34,6 +34,7 @@ CREATE LARGE SEQUENCE S2;
34 is_cycled | boolean | f34 is_cycled | boolean | f
35 is_called | boolean | f35 is_called | boolean | f
36 uuid | bigint | 036 uuid | bigint | 0
37+ is_global | boolean | f
37 38 
38\d S239\d S2
39 Large Sequence "large_sequence.s2"40 Large Sequence "large_sequence.s2"
@@ -50,6 +51,7 @@ CREATE LARGE SEQUENCE S2;
50 is_cycled | boolean | f51 is_cycled | boolean | f
51 is_called | boolean | f52 is_called | boolean | f
52 uuid | bigint | 053 uuid | bigint | 0
54+ is_global | boolean | f
53 55 
54COMMENT ON LARGE SEQUENCE S2 IS 'FOO';56COMMENT ON LARGE SEQUENCE S2 IS 'FOO';
55COMMENT ON LARGE SEQUENCE S2 IS NULL;57COMMENT ON LARGE SEQUENCE S2 IS NULL;
@@ -365,10 +367,12 @@ NOTICE: drop cascades to default for table tab_seq column c2
365CREATE LARGE SEQUENCE foo;367CREATE LARGE SEQUENCE foo;
366-- rename supported368-- rename supported
367ALTER LARGE SEQUENCE foo RENAME TO bar;369ALTER LARGE SEQUENCE foo RENAME TO bar;
368-SELECT * FROM foo;370+SELECT * FROM bar;
369-ERROR: relation "foo" does not exist on datanode1371+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
370-LINE 1: SELECT * FROM foo;372+---------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------+-----------
371- ^373+ foo | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0 | f
374+(1 row)
375+ 
372-- alter maxvalue - ok376-- alter maxvalue - ok
373ALTER LARGE SEQUENCE bar MAXVALUE 1000;377ALTER LARGE SEQUENCE bar MAXVALUE 1000;
374-- alter owner role -ok378-- alter owner role -ok
@@ -606,13 +610,13 @@ HINT: Use DROP ... CASCADE to drop the dependent objects too.
606DROP TABLE t1;610DROP TABLE t1;
607-- Fails because no longer existent:611-- Fails because no longer existent:
608DROP SEQUENCE t1_f1_seq;612DROP SEQUENCE t1_f1_seq;
609-ERROR: sequence "t1_f1_seq" does not exist613+--?ERROR:*
610DROP LARGE SEQUENCE myseq2;614DROP LARGE SEQUENCE myseq2;
611-- Information schema do not support large sequence for now615-- Information schema do not support large sequence for now
612SELECT * FROM information_schema.sequences WHERE sequence_name in ('myseq3');616SELECT * FROM information_schema.sequences WHERE sequence_name in ('myseq3');
613- sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option 617+ sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option | global_cache_option
614-------------------+-----------------+---------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+-----------------------------------------+-----------+--------------618+------------------+-----------------+---------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+-----------------------------------------+-----------+--------------+---------------------
615- regression | large_sequence | myseq3 | int16 | 128 | 2 | 0 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | NO619+ regression | large_sequence | myseq3 | int16 | 128 | 2 | 0 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | NO | NO
616(1 row)620(1 row)
617 621 
618-- Privilige check622-- Privilige check
@@ -622,9 +626,9 @@ GRANT SELECT ON priv_seq TO zeus;
622GRANT ALL ON SCHEMA large_sequence TO zeus;626GRANT ALL ON SCHEMA large_sequence TO zeus;
623SET ROLE zeus PASSWORD '123qwe!@#';627SET ROLE zeus PASSWORD '123qwe!@#';
624SELECT * FROM priv_seq;628SELECT * FROM priv_seq;
625- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 629+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
626----------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------630+---------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------+-----------
627- priv_seq | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0631+ priv_seq | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0 | f
628(1 row)632(1 row)
629 633 
630\d priv_seq634\d priv_seq
@@ -642,6 +646,7 @@ SELECT * FROM priv_seq;
642 is_cycled | boolean | f646 is_cycled | boolean | f
643 is_called | boolean | f647 is_called | boolean | f
644 uuid | bigint | 0648 uuid | bigint | 0
649+ is_global | boolean | f
645 650 
646SELECT nextval('priv_seq');651SELECT nextval('priv_seq');
647ERROR: permission denied for sequence priv_seq652ERROR: permission denied for sequence priv_seq
@@ -714,9 +719,9 @@ GRANT ALL ON ALL SEQUENCES IN SCHEMA seq_priv_schema TO zeus;
714SET ROLE zeus PASSWORD '123qwe!@#';719SET ROLE zeus PASSWORD '123qwe!@#';
715SET current_schema = seq_priv_schema;720SET current_schema = seq_priv_schema;
716SELECT * FROM priv_seq;721SELECT * FROM priv_seq;
717- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 722+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
718----------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------723+---------------+------------+-------------+--------------+-----------------------------------------+-----------+-------------+---------+-----------+-----------+------+-----------
719- priv_seq | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0724+ priv_seq | 1 | 1 | 1 | 170141183460469231731687303715884105727 | 1 | 1 | 0 | f | f | 0 | f
720(1 row)725(1 row)
721 726 
722\d priv_seq727\d priv_seq
@@ -734,6 +739,7 @@ SELECT * FROM priv_seq;
734 is_cycled | boolean | f739 is_cycled | boolean | f
735 is_called | boolean | f740 is_called | boolean | f
736 uuid | bigint | 0741 uuid | bigint | 0
742+ is_global | boolean | f
737 743 
738SELECT nextval('priv_seq');744SELECT nextval('priv_seq');
739 nextval 745 nextval
@@ -90,9 +90,9 @@ select setval('ss1_TESTTABLE', 10);
90(1 row)90(1 row)
91 91 
92select * from ss1_TESTTABLE;92select * from ss1_TESTTABLE;
93- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 93+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
94----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------94+---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------+-----------
95- ss1_testtable | 10 | 1 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | t | 095+ ss1_testtable | 10 | 1 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | t | 0 | f
96(1 row)96(1 row)
97 97 
98alter table s1_TESTTABLE alter column id set default nextval('ss1_TESTTABLE');98alter table s1_TESTTABLE alter column id set default nextval('ss1_TESTTABLE');
@@ -106,9 +106,9 @@ select * from s1_TESTTABLE order by id;
106(2 rows)106(2 rows)
107 107 
108select * from ss1_TESTTABLE;108select * from ss1_TESTTABLE;
109- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 109+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
110----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------110+---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------+-----------
111- ss1_testtable | 12 | 1 | 1 | 9223372036854775807 | 1 | 1 | 31 | f | t | 0111+ ss1_testtable | 12 | 1 | 1 | 9223372036854775807 | 1 | 1 | 31 | f | t | 0 | f
112(1 row)112(1 row)
113 113 
114drop table s1_TESTTABLE;114drop table s1_TESTTABLE;
@@ -182,9 +182,9 @@ DROP SEQUENCE sequence_test;
182CREATE SEQUENCE foo_seq;182CREATE SEQUENCE foo_seq;
183ALTER TABLE foo_seq RENAME TO foo_seq_new;183ALTER TABLE foo_seq RENAME TO foo_seq_new;
184SELECT * FROM foo_seq_new;184SELECT * FROM foo_seq_new;
185- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 185+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
186----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------186+---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------+-----------
187- foo_seq | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | f | 0187+ foo_seq | 1 | 1 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | f | 0 | f
188(1 row)188(1 row)
189 189 
190SELECT nextval('foo_seq_new');190SELECT nextval('foo_seq_new');
@@ -200,9 +200,9 @@ SELECT nextval('foo_seq_new');
200(1 row)200(1 row)
201 201 
202SELECT * FROM foo_seq_new;202SELECT * FROM foo_seq_new;
203- sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid 203+ sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid | is_global
204----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------204+---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------+-----------
205- foo_seq | 2 | 1 | 1 | 9223372036854775807 | 1 | 1 | 31 | f | t | 0205+ foo_seq | 2 | 1 | 1 | 9223372036854775807 | 1 | 1 | 31 | f | t | 0 | f
206(1 row)206(1 row)
207 207 
208DROP SEQUENCE foo_seq_new;208DROP SEQUENCE foo_seq_new;
@@ -316,14 +316,14 @@ SELECT * FROM information_schema.sequences WHERE sequence_name IN
316 ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq',316 ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq',
317 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq')317 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq')
318 ORDER BY sequence_name ASC;318 ORDER BY sequence_name ASC;
319- sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option 319+ sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option | global_cache_option
320-------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+--------------320+------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+--------------+---------------------
321- regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 5 | 36 | 4 | YES321+ regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 5 | 36 | 4 | YES | NO
322- regression | public | serialtest2_f2_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO322+ regression | public | serialtest2_f2_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO | NO
323- regression | public | serialtest2_f3_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO323+ regression | public | serialtest2_f3_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO | NO
324- regression | public | serialtest2_f4_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO324+ regression | public | serialtest2_f4_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO | NO
325- regression | public | serialtest2_f5_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO325+ regression | public | serialtest2_f5_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO | NO
326- regression | public | serialtest2_f6_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO326+ regression | public | serialtest2_f6_seq | int16 | 128 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO | NO
327(6 rows)327(6 rows)
328 328 
329-- Test comments329-- Test comments
@@ -397,9 +397,9 @@ SELECT * FROM information_schema.sequences WHERE sequence_name IN
397 ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq',397 ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq',
398 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq')398 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq')
399 ORDER BY sequence_name ASC;399 ORDER BY sequence_name ASC;
400- sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option 400+ sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option | global_cache_option
401-------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------+-----------+--------------401+------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------+-----------+--------------+---------------------
402- regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 5 | 36 | 4 | YES402+ regression | public | sequence_test2 | int16 | 128 | 2 | 0 | 32 | 5 | 36 | 4 | YES | NO
403(1 row)403(1 row)
404 404 
405-- test case sensitivity of index names405-- test case sensitivity of index names
@@ -457,7 +457,7 @@ ORDER BY 1;
457-- Look for illegal values in pg_class fields457-- Look for illegal values in pg_class fields
458SELECT p1.oid, p1.relname458SELECT p1.oid, p1.relname
459FROM pg_class as p1459FROM pg_class as p1
460-WHERE p1.relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f');460+WHERE p1.relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f', 'z');
461 oid | relname 461 oid | relname
462-----+---------462-----+---------
463(0 rows)463(0 rows)
@@ -394,7 +394,7 @@ ORDER BY 1;
394-- Look for illegal values in pg_class fields394-- Look for illegal values in pg_class fields
395SELECT p1.oid, p1.relname395SELECT p1.oid, p1.relname
396FROM pg_class as p1396FROM pg_class as p1
397-WHERE p1.relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f');397+WHERE p1.relkind NOT IN ('r', 'i', 's', 'S', 'c', 't', 'v', 'f', 'z');
398 oid | relname 398 oid | relname
399-----+---------399-----+---------
400(0 rows)400(0 rows)
@@ -258,6 +258,7 @@ SELECT table_name, column_name, is_updatable
258 ro_view19 | is_cycled | NO258 ro_view19 | is_cycled | NO
259 ro_view19 | is_called | NO259 ro_view19 | is_called | NO
260 ro_view19 | uuid | NO260 ro_view19 | uuid | NO
261+ ro_view19 | is_global | NO
261 ro_view2 | a | NO262 ro_view2 | a | NO
262 ro_view2 | b | NO263 ro_view2 | b | NO
263 ro_view20 | a | NO264 ro_view20 | a | NO
@@ -283,7 +284,7 @@ SELECT table_name, column_name, is_updatable
283 rw_view16 | a | YES284 rw_view16 | a | YES
284 rw_view16 | b | YES285 rw_view16 | b | YES
285 rw_view16 | aa | YES286 rw_view16 | aa | YES
286-(47 rows)287+(48 rows)
287 288 
288-- Read-only views289-- Read-only views
289DELETE FROM ro_view1;290DELETE FROM ro_view1;
@@ -0,0 +1,361 @@
1+-- ========================================
2+-- 1. D模式下的几个函数测试
3+-- ========================================
4+CREATE DATABASE compatible_db_d DBCOMPATIBILITY 'D';
5+\c compatible_db_d
6+create extension shark;
7+-- 1.1 普通序列
8+CREATE SEQUENCE pg_seq_params_seq1
9+ START 10
10+ INCREMENT 2
11+ MINVALUE 1
12+ MAXVALUE 100
13+ CACHE 5
14+ NO CYCLE
15+ GLOBAL;
16+CREATE LARGE SEQUENCE pg_seq_params_seq2
17+ START 10
18+ INCREMENT 2
19+ MINVALUE 1
20+ MAXVALUE 100
21+ CACHE 5
22+ NO CYCLE
23+ SESSION;
24+ 
25+SELECT * FROM pg_sequence_all_parameters('pg_seq_params_seq1');
26+SELECT * FROM pg_sequence_all_parameters('pg_seq_params_seq2');
27+ 
28+-- 清理 pg_sequence_all_parameters 相关
29+DROP SEQUENCE pg_seq_params_seq1;
30+DROP LARGE SEQUENCE pg_seq_params_seq2;
31+ 
32+-- 4.2 若已加载 shark,可在 shark 测试 schema 中建表并调用(与 contrib/shark 用例一致)
33+-- 这里创建本地表并尝试调用,便于在安装 shark 的环境中覆盖
34+CREATE SCHEMA IF NOT EXISTS dbcc_coverage_schema;
35+CREATE SEQUENCE dbcc_coverage_schema.test_seq1
36+ START 10
37+ INCREMENT 2
38+ MINVALUE 1
39+ MAXVALUE 100
40+ CACHE 5
41+ NO CYCLE
42+ GLOBAL;
43+CREATE LARGE SEQUENCE dbcc_coverage_schema.test_seq2
44+ START 10
45+ INCREMENT 2
46+ MINVALUE 1
47+ MAXVALUE 100
48+ CACHE 5
49+ NO CYCLE
50+ GLOBAL;
51+ 
52+CREATE TABLE dbcc_coverage_schema.ident_tab (id bigint PRIMARY KEY DEFAULT nextval('dbcc_coverage_schema.test_seq1'), name char);
53+CREATE TABLE dbcc_coverage_schema.ident_tab1 (id bigint PRIMARY KEY DEFAULT nextval('dbcc_coverage_schema.test_seq2'), name char);
54+INSERT INTO dbcc_coverage_schema.ident_tab(name) VALUES ('a'), ('b'), ('c');
55+INSERT INTO dbcc_coverage_schema.ident_tab1(name) VALUES ('a'), ('b'), ('c');
56+ 
57+DO $$
58+BEGIN
59+ IF EXISTS (
60+ SELECT 1 FROM pg_proc p
61+ JOIN pg_namespace n ON p.pronamespace = n.oid
62+ WHERE n.nspname = 'sys' AND p.proname = 'dbcc_check_ident_reseed'
63+ ) THEN
64+ PERFORM sys.dbcc_check_ident_reseed('dbcc_coverage_schema.ident_tab', 100::bigint, true);
65+ PERFORM sys.dbcc_check_ident_reseed('dbcc_coverage_schema.ident_tab', 50::bigint, false);
66+ PERFORM sys.dbcc_check_ident_reseed('dbcc_coverage_schema.ident_tab1', 100::int16, true);
67+ PERFORM sys.dbcc_check_ident_reseed('dbcc_coverage_schema.ident_tab1', 50::int16, false);
68+ END IF;
69+EXCEPTION
70+ WHEN OTHERS THEN
71+ NULL;
72+END;
73+$$;
74+ 
75+-- copy identity(start/increment) of source table in SELECT INTO clause for D format
76+CREATE TABLE tbl_identity (id bigint identity(1,1), name VARCHAR(100));
77+select * into tbl1 from tbl_identity where id % 2 != 0;
78+ 
79+drop table tbl_identity cascade;
80+ 
81+DROP SCHEMA dbcc_coverage_schema cascade;
82+ 
83+\c regression
84+DROP DATABASE compatible_db_d;
85+ 
86+-- ========================================
87+-- 2. publication_deparse_table_rewrite()
88+-- 仅在 table_rewrite 事件触发器内调用,对支持 DDL 复制的表进行 deparse 并记录
89+-- 通过:创建 publication(with ddl) -> 建表 -> 执行触发 table_rewrite 的 ALTER
90+-- ========================================
91+ 
92+-- 2.1 直接调用会报错(非事件触发器上下文),捕获错误以便脚本继续
93+DO $$
94+BEGIN
95+ PERFORM publication_deparse_table_rewrite();
96+EXCEPTION WHEN OTHERS THEN
97+ RAISE NOTICE 'expected: not fired by event trigger manager';
98+END;
99+$$;
100+ 
101+-- 2.2 通过 publication + table_rewrite 触发
102+CREATE SEQUENCE test_seq1
103+ START 10
104+ INCREMENT 2
105+ MINVALUE 1
106+ MAXVALUE 100
107+ CACHE 5
108+ NO CYCLE
109+ GLOBAL;
110+ 
111+create large sequence test_large_seq1 global;
112+ 
113+CREATE TABLE rewrite_tab (a int PRIMARY KEY DEFAULT nextval('test_seq1'), b char);
114+INSERT INTO rewrite_tab(b) VALUES ('x'), ('y'), ('z');
115+ 
116+CREATE TABLE rewrite_tab1 (a int PRIMARY KEY DEFAULT nextval('test_large_seq1'), b char);
117+INSERT INTO rewrite_tab1(b) VALUES ('x'), ('y'), ('z');
118+ 
119+-- 创建带 DDL 的 publication,会注册 table_rewrite 等事件触发器
120+CREATE PUBLICATION pub_deparse_rewrite FOR ALL TABLES WITH (ddl = 'table');
121+ 
122+-- 执行会触发 table_rewrite 的 ALTER(例如改列类型导致重写)
123+alter sequence test_seq1 session;
124+alter sequence test_seq1 global;
125+alter sequence if exists test_seq1 session;
126+alter sequence if exists test_seq1 global;
127+alter large sequence test_large_seq1 session;
128+alter large sequence test_large_seq1 global;
129+alter large sequence if exists test_large_seq1 session;
130+alter large sequence if exists test_large_seq1 global;
131+ 
132+create sequence test_seq_1 start with 1 increment by 1 cache 20 global;
133+create large sequence test_seq_2 start with 1 increment by 1 cache 20 global;
134+alter extension hstore add sequence test_seq1;
135+alter extension hstore drop sequence test_seq1;
136+SECURITY LABEL ON sequence test_seq IS 'classified';
137+alter sequence test_seq1 RENAME TO test_seq1_new;
138+alter sequence if exists test_seq1_new RENAME TO test_seq1;
139+alter large sequence test_large_seq1 RENAME TO test_large_seq1_new;
140+alter large sequence if exists test_large_seq1_new RENAME TO test_large_seq1;
141+create schema test_sch;
142+alter sequence test_seq_1 set SCHEMA test_sch;
143+alter sequence if exists test_seq_1 set SCHEMA test_sch;
144+alter large sequence test_seq_2 set SCHEMA test_sch;
145+alter large sequence if exists test_seq_2 set SCHEMA test_sch;
146+drop schema test_sch;
147+drop sequence test_seq_1;
148+drop large sequence test_seq_2;
149+ 
150+-- 再执行一种会触发 rewrite 的变更(如设 NOT NULL + 默认值导致重写,视实现而定)
151+-- ALTER TABLE rewrite_tab ALTER COLUMN b SET NOT NULL;
152+ 
153+-- 清理
154+DROP PUBLICATION pub_deparse_rewrite;
155+DROP TABLE rewrite_tab;
156+DROP TABLE rewrite_tab1;
157+DROP SEQUENCE test_seq1;
158+DROP LARGE SEQUENCE test_large_seq1;
159+ 
160+-- ========================================
161+-- 3. pg_sequence_all_parameters(sequence_name text)
162+-- 返回序列的全部参数: start_value, minimum_value, maximum_value, increment,
163+-- cycle_option, cache_size, last_value, is_called, log_cnt, uuid,
164+-- last_used_value, is_exhausted
165+-- ========================================
166+ 
167+-- 3.1 普通序列
168+CREATE SEQUENCE pg_seq_params_seq1
169+ START 10
170+ INCREMENT 2
171+ MINVALUE 1
172+ MAXVALUE 100
173+ CACHE 5
174+ NO CYCLE;
175+ 
176+SELECT * FROM pg_sequence_all_parameters('pg_seq_params_seq1');
177+ 
178+-- 按列查询
179+SELECT start_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
180+SELECT minimum_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
181+SELECT maximum_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
182+SELECT increment FROM pg_sequence_all_parameters('pg_seq_params_seq1');
183+SELECT cycle_option FROM pg_sequence_all_parameters('pg_seq_params_seq1');
184+SELECT cache_size FROM pg_sequence_all_parameters('pg_seq_params_seq1');
185+SELECT last_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
186+SELECT is_called FROM pg_sequence_all_parameters('pg_seq_params_seq1');
187+SELECT log_cnt FROM pg_sequence_all_parameters('pg_seq_params_seq1');
188+SELECT uuid FROM pg_sequence_all_parameters('pg_seq_params_seq1');
189+SELECT last_used_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
190+SELECT is_exhausted FROM pg_sequence_all_parameters('pg_seq_params_seq1');
191+ 
192+-- 调用 nextval 后再查
193+SELECT nextval('pg_seq_params_seq1');
194+SELECT nextval('pg_seq_params_seq1');
195+SELECT last_value, is_called, last_used_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
196+ 
197+-- 3.2 带 schema 的序列
198+CREATE SCHEMA test_seq_params_schema;
199+CREATE SEQUENCE test_seq_params_schema.seq2 START 1 INCREMENT 1;
200+SELECT * FROM pg_sequence_all_parameters('test_seq_params_schema.seq2');
201+SELECT nextval('test_seq_params_schema.seq2');
202+SELECT last_used_value FROM pg_sequence_all_parameters('test_seq_params_schema.seq2');
203+DROP SCHEMA test_seq_params_schema cascade;
204+ 
205+-- 3.3 CYCLE 序列
206+CREATE SEQUENCE pg_seq_params_cycle
207+ START 1 INCREMENT 1 MAXVALUE 3 MINVALUE 1 CYCLE;
208+SELECT nextval('pg_seq_params_cycle');
209+SELECT nextval('pg_seq_params_cycle');
210+SELECT nextval('pg_seq_params_cycle');
211+SELECT nextval('pg_seq_params_cycle');
212+SELECT cycle_option, is_exhausted FROM pg_sequence_all_parameters('pg_seq_params_cycle');
213+ 
214+-- 3.4 表上的 serial 对应序列
215+CREATE TABLE pg_seq_params_tab (id serial PRIMARY KEY, data text);
216+INSERT INTO pg_seq_params_tab(data) VALUES ('a'), ('b');
217+SELECT * FROM pg_sequence_all_parameters('pg_seq_params_tab_id_seq');
218+SELECT last_used_value FROM pg_sequence_all_parameters('pg_seq_params_tab_id_seq');
219+ 
220+-- 3.5 错误: 非序列对象(捕获错误以便脚本继续)
221+DO $$
222+BEGIN
223+ PERFORM (SELECT pg_sequence_all_parameters('pg_seq_params_tab'));
224+EXCEPTION WHEN OTHERS THEN
225+ RAISE NOTICE 'expected: not a sequence';
226+END;
227+$$;
228+ 
229+-- 3.6 错误: 不存在的序列(捕获错误以便脚本继续)
230+DO $$
231+BEGIN
232+ PERFORM (SELECT pg_sequence_all_parameters('nonexistent_seq_xyz'));
233+EXCEPTION WHEN OTHERS THEN
234+ RAISE NOTICE 'expected: sequence does not exist';
235+END;
236+$$;
237+ 
238+-- 清理 pg_sequence_all_parameters 相关
239+DROP TABLE pg_seq_params_tab;
240+DROP SEQUENCE pg_seq_params_cycle;
241+DROP SEQUENCE pg_seq_params_seq1;
242+ 
243+-- ========================================
244+-- 4. pg_sequence_all_parameters(sequence_name text)
245+-- 返回序列的全部参数: start_value, minimum_value, maximum_value, increment,
246+-- cycle_option, cache_size, last_value, is_called, log_cnt, uuid,
247+-- last_used_value, is_exhausted
248+-- ========================================
249+ 
250+-- 4.1 普通LARGE序列
251+CREATE LARGE SEQUENCE pg_seq_params_seq1
252+ START 10
253+ INCREMENT 2
254+ MINVALUE 1
255+ MAXVALUE 100
256+ CACHE 5
257+ NO CYCLE;
258+ 
259+SELECT * FROM pg_sequence_all_parameters('pg_seq_params_seq1');
260+ 
261+-- 按列查询
262+SELECT start_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
263+SELECT minimum_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
264+SELECT maximum_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
265+SELECT increment FROM pg_sequence_all_parameters('pg_seq_params_seq1');
266+SELECT cycle_option FROM pg_sequence_all_parameters('pg_seq_params_seq1');
267+SELECT cache_size FROM pg_sequence_all_parameters('pg_seq_params_seq1');
268+SELECT last_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
269+SELECT is_called FROM pg_sequence_all_parameters('pg_seq_params_seq1');
270+SELECT log_cnt FROM pg_sequence_all_parameters('pg_seq_params_seq1');
271+SELECT uuid FROM pg_sequence_all_parameters('pg_seq_params_seq1');
272+SELECT last_used_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
273+SELECT is_exhausted FROM pg_sequence_all_parameters('pg_seq_params_seq1');
274+ 
275+-- 调用 nextval 后再查
276+SELECT nextval('pg_seq_params_seq1');
277+SELECT nextval('pg_seq_params_seq1');
278+SELECT last_value, is_called, last_used_value FROM pg_sequence_all_parameters('pg_seq_params_seq1');
279+ 
280+-- 4.2 带 schema 的序列
281+CREATE SCHEMA test_seq_params_schema;
282+CREATE LARGE SEQUENCE test_seq_params_schema.seq2 START 1 INCREMENT 1;
283+SELECT * FROM pg_sequence_all_parameters('test_seq_params_schema.seq2');
284+SELECT nextval('test_seq_params_schema.seq2');
285+SELECT last_used_value FROM pg_sequence_all_parameters('test_seq_params_schema.seq2');
286+DROP SCHEMA test_seq_params_schema cascade;
287+ 
288+-- 4.3 CYCLE 序列
289+CREATE LARGE SEQUENCE pg_seq_params_cycle
290+ START 1 INCREMENT 1 MAXVALUE 3 MINVALUE 1 CYCLE;
291+SELECT nextval('pg_seq_params_cycle');
292+SELECT nextval('pg_seq_params_cycle');
293+SELECT nextval('pg_seq_params_cycle');
294+SELECT nextval('pg_seq_params_cycle');
295+SELECT cycle_option, is_exhausted FROM pg_sequence_all_parameters('pg_seq_params_cycle');
296+ 
297+-- 4.4 表上的 serial 对应序列
298+CREATE TABLE pg_seq_params_tab (id serial PRIMARY KEY, data text);
299+INSERT INTO pg_seq_params_tab(data) VALUES ('a'), ('b');
300+SELECT * FROM pg_sequence_all_parameters('pg_seq_params_tab_id_seq');
301+SELECT last_used_value FROM pg_sequence_all_parameters('pg_seq_params_tab_id_seq');
302+ 
303+-- 4.5 错误: 非序列对象(捕获错误以便脚本继续)
304+DO $$
305+BEGIN
306+ PERFORM (SELECT pg_sequence_all_parameters('pg_seq_params_tab'));
307+EXCEPTION WHEN OTHERS THEN
308+ RAISE NOTICE 'expected: not a sequence';
309+END;
310+$$;
311+ 
312+-- 4.6 错误: 不存在的序列(捕获错误以便脚本继续)
313+DO $$
314+BEGIN
315+ PERFORM (SELECT pg_sequence_all_parameters('nonexistent_seq_xyz'));
316+EXCEPTION WHEN OTHERS THEN
317+ RAISE NOTICE 'expected: sequence does not exist';
318+END;
319+$$;
320+ 
321+-- 清理 pg_sequence_all_parameters 相关
322+DROP TABLE pg_seq_params_tab;
323+DROP LARGE SEQUENCE pg_seq_params_cycle;
324+DROP LARGE SEQUENCE pg_seq_params_seq1;
325+ 
326+CREATE DATABASE test_db_b DBCOMPATIBILITY 'B';
327+\c test_db_b
328+ 
329+-- test reset sequence
330+CREATE TABLE truncate_a (id int auto_increment primary key, name VARCHAR(64));
331+insert into truncate_a(name) values ('a001'), ('a002'),('a003'),('a004');
332+truncate TABLE truncate_a ;
333+select get_auto_increment_nextval('truncate_a'::regclass::oid, false);
334+select get_auto_increment_nextval('truncate_a'::regclass::oid, true);
335+alter large sequence truncate_a_id_seq global;
336+truncate TABLE truncate_a ;
337+select get_auto_increment_nextval('truncate_a'::regclass::oid, false);
338+select get_auto_increment_nextval('truncate_a'::regclass::oid, true);
339+ 
340+-- 模拟64-bit sequence
341+update pg_class set relkind='z' where relname='truncate_a_id_seq';
342+select get_auto_increment_nextval('truncate_a'::regclass::oid, false);
343+select get_auto_increment_nextval('truncate_a'::regclass::oid, true);
344+update pg_class set relkind='Z' where relname='truncate_a_id_seq';
345+drop table truncate_a cascade;
346+ 
347+\c regression
348+drop database test_db_b;
349+ 
350+-- add Coverage 1
351+create tablespace ts1 location '/tmp/ts1';
352+create tablespace ts2 location '/tmp/ts2';
353+create database test_db_ts tablespace ts1;
354+\c test_db_ts
355+create table tbl1(id bigserial PRIMARY KEY, data text) tablespace ts2;
356+drop table tbl1 ;
357+ 
358+\c regression
359+drop database test_db_ts;
360+drop tablespace ts1;
361+drop tablespace ts2;