Re: strpos behavior change around empty substring in PG12
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>, Shay Rojansky <roji@roji.org>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2019-10-28T15:57:21Z
Lists: pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, Oct 28, 2019 at 11:02 AM Shay Rojansky <roji@roji.org> wrote:
>> Before PG12, select strpos('test', '') returns 1 (empty substring found at first position of the string), whereas starting with PG12 it returns 0 (empty substring not found).
> It looks to me like this got broken here:
> commit 9556aa01c69a26ca726d8dda8e395acc7c1e30fc
> Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
> Date: Fri Jan 25 16:25:05 2019 +0200
> Use single-byte Boyer-Moore-Horspool search even with multibyte encodings.
> Not sure what happened exactly.
I think the problem is lack of clarity about the edge cases.
The patch added this short-circuit right at the top of text_position():
+ if (VARSIZE_ANY_EXHDR(t1) < 1 || VARSIZE_ANY_EXHDR(t2) < 1)
+ return 0;
and as this example shows, that's the Wrong Thing. Fortunately,
it also seems easily fixed.
regards, tom lane
Commits
-
Handle empty-string edge cases correctly in strpos().
- bd1ef5799b04 13.0 landed
- 43e43771bc4b 12.1 landed
-
Use single-byte Boyer-Moore-Horspool search even with multibyte encodings.
- 9556aa01c69a 12.0 cited