small erreport bug over partitioned table pgrowlocks module

Started by jian heabout 2 years ago3 messages
#1jian he
jian.universality@gmail.com

hi.
erreport bug over partitioned table in pgrowlocks.

BEGIN;
CREATE TABLE fk_parted_pk (a int PRIMARY KEY) PARTITION BY LIST (a);
SELECT * FROM pgrowlocks('fk_parted_pk');
ERROR: only heap AM is supported

error should be the following part:
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is a partitioned table",
RelationGetRelationName(rel)),
errdetail("Partitioned tables do not contain rows.")));

#2David Rowley
dgrowleyml@gmail.com
In reply to: jian he (#1)
1 attachment(s)
Re: small erreport bug over partitioned table pgrowlocks module

On Tue, 31 Oct 2023 at 13:00, jian he <jian.universality@gmail.com> wrote:

BEGIN;
CREATE TABLE fk_parted_pk (a int PRIMARY KEY) PARTITION BY LIST (a);
SELECT * FROM pgrowlocks('fk_parted_pk');
ERROR: only heap AM is supported

error should be the following part:
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is a partitioned table",
RelationGetRelationName(rel)),
errdetail("Partitioned tables do not contain rows.")));

Yeah. Seems that 4b8266415 didn't look closely enough at the other
error messages and mistakenly put the relam check first instead of
last.

Here's a patch that puts the relam check last.

David

Attachments:

fix_pgrowlocks.patchtext/plain; charset=US-ASCII; name=fix_pgrowlocks.patchDownload
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index a04e187ec4..adbc8279c3 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -81,10 +81,6 @@ pgrowlocks(PG_FUNCTION_ARGS)
 	relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
 	rel = relation_openrv(relrv, AccessShareLock);
 
-	if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
-		ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-						errmsg("only heap AM is supported")));
-
 	if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
@@ -96,6 +92,10 @@ pgrowlocks(PG_FUNCTION_ARGS)
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
 				 errmsg("\"%s\" is not a table",
 						RelationGetRelationName(rel))));
+	else if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
+		ereport(ERROR,
+				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+				 errmsg("only heap AM is supported")));
 
 	/*
 	 * check permissions: must have SELECT on table or be in
#3David Rowley
dgrowleyml@gmail.com
In reply to: David Rowley (#2)
Re: small erreport bug over partitioned table pgrowlocks module

On Tue, 31 Oct 2023 at 13:18, David Rowley <dgrowleyml@gmail.com> wrote:

Here's a patch that puts the relam check last.

I've pushed that patch.

David