From: Tom Lane Date: Fri, 3 Jul 2026 17:11:14 +0000 (-0400) Subject: Use the proper comparator in gbt_bit_ssup_cmp. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a9fa6c69e3f5405866a0ebed27597e80760abc77;p=thirdparty%2Fpostgresql.git Use the proper comparator in gbt_bit_ssup_cmp. If we're dealing with leaf entries, the function to call is bitcmp not byteacmp. Using byteacmp didn't lead to any obvious failure, but it did result in sorting the entries in a way not matching the datatype's actual sort order. Hence the constructed index would be less efficient than one would expect, and in particular worse than what you got before this code was added in v18 (by commit e4309f73f). We might want to recommend that users reindex btree_gist indexes on bit/varbit columns. Author: Tom Lane Reviewed-by: Ayush Tiwari Discussion: https://postgr.es/m/AH*AvQCYKhQGVvPWi1GiU4oY.8.1781609375063.Hmail.3020001251@tju.edu.cn Backpatch-through: 18 --- diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c index 2b9c18a586f..ad1d2013116 100644 --- a/contrib/btree_gist/btree_bit.c +++ b/contrib/btree_gist/btree_bit.c @@ -217,7 +217,7 @@ gbt_bit_ssup_cmp(Datum x, Datum y, SortSupport ssup) Datum result; /* for leaf items we expect lower == upper, so only compare lower */ - result = DirectFunctionCall2(byteacmp, + result = DirectFunctionCall2(bitcmp, PointerGetDatum(arg1.lower), PointerGetDatum(arg2.lower));