Skip to content

Commit be1cc9a

Browse files
committed
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> Co-authored-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent 5ac462e commit be1cc9a

File tree

1 file changed

+5
-32
lines changed

1 file changed

+5
-32
lines changed

src/backend/utils/adt/network.c

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,39 +1093,13 @@ match_network_subset(Node *leftop,
10931093
return NIL;
10941094
rightopval = ((Const *) rightop)->constvalue;
10951095

1096-
/*
1097-
* Must check that index's opfamily supports the operators we will want to
1098-
* apply.
1099-
*
1100-
* We insist on the opfamily being the specific one we expect, else we'd
1101-
* do the wrong thing if someone were to make a reverse-sort opfamily with
1102-
* the same operators.
1103-
*/
1104-
if (opfamily != NETWORK_BTREE_FAM_OID)
1105-
return NIL;
1106-
11071096
/*
11081097
* create clause "key >= network_scan_first( rightopval )", or ">" if the
11091098
* operator disallows equality.
1110-
*
1111-
* Note: seeing that this function supports only fixed values for opfamily
1112-
* and datatype, we could just hard-wire the operator OIDs instead of
1113-
* looking them up. But for now it seems better to be general.
11141099
*/
1115-
if (is_eq)
1116-
{
1117-
opr1oid = get_opfamily_member(opfamily, datatype, datatype,
1118-
BTGreaterEqualStrategyNumber);
1119-
if (opr1oid == InvalidOid)
1120-
elog(ERROR, "no >= operator for opfamily %u", opfamily);
1121-
}
1122-
else
1123-
{
1124-
opr1oid = get_opfamily_member(opfamily, datatype, datatype,
1125-
BTGreaterStrategyNumber);
1126-
if (opr1oid == InvalidOid)
1127-
elog(ERROR, "no > operator for opfamily %u", opfamily);
1128-
}
1100+
opr1oid = get_opfamily_member_for_cmptype(opfamily, datatype, datatype, is_eq ? COMPARE_GE : COMPARE_GT);
1101+
if (opr1oid == InvalidOid)
1102+
return NIL;
11291103

11301104
opr1right = network_scan_first(rightopval);
11311105

@@ -1140,10 +1114,9 @@ match_network_subset(Node *leftop,
11401114

11411115
/* create clause "key <= network_scan_last( rightopval )" */
11421116

1143-
opr2oid = get_opfamily_member(opfamily, datatype, datatype,
1144-
BTLessEqualStrategyNumber);
1117+
opr2oid = get_opfamily_member_for_cmptype(opfamily, datatype, datatype, COMPARE_LE);
11451118
if (opr2oid == InvalidOid)
1146-
elog(ERROR, "no <= operator for opfamily %u", opfamily);
1119+
return NIL;
11471120

11481121
opr2right = network_scan_last(rightopval);
11491122

0 commit comments

Comments
 (0)