From 8fd0aff620dfdd03943e1f54f261d2741edafbc0 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Wed, 28 Sep 2022 18:22:53 +0300 Subject: [PATCH] Ensure no dependencies to index before drop (cherry picked from commit 11a9a3771fcab97447a6e910aaae27d19e92f5ce) --- .../columnar/sql/columnar--10.2-2--10.2-3.sql | 11 +++++++++++ .../sql/downgrades/columnar--10.2-1--10.1-1.sql | 11 +++++++++++ .../sql/downgrades/columnar--10.2-3--10.2-2.sql | 12 +++++++++++- src/test/regress/expected/multi_extension.out | 4 ---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/backend/columnar/sql/columnar--10.2-2--10.2-3.sql b/src/backend/columnar/sql/columnar--10.2-2--10.2-3.sql index db0d8e785..25e0aade4 100644 --- a/src/backend/columnar/sql/columnar--10.2-2--10.2-3.sql +++ b/src/backend/columnar/sql/columnar--10.2-2--10.2-3.sql @@ -10,6 +10,17 @@ -- -- To do that, drop stripe_first_row_number_idx and create a unique -- constraint with the same name to keep the code change at minimum. +-- +-- If we have a pg_depend entry for this index, we can not drop it as +-- the extension depends on it. Remove the pg_depend entry if it exists. +DELETE FROM pg_depend +WHERE classid = 'pg_am'::regclass::oid + AND objid IN (select oid from pg_am where amname = 'columnar') + AND objsubid = 0 + AND refclassid = 'pg_class'::regclass::oid + AND refobjid = 'columnar.stripe_first_row_number_idx'::regclass::oid + AND refobjsubid = 0 + AND deptype = 'n'; DROP INDEX columnar.stripe_first_row_number_idx; ALTER TABLE columnar.stripe ADD CONSTRAINT stripe_first_row_number_idx UNIQUE (storage_id, first_row_number); diff --git a/src/backend/columnar/sql/downgrades/columnar--10.2-1--10.1-1.sql b/src/backend/columnar/sql/downgrades/columnar--10.2-1--10.1-1.sql index 5438a5dc4..1dc19d296 100644 --- a/src/backend/columnar/sql/downgrades/columnar--10.2-1--10.1-1.sql +++ b/src/backend/columnar/sql/downgrades/columnar--10.2-1--10.1-1.sql @@ -8,5 +8,16 @@ DROP FUNCTION citus_internal.upgrade_columnar_storage(regclass); DROP FUNCTION citus_internal.downgrade_columnar_storage(regclass); -- drop "first_row_number" column and the index defined on it +-- +-- If we have a pg_depend entry for this index, we can not drop it as +-- the extension depends on it. Remove the pg_depend entry if it exists. +DELETE FROM pg_depend +WHERE classid = 'pg_am'::regclass::oid + AND objid IN (select oid from pg_am where amname = 'columnar') + AND objsubid = 0 + AND refclassid = 'pg_class'::regclass::oid + AND refobjid = 'columnar.stripe_first_row_number_idx'::regclass::oid + AND refobjsubid = 0 + AND deptype = 'n'; DROP INDEX columnar.stripe_first_row_number_idx; ALTER TABLE columnar.stripe DROP COLUMN first_row_number; diff --git a/src/backend/columnar/sql/downgrades/columnar--10.2-3--10.2-2.sql b/src/backend/columnar/sql/downgrades/columnar--10.2-3--10.2-2.sql index fc525accd..85162f879 100644 --- a/src/backend/columnar/sql/downgrades/columnar--10.2-3--10.2-2.sql +++ b/src/backend/columnar/sql/downgrades/columnar--10.2-3--10.2-2.sql @@ -1,4 +1,14 @@ -- columnar--10.2-3--10.2-2.sql - +-- +-- If we have a pg_depend entry for this index, we can not drop it as +-- the extension depends on it. Remove the pg_depend entry if it exists. +DELETE FROM pg_depend +WHERE classid = 'pg_am'::regclass::oid + AND objid IN (select oid from pg_am where amname = 'columnar') + AND objsubid = 0 + AND refclassid = 'pg_class'::regclass::oid + AND refobjid = 'columnar.stripe_first_row_number_idx'::regclass::oid + AND refobjsubid = 0 + AND deptype = 'n'; ALTER TABLE columnar.stripe DROP CONSTRAINT stripe_first_row_number_idx; CREATE INDEX stripe_first_row_number_idx ON columnar.stripe USING BTREE(storage_id, first_row_number); diff --git a/src/test/regress/expected/multi_extension.out b/src/test/regress/expected/multi_extension.out index 64c7f2593..8bded7eca 100644 --- a/src/test/regress/expected/multi_extension.out +++ b/src/test/regress/expected/multi_extension.out @@ -918,11 +918,7 @@ SELECT * FROM multi_extension.print_extension_changes(); -- There was a bug when downgrading to 10.2-2 from 10.2-4 -- Test that we do not have any issues with this particular downgrade ALTER EXTENSION citus UPDATE TO '10.2-2'; -ERROR: cannot drop constraint stripe_first_row_number_idx on table columnar.stripe because other objects depend on it -DETAIL: access method columnar depends on index columnar.stripe_first_row_number_idx -HINT: Use DROP ... CASCADE to drop the dependent objects too. ALTER EXTENSION citus UPDATE TO '10.2-4'; -NOTICE: version "10.2-4" of extension "citus" is already installed SELECT * FROM multi_extension.print_extension_changes(); previous_object | current_object ---------------------------------------------------------------------