ltree: fix case-insensitive matching.

Jeff Davis <jdavis@postgresql.org>

Commit: 806555e3000d0b0e0c536c1dc65548128d457d86
Author: Jeff Davis <jdavis@postgresql.org>
Date: 2025-12-16T20:57:12Z
Releases: 18.2
ltree: fix case-insensitive matching.

Previously, ltree_prefix_eq_ci() used lowercasing with the default
collation; while ltree_crc32_sz() used tolower() directly. These were
equivalent only if the default collation provider was libc and the
encoding was single-byte.

Change both to use casefolding with the default collation.

Backpatch through 18, where the casefolding APIs were introduced. The
bug exists in earlier versions, but would require some adaptation.

A REINDEX is required for ltree indexes where the database default
collation is not libc.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Backpatch-through: 18
Discussion: https://postgr.es/m/450ceb6260cad30d7afdf155d991a9caafee7c0d.camel@j-davis.com
Discussion: https://postgr.es/m/01fc00fd66f641b9693d4f9f1af0ccf44cbdfbdf.camel@j-davis.com

Files

PathChange+/−
contrib/ltree/crc32.c modified +39 −8
contrib/ltree/lquery_op.c modified +36 −3
src/include/utils/pg_locale.h modified +14 −0

Discussion