pgsql: Fix an issue with index scan using pg_trgm due to char signednes - Mailing list pgsql-committers

From Masahiko Sawada
Subject pgsql: Fix an issue with index scan using pg_trgm due to char signednes
Date
Msg-id E1tlXkn-000VZr-2D@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix an issue with index scan using pg_trgm due to char signedness on different architectures.

GIN and GiST indexes utilizing pg_trgm's opclasses store sorted
trigrams within index tuples. When comparing and sorting each trigram,
pg_trgm treats each character as a 'char[3]' type in C. However, the
char type in C can be interpreted as either signed char or unsigned
char, depending on the platform, if the signedness is not explicitly
specified. Consequently, during replication between different CPU
architectures, there was an issue where index scans on standby servers
could not locate matching index tuples due to the differing treatment
of character signedness.

This change introduces comparison functions for trgm that explicitly
handle signed char and unsigned char. The appropriate comparison
function will be dynamically selected based on the character
signedness stored in the control file. Therefore, upgraded clusters
can utilize the indexes without rebuilding, provided the cluster
upgrade occurs on platforms with the same character signedness as the
original cluster initialization.

The default char signedness information was introduced in 44fe30fdab6,
so no backpatch.

Reviewed-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/CB11ADBC-0C3F-4FE0-A678-666EE80CBB07%40amazon.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dfd8e6c73eeaa8a4d53851ba01e8d7b1c0bef0e3

Modified Files
--------------
contrib/pg_trgm/trgm.h    |  5 +----
contrib/pg_trgm/trgm_op.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 4 deletions(-)


pgsql-committers by date:

Previous
From: Masahiko Sawada
Date:
Subject: pgsql: pg_upgrade: Add --set-char-signedness to set the default char si
Next
From: Tom Lane
Date:
Subject: pgsql: Fix pg_dumpall to cope with dangling OIDs in pg_auth_members.