Skip to content

Commit

Permalink
Adjust print_extension_changes function for extra type outputs in PG17
Browse files Browse the repository at this point in the history
In PG17, Auto-generated array types, multirange types, and relation rowtypes
are treated as dependent objects, hence changing the output of the
print_extension_changes function.

Relevant PG commit:
e5bc9454e527b1cba97553531d8d4992892fdeef
postgres/postgres@e5bc945

Here we create a table with only the basic extension types
in order to avoid printing extra ones for now
This can be removed when we drop PG16 support.
  • Loading branch information
naisila committed Nov 22, 2024
1 parent e108bb8 commit 85b11f9
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 7 deletions.
32 changes: 28 additions & 4 deletions src/test/regress/expected/multi_extension.out
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ $definition$ create_function_test_maintenance_worker
CREATE TABLE multi_extension.prev_objects(description text);
CREATE TABLE multi_extension.extension_diff(previous_object text COLLATE "C",
current_object text COLLATE "C");
-- In PG17, Auto-generated array types, multirange types, and relation rowtypes
-- are treated as dependent objects, hence changing the output of the
-- print_extension_changes function.
-- Relevant PG commit: e5bc9454e527b1cba97553531d8d4992892fdeef
-- Here we create a table with only the basic extension types
-- in order to avoid printing extra ones for now
-- This can be removed when we drop PG16 support.
CREATE TABLE multi_extension.extension_basic_types (description text);
INSERT INTO multi_extension.extension_basic_types VALUES ('type citus.distribution_type'),
('type citus.shard_transfer_mode'),
('type citus_copy_format'),
('type noderole'),
('type citus_job_status'),
('type citus_task_status'),
('type replication_slot_info'),
('type split_copy_info'),
('type split_shard_info'),
('type cluster_clock');
CREATE FUNCTION multi_extension.print_extension_changes()
RETURNS TABLE(previous_object text, current_object text)
AS $func$
Expand All @@ -53,14 +71,17 @@ BEGIN
WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
AND refobjid = e.oid
AND deptype = 'e'
AND e.extname='citus';
AND e.extname='citus'
AND (pg_catalog.pg_describe_object(classid, objid, 0) NOT LIKE 'type%'
OR
pg_catalog.pg_describe_object(classid, objid, 0) IN (SELECT * FROM extension_basic_types));

INSERT INTO extension_diff
SELECT p.description previous_object, c.description current_object
FROM current_objects c FULL JOIN prev_objects p
ON p.description = c.description
WHERE (p.description is null OR c.description is null)
AND c.description IS DISTINCT FROM 'function any_value(anyelement) anyelement'
AND c.description IS DISTINCT FROM 'function any_value(anyelement) anyelement'
AND c.description IS DISTINCT FROM 'function any_value_agg(anyelement,anyelement) anyelement';

DROP TABLE prev_objects;
Expand Down Expand Up @@ -88,7 +109,8 @@ FROM pg_depend AS pgd,
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal')
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal') AND
pgio.type != 'type'
ORDER BY 1, 2;
type | identity
---------------------------------------------------------------------
Expand Down Expand Up @@ -1424,7 +1446,8 @@ FROM pg_depend AS pgd,
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal')
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal') AND
pgio.type != 'type'
ORDER BY 1, 2;
type | identity
---------------------------------------------------------------------
Expand Down Expand Up @@ -1914,6 +1937,7 @@ RESET citus.enable_schema_based_sharding;
DROP EXTENSION citus;
CREATE EXTENSION citus;
DROP TABLE version_mismatch_table;
DROP TABLE multi_extension.extension_basic_types;
DROP SCHEMA multi_extension;
ERROR: cannot drop schema multi_extension because other objects depend on it
DETAIL: function multi_extension.print_extension_changes() depends on schema multi_extension
Expand Down
22 changes: 22 additions & 0 deletions src/test/regress/expected/upgrade_list_citus_objects.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
-- In PG17, Auto-generated array types, multirange types, and relation rowtypes
-- are treated as dependent objects, hence changing the output of the
-- print_extension_changes function.
-- Relevant PG commit: e5bc9454e527b1cba97553531d8d4992892fdeef
-- Here we create a table with only the basic extension types
-- in order to avoid printing extra ones for now
-- This can be removed when we drop PG16 support.
CREATE TABLE extension_basic_types (description text);
INSERT INTO extension_basic_types VALUES ('type citus.distribution_type'),
('type citus.shard_transfer_mode'),
('type citus_copy_format'),
('type noderole'),
('type citus_job_status'),
('type citus_task_status'),
('type replication_slot_info'),
('type split_copy_info'),
('type split_shard_info'),
('type cluster_clock');
-- list all postgres objects belonging to the citus extension
SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS description
FROM pg_catalog.pg_depend, pg_catalog.pg_extension e
WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
AND refobjid = e.oid
AND deptype = 'e'
AND e.extname='citus'
AND (pg_catalog.pg_describe_object(classid, objid, 0) NOT LIKE 'type%'
OR
pg_catalog.pg_describe_object(classid, objid, 0) IN (SELECT * FROM extension_basic_types))
AND pg_catalog.pg_describe_object(classid, objid, 0) != 'function any_value(anyelement)'
AND pg_catalog.pg_describe_object(classid, objid, 0) != 'function any_value_agg(anyelement,anyelement)'
ORDER BY 1;
Expand Down Expand Up @@ -345,3 +366,4 @@ ORDER BY 1;
view time_partitions
(333 rows)

DROP TABLE extension_basic_types;
32 changes: 29 additions & 3 deletions src/test/regress/sql/multi_extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ CREATE TABLE multi_extension.prev_objects(description text);
CREATE TABLE multi_extension.extension_diff(previous_object text COLLATE "C",
current_object text COLLATE "C");

-- In PG17, Auto-generated array types, multirange types, and relation rowtypes
-- are treated as dependent objects, hence changing the output of the
-- print_extension_changes function.
-- Relevant PG commit: e5bc9454e527b1cba97553531d8d4992892fdeef
-- Here we create a table with only the basic extension types
-- in order to avoid printing extra ones for now
-- This can be removed when we drop PG16 support.

CREATE TABLE multi_extension.extension_basic_types (description text);
INSERT INTO multi_extension.extension_basic_types VALUES ('type citus.distribution_type'),
('type citus.shard_transfer_mode'),
('type citus_copy_format'),
('type noderole'),
('type citus_job_status'),
('type citus_task_status'),
('type replication_slot_info'),
('type split_copy_info'),
('type split_shard_info'),
('type cluster_clock');

CREATE FUNCTION multi_extension.print_extension_changes()
RETURNS TABLE(previous_object text, current_object text)
AS $func$
Expand All @@ -57,7 +77,10 @@ BEGIN
WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
AND refobjid = e.oid
AND deptype = 'e'
AND e.extname='citus';
AND e.extname='citus'
AND (pg_catalog.pg_describe_object(classid, objid, 0) NOT LIKE 'type%'
OR
pg_catalog.pg_describe_object(classid, objid, 0) IN (SELECT * FROM extension_basic_types));

INSERT INTO extension_diff
SELECT p.description previous_object, c.description current_object
Expand Down Expand Up @@ -90,7 +113,8 @@ FROM pg_depend AS pgd,
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal')
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal') AND
pgio.type != 'type'
ORDER BY 1, 2;


Expand Down Expand Up @@ -647,7 +671,8 @@ FROM pg_depend AS pgd,
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal')
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'columnar', 'columnar_internal') AND
pgio.type != 'type'
ORDER BY 1, 2;

-- see incompatible version errors out
Expand Down Expand Up @@ -1015,4 +1040,5 @@ DROP EXTENSION citus;
CREATE EXTENSION citus;

DROP TABLE version_mismatch_table;
DROP TABLE multi_extension.extension_basic_types;
DROP SCHEMA multi_extension;
25 changes: 25 additions & 0 deletions src/test/regress/sql/upgrade_list_citus_objects.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
-- In PG17, Auto-generated array types, multirange types, and relation rowtypes
-- are treated as dependent objects, hence changing the output of the
-- print_extension_changes function.
-- Relevant PG commit: e5bc9454e527b1cba97553531d8d4992892fdeef
-- Here we create a table with only the basic extension types
-- in order to avoid printing extra ones for now
-- This can be removed when we drop PG16 support.
CREATE TABLE extension_basic_types (description text);
INSERT INTO extension_basic_types VALUES ('type citus.distribution_type'),
('type citus.shard_transfer_mode'),
('type citus_copy_format'),
('type noderole'),
('type citus_job_status'),
('type citus_task_status'),
('type replication_slot_info'),
('type split_copy_info'),
('type split_shard_info'),
('type cluster_clock');

-- list all postgres objects belonging to the citus extension
SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS description
FROM pg_catalog.pg_depend, pg_catalog.pg_extension e
WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass
AND refobjid = e.oid
AND deptype = 'e'
AND e.extname='citus'
AND e.extname='citus'
AND (pg_catalog.pg_describe_object(classid, objid, 0) NOT LIKE 'type%'
OR
pg_catalog.pg_describe_object(classid, objid, 0) IN (SELECT * FROM extension_basic_types))
AND pg_catalog.pg_describe_object(classid, objid, 0) != 'function any_value(anyelement)'
AND pg_catalog.pg_describe_object(classid, objid, 0) != 'function any_value_agg(anyelement,anyelement)'
ORDER BY 1;

DROP TABLE extension_basic_types;

0 comments on commit 85b11f9

Please sign in to comment.