Commit 040da423 authored by Alvaro Herrera's avatar Alvaro Herrera

Enable failure to rename a partitioned index

Concurrently with partitioned index development (commit 8b08f7d4),
the code to handle failure to rename indexes was refactored (commit
8b9e9644).  Turns out that that particular case was untested, which
naturally led it to be broken.  Add tests and the missing code line.
Co-authored-by: default avatarDavid Rowley <dgrowley@gmail.com>
Co-authored-by: default avatarÁlvaro Herrera <alvherre@alvh.no-ip.org>
Reported-by: default avatarRajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>
Discussion: https://postgr.es/m/CAKcux6mfYMS3OX0ywjOiWiGSEKhJf-1zdeTceHFbd0mScUzU5A@mail.gmail.com
parent bbbbc2f8
...@@ -5248,6 +5248,7 @@ get_relkind_objtype(char relkind) ...@@ -5248,6 +5248,7 @@ get_relkind_objtype(char relkind)
case RELKIND_PARTITIONED_TABLE: case RELKIND_PARTITIONED_TABLE:
return OBJECT_TABLE; return OBJECT_TABLE;
case RELKIND_INDEX: case RELKIND_INDEX:
case RELKIND_PARTITIONED_INDEX:
return OBJECT_INDEX; return OBJECT_INDEX;
case RELKIND_SEQUENCE: case RELKIND_SEQUENCE:
return OBJECT_SEQUENCE; return OBJECT_SEQUENCE;
......
...@@ -159,6 +159,24 @@ SELECT * FROM attmp_new2; ...@@ -159,6 +159,24 @@ SELECT * FROM attmp_new2;
DROP TABLE attmp_new; DROP TABLE attmp_new;
DROP TABLE attmp_new2; DROP TABLE attmp_new2;
-- check rename of partitioned tables and indexes also
CREATE TABLE part_attmp (a int primary key) partition by range (a);
CREATE TABLE part_attmp1 PARTITION OF part_attmp FOR VALUES FROM (0) TO (100);
ALTER INDEX part_attmp_pkey RENAME TO part_attmp_index;
ALTER INDEX part_attmp1_pkey RENAME TO part_attmp1_index;
ALTER TABLE part_attmp RENAME TO part_at2tmp;
ALTER TABLE part_attmp1 RENAME TO part_at2tmp1;
SET ROLE regress_alter_table_user1;
ALTER INDEX part_attmp_index RENAME TO fail;
ERROR: must be owner of index part_attmp_index
ALTER INDEX part_attmp1_index RENAME TO fail;
ERROR: must be owner of index part_attmp1_index
ALTER TABLE part_at2tmp RENAME TO fail;
ERROR: must be owner of table part_at2tmp
ALTER TABLE part_at2tmp1 RENAME TO fail;
ERROR: must be owner of table part_at2tmp1
RESET ROLE;
DROP TABLE part_at2tmp;
-- --
-- check renaming to a table's array type's autogenerated name -- check renaming to a table's array type's autogenerated name
-- (the array type's name should get out of the way) -- (the array type's name should get out of the way)
......
...@@ -19,6 +19,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs ...@@ -19,6 +19,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs
CREATE TABLE addr_nsp.gentable ( CREATE TABLE addr_nsp.gentable (
a serial primary key CONSTRAINT a_chk CHECK (a > 0), a serial primary key CONSTRAINT a_chk CHECK (a > 0),
b text DEFAULT 'hello'); b text DEFAULT 'hello');
CREATE TABLE addr_nsp.parttable (
a int PRIMARY KEY
) PARTITION BY RANGE (a);
CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable; CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable;
CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable; CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
CREATE TYPE addr_nsp.gencomptype AS (a int); CREATE TYPE addr_nsp.gencomptype AS (a int);
...@@ -368,7 +371,9 @@ ERROR: name list length must be exactly 1 ...@@ -368,7 +371,9 @@ ERROR: name list length must be exactly 1
-- test successful cases -- test successful cases
WITH objects (type, name, args) AS (VALUES WITH objects (type, name, args) AS (VALUES
('table', '{addr_nsp, gentable}'::text[], '{}'::text[]), ('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
('index', '{addr_nsp, gentable_pkey}', '{}'), ('index', '{addr_nsp, gentable_pkey}', '{}'),
('index', '{addr_nsp, parttable_pkey}', '{}'),
('sequence', '{addr_nsp, gentable_a_seq}', '{}'), ('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
-- toast table -- toast table
('view', '{addr_nsp, genview}', '{}'), ('view', '{addr_nsp, genview}', '{}'),
...@@ -444,6 +449,8 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, ...@@ -444,6 +449,8 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
table | addr_nsp | gentable | addr_nsp.gentable | t table | addr_nsp | gentable | addr_nsp.gentable | t
table column | addr_nsp | gentable | addr_nsp.gentable.b | t table column | addr_nsp | gentable | addr_nsp.gentable.b | t
index | addr_nsp | gentable_pkey | addr_nsp.gentable_pkey | t index | addr_nsp | gentable_pkey | addr_nsp.gentable_pkey | t
table | addr_nsp | parttable | addr_nsp.parttable | t
index | addr_nsp | parttable_pkey | addr_nsp.parttable_pkey | t
view | addr_nsp | genview | addr_nsp.genview | t view | addr_nsp | genview | addr_nsp.genview | t
materialized view | addr_nsp | genmatview | addr_nsp.genmatview | t materialized view | addr_nsp | genmatview | addr_nsp.genmatview | t
foreign table | addr_nsp | genftable | addr_nsp.genftable | t foreign table | addr_nsp | genftable | addr_nsp.genftable | t
...@@ -478,7 +485,7 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, ...@@ -478,7 +485,7 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
subscription | | addr_sub | addr_sub | t subscription | | addr_sub | addr_sub | t
publication | | addr_pub | addr_pub | t publication | | addr_pub | addr_pub | t
publication relation | | | addr_nsp.gentable in publication addr_pub | t publication relation | | | addr_nsp.gentable in publication addr_pub | t
(47 rows) (49 rows)
--- ---
--- Cleanup resources --- Cleanup resources
...@@ -489,6 +496,6 @@ NOTICE: drop cascades to 4 other objects ...@@ -489,6 +496,6 @@ NOTICE: drop cascades to 4 other objects
DROP PUBLICATION addr_pub; DROP PUBLICATION addr_pub;
DROP SUBSCRIPTION addr_sub; DROP SUBSCRIPTION addr_sub;
DROP SCHEMA addr_nsp CASCADE; DROP SCHEMA addr_nsp CASCADE;
NOTICE: drop cascades to 13 other objects NOTICE: drop cascades to 14 other objects
DROP OWNED BY regress_addr_user; DROP OWNED BY regress_addr_user;
DROP USER regress_addr_user; DROP USER regress_addr_user;
...@@ -191,6 +191,21 @@ SELECT * FROM attmp_new2; ...@@ -191,6 +191,21 @@ SELECT * FROM attmp_new2;
DROP TABLE attmp_new; DROP TABLE attmp_new;
DROP TABLE attmp_new2; DROP TABLE attmp_new2;
-- check rename of partitioned tables and indexes also
CREATE TABLE part_attmp (a int primary key) partition by range (a);
CREATE TABLE part_attmp1 PARTITION OF part_attmp FOR VALUES FROM (0) TO (100);
ALTER INDEX part_attmp_pkey RENAME TO part_attmp_index;
ALTER INDEX part_attmp1_pkey RENAME TO part_attmp1_index;
ALTER TABLE part_attmp RENAME TO part_at2tmp;
ALTER TABLE part_attmp1 RENAME TO part_at2tmp1;
SET ROLE regress_alter_table_user1;
ALTER INDEX part_attmp_index RENAME TO fail;
ALTER INDEX part_attmp1_index RENAME TO fail;
ALTER TABLE part_at2tmp RENAME TO fail;
ALTER TABLE part_at2tmp1 RENAME TO fail;
RESET ROLE;
DROP TABLE part_at2tmp;
-- --
-- check renaming to a table's array type's autogenerated name -- check renaming to a table's array type's autogenerated name
-- (the array type's name should get out of the way) -- (the array type's name should get out of the way)
......
...@@ -22,6 +22,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs ...@@ -22,6 +22,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs
CREATE TABLE addr_nsp.gentable ( CREATE TABLE addr_nsp.gentable (
a serial primary key CONSTRAINT a_chk CHECK (a > 0), a serial primary key CONSTRAINT a_chk CHECK (a > 0),
b text DEFAULT 'hello'); b text DEFAULT 'hello');
CREATE TABLE addr_nsp.parttable (
a int PRIMARY KEY
) PARTITION BY RANGE (a);
CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable; CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable;
CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable; CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
CREATE TYPE addr_nsp.gencomptype AS (a int); CREATE TYPE addr_nsp.gencomptype AS (a int);
...@@ -138,7 +141,9 @@ SELECT pg_get_object_address('subscription', '{one,two}', '{}'); ...@@ -138,7 +141,9 @@ SELECT pg_get_object_address('subscription', '{one,two}', '{}');
-- test successful cases -- test successful cases
WITH objects (type, name, args) AS (VALUES WITH objects (type, name, args) AS (VALUES
('table', '{addr_nsp, gentable}'::text[], '{}'::text[]), ('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
('index', '{addr_nsp, gentable_pkey}', '{}'), ('index', '{addr_nsp, gentable_pkey}', '{}'),
('index', '{addr_nsp, parttable_pkey}', '{}'),
('sequence', '{addr_nsp, gentable_a_seq}', '{}'), ('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
-- toast table -- toast table
('view', '{addr_nsp, genview}', '{}'), ('view', '{addr_nsp, genview}', '{}'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment