Hi all, See attached a regression test (0001) and fix (0002) for a contrib/btree_gist index corruption.
btree_gist indexes on bit and VarBit types use an internal node structure that is different from leaf note structure. So gbt_var_union() has to always look for incoming leaf node and convert it to internal. Current implementation copied its first entry into the union as is, without checking if it is leaf. When the first entry is a leaf key, the corresponding internal bound after a union is essentially corrupted. Index scans can then return wrong results. The fix makes sure that every entry (including the first) passes through gbt_var_bin_union(), which already properly handles leaf2node conversion. Existing bit and varbit GiST indexes can return incomplete results and should be reindexed. I have found a few other issues in contrib/btree_gist relating to alignment, wrong result near supported type range boundaries, etc. I will clean those up and share all itemized test and fix patches in a single separate thread unless you suggest something else here. Narek --
0002-Fix-btree_gist-unions-of-bit-and-varbit-leaf-keys.patch
Description: Binary data
0001-Add-a-test-for-btree_gist-bit-indexes-built-from-lea.patch
Description: Binary data
