v22-0005-Generalize-index-support-in-network-support-func.patch

text/plain

Filename: v22-0005-Generalize-index-support-in-network-support-func.patch
Type: text/plain
Part: 4
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 v22-0005
Subject: Generalize index support in network support function
File+
src/backend/utils/adt/network.c 5 32
From f4980bfb80e2ea1cede8db2f7f0355ab72caecd5 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Wed, 19 Mar 2025 12:03:23 +0100
Subject: [PATCH v22 05/10] Generalize index support in network support
 function

The network (inet) support functions currently only supported a
hardcoded btree operator family.  With the generalized compare type
facility, we can generalize this to support any operator family from
any index type that supports the required operators.

Author: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
---
 src/backend/utils/adt/network.c | 37 +++++----------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 450dacd031c..227980c14d3 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1093,39 +1093,13 @@ match_network_subset(Node *leftop,
 		return NIL;
 	rightopval = ((Const *) rightop)->constvalue;
 
-	/*
-	 * Must check that index's opfamily supports the operators we will want to
-	 * apply.
-	 *
-	 * We insist on the opfamily being the specific one we expect, else we'd
-	 * do the wrong thing if someone were to make a reverse-sort opfamily with
-	 * the same operators.
-	 */
-	if (opfamily != NETWORK_BTREE_FAM_OID)
-		return NIL;
-
 	/*
 	 * create clause "key >= network_scan_first( rightopval )", or ">" if the
 	 * operator disallows equality.
-	 *
-	 * Note: seeing that this function supports only fixed values for opfamily
-	 * and datatype, we could just hard-wire the operator OIDs instead of
-	 * looking them up.  But for now it seems better to be general.
 	 */
-	if (is_eq)
-	{
-		opr1oid = get_opfamily_member(opfamily, datatype, datatype,
-									  BTGreaterEqualStrategyNumber);
-		if (opr1oid == InvalidOid)
-			elog(ERROR, "no >= operator for opfamily %u", opfamily);
-	}
-	else
-	{
-		opr1oid = get_opfamily_member(opfamily, datatype, datatype,
-									  BTGreaterStrategyNumber);
-		if (opr1oid == InvalidOid)
-			elog(ERROR, "no > operator for opfamily %u", opfamily);
-	}
+	opr1oid = get_opfamily_member_for_cmptype(opfamily, datatype, datatype, is_eq ? COMPARE_GE : COMPARE_GT);
+	if (opr1oid == InvalidOid)
+		return NIL;
 
 	opr1right = network_scan_first(rightopval);
 
@@ -1140,10 +1114,9 @@ match_network_subset(Node *leftop,
 
 	/* create clause "key <= network_scan_last( rightopval )" */
 
-	opr2oid = get_opfamily_member(opfamily, datatype, datatype,
-								  BTLessEqualStrategyNumber);
+	opr2oid = get_opfamily_member_for_cmptype(opfamily, datatype, datatype, COMPARE_LE);
 	if (opr2oid == InvalidOid)
-		elog(ERROR, "no <= operator for opfamily %u", opfamily);
+		return NIL;
 
 	opr2right = network_scan_last(rightopval);
 
-- 
2.49.0