v19.2-0002-Add-get_opfamily_name-function.patch

text/plain

Filename: v19.2-0002-Add-get_opfamily_name-function.patch
Type: text/plain
Part: 1
Message: Re: Index AM API cleanup

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v19-0002
Subject: Add get_opfamily_name() function
File+
src/backend/utils/cache/lsyscache.c 27 0
src/include/utils/lsyscache.h 1 0
From 48a087657a1bdcecc99a86d54576da282f4d3b72 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 24 Jan 2025 22:58:13 +0100
Subject: [PATCH v19.2 2/6] Add get_opfamily_name() function

---
 src/backend/utils/cache/lsyscache.c | 27 +++++++++++++++++++++++++++
 src/include/utils/lsyscache.h       |  1 +
 2 files changed, 28 insertions(+)

diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 7a9af03c960..bcfa5cb4add 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -30,6 +30,7 @@
 #include "catalog/pg_language.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_opclass.h"
+#include "catalog/pg_opfamily.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_publication.h"
@@ -1273,6 +1274,32 @@ get_opclass_method(Oid opclass)
 	return result;
 }
 
+/*				---------- OPFAMILY CACHE ----------					 */
+
+char *
+get_opfamily_name(Oid opfid, bool missing_ok)
+{
+	HeapTuple	tup;
+	char	   *opfname;
+	Form_pg_opfamily opfform;
+
+	tup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfid));
+
+	if (!HeapTupleIsValid(tup))
+	{
+		if (!missing_ok)
+			elog(ERROR, "cache lookup failed for operator family %u", opfid);
+		return NULL;
+	}
+
+	opfform = (Form_pg_opfamily) GETSTRUCT(tup);
+	opfname = pstrdup(NameStr(opfform->opfname));
+
+	ReleaseSysCache(tup);
+
+	return opfname;
+}
+
 /*				---------- OPERATOR CACHE ----------					 */
 
 /*
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index b23deb9662f..6fab7aa6009 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -108,6 +108,7 @@ extern Oid	get_opclass_input_type(Oid opclass);
 extern bool get_opclass_opfamily_and_input_type(Oid opclass,
 												Oid *opfamily, Oid *opcintype);
 extern Oid	get_opclass_method(Oid opclass);
+extern char *get_opfamily_name(Oid opfid, bool missing_ok);
 extern RegProcedure get_opcode(Oid opno);
 extern char *get_opname(Oid opno);
 extern Oid	get_op_rettype(Oid opno);
-- 
2.48.1