]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix like_fixed_prefix_ci() selectivity.
authorJeff Davis <jdavis@postgresql.org>
Wed, 15 Jul 2026 19:34:20 +0000 (12:34 -0700)
committerJeff Davis <jdavis@postgresql.org>
Wed, 15 Jul 2026 19:35:32 +0000 (12:35 -0700)
A wrong calculation introduced by 9c8de15969 could cause trailing
characters from the prefix to be passed to like_selectivity() rather
than just the "rest".

Discussion: https://postgr.es/m/c7334a7a44243d2e4ec5e83747589908b3787491.camel@j-davis.com
Backpatch-through: 19

src/backend/utils/adt/like_support.c

index 4c8db9147ee551744c05daeb790658353e0cd604..e354360a8e68b08d365bac7d99a11bc132456b30 100644 (file)
@@ -1150,12 +1150,12 @@ like_fixed_prefix_ci(Const *patt_const, Oid collation, Const **prefix_const,
 
        if (rest_selec != NULL)
        {
-               int                     wrestlen = wpattlen - wmatch_pos;
+               int                     wrestlen = wpattlen - wpos;
                char       *rest;
                int                     rest_mblen;
 
                rest = palloc(pg_database_encoding_max_length() * wrestlen + 1);
-               rest_mblen = pg_wchar2mb_with_len(&wpatt[wmatch_pos], rest, wrestlen);
+               rest_mblen = pg_wchar2mb_with_len(&wpatt[wpos], rest, wrestlen);
 
                *rest_selec = like_selectivity(rest, rest_mblen, true);
                pfree(rest);