Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 040da42

Browse files
Enable failure to rename a partitioned index
Concurrently with partitioned index development (commit 8b08f7d), the code to handle failure to rename indexes was refactored (commit 8b9e964). 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: David Rowley <dgrowley@gmail.com> Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Reported-by: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com> Discussion: https://postgr.es/m/CAKcux6mfYMS3OX0ywjOiWiGSEKhJf-1zdeTceHFbd0mScUzU5A@mail.gmail.com
1 parent bbbbc2f commit 040da42

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5248,6 +5248,7 @@ get_relkind_objtype(char relkind)
52485248
case RELKIND_PARTITIONED_TABLE:
52495249
return OBJECT_TABLE;
52505250
case RELKIND_INDEX:
5251+
case RELKIND_PARTITIONED_INDEX:
52515252
return OBJECT_INDEX;
52525253
case RELKIND_SEQUENCE:
52535254
return OBJECT_SEQUENCE;

src/test/regress/expected/alter_table.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ SELECT * FROM attmp_new2;
159159

160160
DROP TABLE attmp_new;
161161
DROP TABLE attmp_new2;
162+
-- check rename of partitioned tables and indexes also
163+
CREATE TABLE part_attmp (a int primary key) partition by range (a);
164+
CREATE TABLE part_attmp1 PARTITION OF part_attmp FOR VALUES FROM (0) TO (100);
165+
ALTER INDEX part_attmp_pkey RENAME TO part_attmp_index;
166+
ALTER INDEX part_attmp1_pkey RENAME TO part_attmp1_index;
167+
ALTER TABLE part_attmp RENAME TO part_at2tmp;
168+
ALTER TABLE part_attmp1 RENAME TO part_at2tmp1;
169+
SET ROLE regress_alter_table_user1;
170+
ALTER INDEX part_attmp_index RENAME TO fail;
171+
ERROR: must be owner of index part_attmp_index
172+
ALTER INDEX part_attmp1_index RENAME TO fail;
173+
ERROR: must be owner of index part_attmp1_index
174+
ALTER TABLE part_at2tmp RENAME TO fail;
175+
ERROR: must be owner of table part_at2tmp
176+
ALTER TABLE part_at2tmp1 RENAME TO fail;
177+
ERROR: must be owner of table part_at2tmp1
178+
RESET ROLE;
179+
DROP TABLE part_at2tmp;
162180
--
163181
-- check renaming to a table's array type's autogenerated name
164182
-- (the array type's name should get out of the way)

src/test/regress/expected/object_address.out

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs
1919
CREATE TABLE addr_nsp.gentable (
2020
a serial primary key CONSTRAINT a_chk CHECK (a > 0),
2121
b text DEFAULT 'hello');
22+
CREATE TABLE addr_nsp.parttable (
23+
a int PRIMARY KEY
24+
) PARTITION BY RANGE (a);
2225
CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable;
2326
CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
2427
CREATE TYPE addr_nsp.gencomptype AS (a int);
@@ -368,7 +371,9 @@ ERROR: name list length must be exactly 1
368371
-- test successful cases
369372
WITH objects (type, name, args) AS (VALUES
370373
('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
374+
('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
371375
('index', '{addr_nsp, gentable_pkey}', '{}'),
376+
('index', '{addr_nsp, parttable_pkey}', '{}'),
372377
('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
373378
-- toast table
374379
('view', '{addr_nsp, genview}', '{}'),
@@ -444,6 +449,8 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
444449
table | addr_nsp | gentable | addr_nsp.gentable | t
445450
table column | addr_nsp | gentable | addr_nsp.gentable.b | t
446451
index | addr_nsp | gentable_pkey | addr_nsp.gentable_pkey | t
452+
table | addr_nsp | parttable | addr_nsp.parttable | t
453+
index | addr_nsp | parttable_pkey | addr_nsp.parttable_pkey | t
447454
view | addr_nsp | genview | addr_nsp.genview | t
448455
materialized view | addr_nsp | genmatview | addr_nsp.genmatview | t
449456
foreign table | addr_nsp | genftable | addr_nsp.genftable | t
@@ -478,7 +485,7 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
478485
subscription | | addr_sub | addr_sub | t
479486
publication | | addr_pub | addr_pub | t
480487
publication relation | | | addr_nsp.gentable in publication addr_pub | t
481-
(47 rows)
488+
(49 rows)
482489

483490
---
484491
--- Cleanup resources
@@ -489,6 +496,6 @@ NOTICE: drop cascades to 4 other objects
489496
DROP PUBLICATION addr_pub;
490497
DROP SUBSCRIPTION addr_sub;
491498
DROP SCHEMA addr_nsp CASCADE;
492-
NOTICE: drop cascades to 13 other objects
499+
NOTICE: drop cascades to 14 other objects
493500
DROP OWNED BY regress_addr_user;
494501
DROP USER regress_addr_user;

src/test/regress/sql/alter_table.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ SELECT * FROM attmp_new2;
191191
DROP TABLE attmp_new;
192192
DROP TABLE attmp_new2;
193193

194+
-- check rename of partitioned tables and indexes also
195+
CREATE TABLE part_attmp (a int primary key) partition by range (a);
196+
CREATE TABLE part_attmp1 PARTITION OF part_attmp FOR VALUES FROM (0) TO (100);
197+
ALTER INDEX part_attmp_pkey RENAME TO part_attmp_index;
198+
ALTER INDEX part_attmp1_pkey RENAME TO part_attmp1_index;
199+
ALTER TABLE part_attmp RENAME TO part_at2tmp;
200+
ALTER TABLE part_attmp1 RENAME TO part_at2tmp1;
201+
SET ROLE regress_alter_table_user1;
202+
ALTER INDEX part_attmp_index RENAME TO fail;
203+
ALTER INDEX part_attmp1_index RENAME TO fail;
204+
ALTER TABLE part_at2tmp RENAME TO fail;
205+
ALTER TABLE part_at2tmp1 RENAME TO fail;
206+
RESET ROLE;
207+
DROP TABLE part_at2tmp;
208+
194209
--
195210
-- check renaming to a table's array type's autogenerated name
196211
-- (the array type's name should get out of the way)

src/test/regress/sql/object_address.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs
2222
CREATE TABLE addr_nsp.gentable (
2323
a serial primary key CONSTRAINT a_chk CHECK (a > 0),
2424
b text DEFAULT 'hello');
25+
CREATE TABLE addr_nsp.parttable (
26+
a int PRIMARY KEY
27+
) PARTITION BY RANGE (a);
2528
CREATE VIEW addr_nsp.genview AS SELECT * from addr_nsp.gentable;
2629
CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
2730
CREATE TYPE addr_nsp.gencomptype AS (a int);
@@ -138,7 +141,9 @@ SELECT pg_get_object_address('subscription', '{one,two}', '{}');
138141
-- test successful cases
139142
WITH objects (type, name, args) AS (VALUES
140143
('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
144+
('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
141145
('index', '{addr_nsp, gentable_pkey}', '{}'),
146+
('index', '{addr_nsp, parttable_pkey}', '{}'),
142147
('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
143148
-- toast table
144149
('view', '{addr_nsp, genview}', '{}'),

0 commit comments

Comments
 (0)