unexpected relkind: 73 ERROR with partition table index

Started by Rajkumar Raghuwanshiover 7 years ago4 messages
#1Rajkumar Raghuwanshi
rajkumar.raghuwanshi@enterprisedb.com

Hi,

I am getting "ERROR: unexpected relkind: 73" when trying to rename
partition table index with below test case.

create user u1 superuser;
create user u2 nosuperuser login;
\c postgres u1

create table public.part(c1 int, c2 int) partition by range(c1);
create table public.part_p1 partition of public.part for values from
(minvalue) to (0);
create table public.part_p2 partition of public.part for values from (0) to
(maxvalue);
create index part_idx on public.part(c1);

create table public.nopart (c1 int, c2 int);
create index nopart_idx on public.nopart(c1);

--switch to nonsuperuser
\c postgres u2

postgres=> --rename the index owned by another user --non partition table
postgres=> ALTER INDEX nopart_idx RENAME TO nopart_idx_renamed;
ERROR: must be owner of index nopart_idx
postgres=>
postgres=> --rename the index owned by another user --partition table
postgres=> ALTER INDEX part_idx RENAME TO part_idx_renamed;
ERROR: unexpected relkind: 73

Thanks & Regards,
Rajkumar Raghuwanshi
QMG, EnterpriseDB Corporation

#2David Rowley
david.rowley@2ndquadrant.com
In reply to: Rajkumar Raghuwanshi (#1)
1 attachment(s)
Re: unexpected relkind: 73 ERROR with partition table index

On 27 June 2018 at 00:18, Rajkumar Raghuwanshi
<rajkumar.raghuwanshi@enterprisedb.com> wrote:

postgres=> ALTER INDEX part_idx RENAME TO part_idx_renamed;
ERROR: unexpected relkind: 73

Seems to be caused by the auth failure code path in
RangeVarCallbackForAlterRelation().

Patch attached.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

teach_get_relkind_objtype_about_partitioned_indexes.patchapplication/octet-stream; name=teach_get_relkind_objtype_about_partitioned_indexes.patchDownload
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index ad682673e6..7db942dcba 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -5248,6 +5248,7 @@ get_relkind_objtype(char relkind)
 		case RELKIND_PARTITIONED_TABLE:
 			return OBJECT_TABLE;
 		case RELKIND_INDEX:
+		case RELKIND_PARTITIONED_INDEX:
 			return OBJECT_INDEX;
 		case RELKIND_SEQUENCE:
 			return OBJECT_SEQUENCE;
#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: David Rowley (#2)
1 attachment(s)
Re: unexpected relkind: 73 ERROR with partition table index

On 2018-Jun-27, David Rowley wrote:

On 27 June 2018 at 00:18, Rajkumar Raghuwanshi
<rajkumar.raghuwanshi@enterprisedb.com> wrote:

postgres=> ALTER INDEX part_idx RENAME TO part_idx_renamed;
ERROR: unexpected relkind: 73

Seems to be caused by the auth failure code path in
RangeVarCallbackForAlterRelation().

Ah, yeah, thanks. No surprise this was missed, since I didn't add
tests for ALTER INDEX RENAME and Peter concurrently refactored the
handling code. I propose we add a few more test lines, as attached.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-fix-get_relkind_objtype-introduced-by-8b9e9644dc6a9b.patchtext/plain; charset=us-asciiDownload
From 4369b4aaea349d427a4924df74e387eea33aad0b Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 26 Jun 2018 10:45:38 -0400
Subject: [PATCH] fix get_relkind_objtype (introduced by
 8b9e9644dc6a9bd4b7a97950e6212f63880cf18b)

---
 src/backend/catalog/objectaddress.c          |  1 +
 src/test/regress/expected/alter_table.out    | 18 ++++++++++++++++++
 src/test/regress/expected/object_address.out | 11 +++++++++--
 src/test/regress/sql/alter_table.sql         | 15 +++++++++++++++
 src/test/regress/sql/object_address.sql      |  5 +++++
 5 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index ad682673e6..7db942dcba 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -5248,6 +5248,7 @@ get_relkind_objtype(char relkind)
 		case RELKIND_PARTITIONED_TABLE:
 			return OBJECT_TABLE;
 		case RELKIND_INDEX:
+		case RELKIND_PARTITIONED_INDEX:
 			return OBJECT_INDEX;
 		case RELKIND_SEQUENCE:
 			return OBJECT_SEQUENCE;
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index b9fd6d1d1c..df604a326c 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -159,6 +159,24 @@ SELECT * FROM attmp_new2;
 
 DROP TABLE attmp_new;
 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
 -- (the array type's name should get out of the way)
diff --git a/src/test/regress/expected/object_address.out b/src/test/regress/expected/object_address.out
index d195a0d700..4085e451e4 100644
--- a/src/test/regress/expected/object_address.out
+++ b/src/test/regress/expected/object_address.out
@@ -19,6 +19,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs
 CREATE TABLE addr_nsp.gentable (
 	a serial primary key CONSTRAINT a_chk CHECK (a > 0),
 	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 MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
 CREATE TYPE addr_nsp.gencomptype AS (a int);
@@ -368,7 +371,9 @@ ERROR:  name list length must be exactly 1
 -- test successful cases
 WITH objects (type, name, args) AS (VALUES
 				('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
+				('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
 				('index', '{addr_nsp, gentable_pkey}', '{}'),
+				('index', '{addr_nsp, parttable_pkey}', '{}'),
 				('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
 				-- toast table
 				('view', '{addr_nsp, genview}', '{}'),
@@ -444,6 +449,8 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
  table                     | addr_nsp   | gentable          | addr_nsp.gentable                                                    | t
  table column              | addr_nsp   | gentable          | addr_nsp.gentable.b                                                  | 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
  materialized view         | addr_nsp   | genmatview        | addr_nsp.genmatview                                                  | t
  foreign table             | addr_nsp   | genftable         | addr_nsp.genftable                                                   | t
@@ -478,7 +485,7 @@ SELECT (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*,
  subscription              |            | addr_sub          | addr_sub                                                             | t
  publication               |            | addr_pub          | addr_pub                                                             | t
  publication relation      |            |                   | addr_nsp.gentable in publication addr_pub                            | t
-(47 rows)
+(49 rows)
 
 ---
 --- Cleanup resources
@@ -489,6 +496,6 @@ NOTICE:  drop cascades to 4 other objects
 DROP PUBLICATION addr_pub;
 DROP SUBSCRIPTION addr_sub;
 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 USER regress_addr_user;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 3a5b80ea81..22cf4ef0a7 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -191,6 +191,21 @@ SELECT * FROM attmp_new2;
 DROP TABLE attmp_new;
 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
 -- (the array type's name should get out of the way)
diff --git a/src/test/regress/sql/object_address.sql b/src/test/regress/sql/object_address.sql
index 55faa71edf..d7df322873 100644
--- a/src/test/regress/sql/object_address.sql
+++ b/src/test/regress/sql/object_address.sql
@@ -22,6 +22,9 @@ CREATE TEXT SEARCH PARSER addr_ts_prs
 CREATE TABLE addr_nsp.gentable (
 	a serial primary key CONSTRAINT a_chk CHECK (a > 0),
 	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 MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;
 CREATE TYPE addr_nsp.gencomptype AS (a int);
@@ -138,7 +141,9 @@ SELECT pg_get_object_address('subscription', '{one,two}', '{}');
 -- test successful cases
 WITH objects (type, name, args) AS (VALUES
 				('table', '{addr_nsp, gentable}'::text[], '{}'::text[]),
+				('table', '{addr_nsp, parttable}'::text[], '{}'::text[]),
 				('index', '{addr_nsp, gentable_pkey}', '{}'),
+				('index', '{addr_nsp, parttable_pkey}', '{}'),
 				('sequence', '{addr_nsp, gentable_a_seq}', '{}'),
 				-- toast table
 				('view', '{addr_nsp, genview}', '{}'),
-- 
2.11.0

#4Rajkumar Raghuwanshi
rajkumar.raghuwanshi@enterprisedb.com
In reply to: Alvaro Herrera (#3)
Re: unexpected relkind: 73 ERROR with partition table index

Thanks for fix and commit. It is working fine now.

Thanks & Regards,
Rajkumar Raghuwanshi
QMG, EnterpriseDB Corporation

On Tue, Jun 26, 2018 at 8:39 PM, Alvaro Herrera <alvherre@2ndquadrant.com>
wrote:

Show quoted text

On 2018-Jun-27, David Rowley wrote:

On 27 June 2018 at 00:18, Rajkumar Raghuwanshi
<rajkumar.raghuwanshi@enterprisedb.com> wrote:

postgres=> ALTER INDEX part_idx RENAME TO part_idx_renamed;
ERROR: unexpected relkind: 73

Seems to be caused by the auth failure code path in
RangeVarCallbackForAlterRelation().

Ah, yeah, thanks. No surprise this was missed, since I didn't add
tests for ALTER INDEX RENAME and Peter concurrently refactored the
handling code. I propose we add a few more test lines, as attached.

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services