v2-0001-Use-the-standard-symbol-for-the-builtin-function-.patch

application/octet-stream

Filename: v2-0001-Use-the-standard-symbol-for-the-builtin-function-.patch
Type: application/octet-stream
Part: 0
Message: Re: duplicate function oid symbols

Patch

Format: format-patch
Series: patch v2-0001
Subject: Use the standard symbol for the builtin function heap_tableam_handler()
File+
src/backend/catalog/genbki.pl 7 0
src/backend/utils/cache/relcache.c 2 2
src/include/catalog/pg_proc.dat 1 2
From 2cc5f93c7052591c2372e4ef05e9a66c9960187d Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@2ndquadrant.com>
Date: Wed, 28 Oct 2020 11:41:56 -0400
Subject: [PATCH v2] Use the standard symbol for the builtin function
 heap_tableam_handler()

It's long been convention that OIDs of builtin functions are referenced
via the automatically generated symbols in fmgroids.h.
heap_tableam_handler() was able to receive a custom symbol because
we had no enforcement otherwise. Change references to this function
to use F_HEAP_TABLEAM_HANDLER instead, and forbid future pg_proc
entries from specifying custom symbols.
---
 src/backend/catalog/genbki.pl      | 7 +++++++
 src/backend/utils/cache/relcache.c | 4 ++--
 src/include/catalog/pg_proc.dat    | 3 +--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index ef3105af44..4653a4d0cb 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -602,6 +602,13 @@ EOM
 		# Emit OID symbol
 		if (defined $bki_values{oid_symbol})
 		{
+			# OID symbols for builtin functions are handled automatically
+			# by utils/Gen_fmgrtab.pl
+			die sprintf
+			  "custom OID symbols for pg_proc entries are not allowed: '%s'",
+			  $bki_values{oid_symbol}
+			  if $catname eq 'pg_proc';
+
 			printf $def "#define %s %s\n",
 			  $bki_values{oid_symbol}, $bki_values{oid};
 		}
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 9061af81a3..9224e2ffed 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1761,7 +1761,7 @@ RelationInitTableAccessMethod(Relation relation)
 		 * seem prudent to show that in the catalog. So just overwrite it
 		 * here.
 		 */
-		relation->rd_amhandler = HEAP_TABLE_AM_HANDLER_OID;
+		relation->rd_amhandler = F_HEAP_TABLEAM_HANDLER;
 	}
 	else if (IsCatalogRelation(relation))
 	{
@@ -1769,7 +1769,7 @@ RelationInitTableAccessMethod(Relation relation)
 		 * Avoid doing a syscache lookup for catalog tables.
 		 */
 		Assert(relation->rd_rel->relam == HEAP_TABLE_AM_OID);
-		relation->rd_amhandler = HEAP_TABLE_AM_HANDLER_OID;
+		relation->rd_amhandler = F_HEAP_TABLEAM_HANDLER;
 	}
 	else
 	{
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index bbcac69d48..5045b493d3 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -901,8 +901,7 @@
   prosrc => 'ftoi4' },
 
 # Table access method handlers
-{ oid => '3', oid_symbol => 'HEAP_TABLE_AM_HANDLER_OID',
-  descr => 'row-oriented heap table access method handler',
+{ oid => '3', descr => 'row-oriented heap table access method handler',
   proname => 'heap_tableam_handler', provolatile => 'v',
   prorettype => 'table_am_handler', proargtypes => 'internal',
   prosrc => 'heap_tableam_handler' },
-- 
2.22.0