From 479732b1d5dade97c3eeb6c6bd30917d37ea1b56 Mon Sep 17 00:00:00 2001 From: Alexander Nestorov Date: Sun, 8 Nov 2026 00:20:13 +0100 Subject: [PATCH v8 1/4] btree_gist: Pass the index key first in gbt_num_distance() Every other caller of the gbtree_ninfo comparison callbacks passes the index key as the left argument and the query value as the right one, matching the usual "index_key OP query_value" form of an index condition. gbt_num_distance() was the lone exception, calling f_le(query, key->lower) and so on. Rewrite it in the common order. All f_dist callbacks return an absolute difference, so swapping their arguments does not change the result. No behavior change; this is preparation for adding cross-type operators, whose callbacks must read each argument at its own width and so depend on a fixed argument order. --- contrib/btree_gist/btree_utils_num.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c index e1f6d0fb2e1..7429f1856c1 100644 --- a/contrib/btree_gist/btree_utils_num.c +++ b/contrib/btree_gist/btree_utils_num.c @@ -353,16 +353,16 @@ gbt_num_distance(const GBT_NUMKEY_R *key, { float8 retval; if (tinfo->f_dist == NULL) elog(ERROR, "KNN search is not supported for btree_gist type %d", (int) tinfo->t); - if (tinfo->f_le(query, key->lower, flinfo)) - retval = tinfo->f_dist(query, key->lower, flinfo); - else if (tinfo->f_ge(query, key->upper, flinfo)) - retval = tinfo->f_dist(query, key->upper, flinfo); + if (tinfo->f_ge(key->lower, query, flinfo)) + retval = tinfo->f_dist(key->lower, query, flinfo); + else if (tinfo->f_le(key->upper, query, flinfo)) + retval = tinfo->f_dist(key->upper, query, flinfo); else retval = 0.0; return retval; } base-commit: 0607aa61090ac1b574f8bafe854c684195b31e16 -- 2.54.0 (Apple Git-157)