| From: | Joao Rito <joaovictor(dot)rito(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | Aleksander Alekseev <aleksander(at)tigerdata(dot)com> |
| Subject: | Re: [PATCH] contrib/fuzzystrmatch: improve test coverage |
| Date: | 2026-11-16 06:07:00 |
| Message-ID: | 20261116060700.758-1-joaovictor.rito@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Aleksander,
Thanks for the patch. I tested v1 on current master (81b2179b492).
I built it with cassert, --enable-debug and --enable-coverage
(autoconf, gcc 14.2, lcov 2.0, Debian container, without icu,
readline and zlib). git am applies it cleanly, with no whitespace
warnings. make -C contrib/fuzzystrmatch check passes before and after
the patch (2 of 2 tests: fuzzystrmatch and fuzzystrmatch_utf8).
I measured line coverage with gcov and lcov, before and after:
file lines before -> after functions after
fuzzystrmatch.c 49.5% -> 98.9% 21 of 21 (was 20)
dmetaphone.c 17.8% -> 94.9% 15 of 15 (was 11)
daitch_mokotoff.c 95.7% -> 98.8% 12 of 12 (same)
These match the numbers in your email. Per function, line coverage
from gcov -f:
_soundex 95.65% -> 100%
_metaphone 21.08% -> 98.19%
metaphone 71.43% -> 100%
DoubleMetaphone 10.77% -> 95.87%
dmetaphone, dmetaphone_alt: 87.50% before and after
difference, soundex: 100% before and after
levenshtein, levenshtein_with_costs, levenshtein_less_equal and
levenshtein_less_equal_with_costs: 100% before and after
The levenshtein functions were already fully covered, so the patch
does not change them.
Lines still not run after the patch, on master line numbers:
- fuzzystrmatch.c, 3 lines: the two elog(ERROR) calls at 372 and 377
and the palloc at 382, all in _metaphone. I did not check whether
SQL can reach them.
- dmetaphone.c, 33 lines. They include the two code = "" lines at
149 and 178, the C-cedilla case (471-475) and the N-tilde case
(1040-1044), and 12 lines of "current += 2".
- daitch_mokotoff.c, 2 lines: the default branch at 442-443.
I understand that you may not want to chase these.
I checked the new expectations in three ways.
- I ran the soundex, metaphone, dmetaphone and daitch_mokotoff
queries for '-hello', '3M', '!(at)#', Knight, queen, zebra, thing,
shoe, Smith, Judge and 'a[b' and '123' on the patched build.
They return H400, M000, empty, NFT, KN, SBR, 0NK, X, SM0/XMT,
JJ/AJ, {070000} and empty, as in the .out file.
- I compared the 44 metaphone(w, 10) rows with Perl Text::Metaphone,
and soundex of the three inputs above with Perl Text::Soundex.
All agree.
- I compared the 80 dmetaphone rows with the python Metaphone
package (doublemetaphone, cut to 4 characters). 31 are equal.
43 differ only because that package leaves the alternate code
empty when it equals the primary. I saw this in the printed rows
and did not re-run with that normalised. 6 rows differ: Hugh
(python HH), Jose (JS/HS, patch HS/HS), Dumb (TMP, patch TM),
Rogier (RJ/RKR, patch RJ/RJR), Wojciech (AJSX, patch AJSK) and
Raj (looks equal, I did not find why my script flagged it).
I did not look into these. They may be differences between the
two implementations, and the test only records the current
behaviour, so I do not see a problem for this patch.
I also ran the contrib tests on the patched tree with:
- default (LANG=en_US.utf8)
- LANG=C.UTF-8 and ENCODING=UTF8
- LANG=en_US.UTF-8 and ENCODING=UTF8
- NO_LOCALE=1 and ENCODING=SQL_ASCII
- NO_LOCALE=1 and ENCODING=LATIN1
All five passed (2 of 2 tests each). The new lines use only ASCII.
What I did not test: the meson build and coverage-html target (I used
autoconf with gcov and lcov 2.0, not lcov 1.16); other platforms (one
Linux build); which expected file fuzzystrmatch_utf8 used in each
encoding; the remaining dmetaphone rows against the C code; non-ASCII
input; check-world, pgindent, and the back branches; and whether the
new tests fail when the code is broken (no mutation testing).
Small suggestions: the commit message subject has a typo ("imporve"),
and Reviewed-by and Discussion still say TODO FIXME.
I have no objection to the patch from what I could test.
Regards,
Joao Rito
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joao Rito | 2026-11-16 06:07:08 | Re: GiST multirange index scans can fail to return rows |
| Previous Message | Hayato Kuroda (Fujitsu) | 2026-11-16 05:53:13 | RE: Patch for migration of the pg_commit_ts directory |