pgsql: Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRL - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRL
Date
Msg-id E1aMexa-0003X8-5J@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRLEN.

Commit e529cd4ffa605c6f introduced an Assert requiring NAMEDATALEN to be
less than MAX_LEVENSHTEIN_STRLEN, which has been 255 for a long time.
Since up to that instant we had always allowed NAMEDATALEN to be
substantially more than that, this was ill-advised.

It's debatable whether we need MAX_LEVENSHTEIN_STRLEN at all (versus
putting a CHECK_FOR_INTERRUPTS into the loop), or whether it has to be
so tight; but this patch takes the narrower approach of just not applying
the MAX_LEVENSHTEIN_STRLEN limit to calls from the parser.

Trusting the parser for this seems reasonable, first because the strings
are limited to NAMEDATALEN which is unlikely to be hugely more than 256,
and second because the maximum distance is tightly constrained by
MAX_FUZZY_DISTANCE (though we'd forgotten to make use of that limit in one
place).  That means the cost is not really O(mn) but more like O(max(m,n)).

Relaxing the limit for user-supplied calls is left for future research;
given the lack of complaints to date, it doesn't seem very high priority.

In passing, fix confusion between lengths-in-bytes and lengths-in-chars
in comments and error messages.

Per gripe from Kevin Day; solution suggested by Robert Haas.  Back-patch
to 9.5 where the unwanted restriction was introduced.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/a396144ac03b0cf337f80201df7e4663cc5a8131

Modified Files
--------------
contrib/fuzzystrmatch/fuzzystrmatch.c |   29 +++++++++---------
src/backend/parser/parse_relation.c   |   13 +++++----
src/backend/utils/adt/levenshtein.c   |   52 ++++++++++++++++++---------------
src/include/utils/builtins.h          |   11 ++++---
4 files changed, 60 insertions(+), 45 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRL
Next
From: Tom Lane
Date:
Subject: pgsql: Improve levenshtein() docs.