From 94bbc475fc5281cc048c08620fc8133bc17e5d28 Mon Sep 17 00:00:00 2001 From: reshke Date: Mon, 21 Sep 2026 10:44:47 +0300 Subject: [PATCH v1] Fix different IP addr families in SP-Gist opclass --- src/backend/utils/adt/network_spgist.c | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/backend/utils/adt/network_spgist.c b/src/backend/utils/adt/network_spgist.c index 52e3c666d4f..1edf90dc2f2 100644 --- a/src/backend/utils/adt/network_spgist.c +++ b/src/backend/utils/adt/network_spgist.c @@ -81,8 +81,19 @@ inet_spg_choose(PG_FUNCTION_ARGS) */ if (!in->hasPrefix) { - /* allTheSame isn't possible for such a tuple */ - Assert(!in->allTheSame); + /* + * We are forced allTheSame mode here if picksplit put all entries + * in one node + */ + if (in->allTheSame) + { + out->resultType = spgMatchNode; + out->result.matchNode.nodeN = 0 /* Doesn't matter, will bee overwritten */; + out->result.matchNode.restDatum = InetPGetDatum(val); + + PG_RETURN_VOID(); + } + Assert(in->nNodes == 2); out->resultType = spgMatchNode; @@ -191,9 +202,8 @@ inet_spg_picksplit(PG_FUNCTION_ARGS) if (ip_bits(tmp) < commonbits) commonbits = ip_bits(tmp); - commonbits = bitncommon(ip_addr(prefix), ip_addr(tmp), commonbits); - if (commonbits == 0) - break; + if (commonbits != 0) + commonbits = bitncommon(ip_addr(prefix), ip_addr(tmp), commonbits); } /* Don't need labels; allocate output arrays */ @@ -245,9 +255,12 @@ inet_spg_inner_consistent(PG_FUNCTION_ARGS) int i; int which; - if (!in->hasPrefix) + if (!in->hasPrefix && in->allTheSame) + { + /* Recurse in all subtrees. */ + which = ~0; + } else if (!in->hasPrefix) { - Assert(!in->allTheSame); Assert(in->nNodes == 2); /* Identify which child nodes need to be visited */ -- 2.43.0