Re: BUG #19951: levenshtein_less_equal returns 0 when exact distance is 1 with a negative cost

From: Nitin Motiani <nitinmotiani(at)google(dot)com>
To: imchifan(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19951: levenshtein_less_equal returns 0 when exact distance is 1 with a negative cost
Date: 2026-11-28 15:54:37
Message-ID: CAH5HC95WQUE7aAe-hVU99fyzvrizk3qdhwtVmJFRFfBQyOLWVA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

Thanks for the report.

On Wed, Nov 25, 2026 at 11:22 PM PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
>
>
> WITH r AS (
> SELECT levenshtein('a', 'b', -1, 2, 2) AS exact_distance,
> levenshtein_less_equal('a', 'b', -1, 2, 2, 0) AS bounded_distance
> )
>

I am not sure anyone is using negative costs here to hit this bug. So
it can probably be left as-is. I am still attaching a patch for a
couple of reasons.

1. levensthtein() does work currently with negative costs so it might
make sense to make levenshtein_less_equal() correct.
2. The change is very small where if any of the 3 costs are negative,
I just set max_d to -1 and let it take the unoptimized path. I
considered disallowing negative costs altogether but that won't be
backward compatible.

Thanks & Regards,
Nitin Motiani
Google

Attachment Content-Type Size
v1-0001-Fix-levenshtein_less_equal-with-negative-edit-cos.patch application/x-patch 3.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Ishjaap Singh 2026-11-28 15:27:19 Re: BUG #19825: JSON_VALUE(... RETURNING <domain over json/jsonb>) loses the re-quoting of scalar strings and silent