Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns - Mailing list pgsql-hackers

From Greg Sabino Mullane
Subject Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns
Date
Msg-id CAKAnmmLBS+x1+TXNV-JYnF8VKrmyNB3qk-Tadwssiu9Dy2TQ_g@mail.gmail.com
Whole thread
In response to Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns  (Atsushi Ogawa <atsushi.ogawa001@gmail.com>)
Responses Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns
List pgsql-hackers
Glad to see all the refinement happening with this patch. Some less important things:

> * Portions Copyright (c) 1996-2026

This looks like new code. Unless you were working on this in 1996, the copyrights for the new files (like_bmh.c and like_bmh.h) should be

# Copyright (c) 2026, PostgreSQL Global Development Group

See e.g. src/backend/commands/repack_worker.c


+       if ((pg_database_encoding_max_length() > 1 &&
+                GetDatabaseEncoding() != PG_UTF8) ||
+               !OidIsValid(collation) ||
+               !like_bmh_pattern_is_eligible(p, plen, &literal_len))
+       {
+               state = MemoryContextAlloc(flinfo->fn_mcxt, sizeof(LikeBMHState));
+               state->mode = LIKE_BMH_GENERIC;
+               flinfo->fn_extra = state;
+               return state;
+       }
+
+       locale = pg_newlocale_from_collation(collation);
+       if (!locale->deterministic)
+       {
+               state = MemoryContextAlloc(flinfo->fn_mcxt, sizeof(LikeBMHState));
+               state->mode = LIKE_BMH_GENERIC;
+               flinfo->fn_extra = state;
+               return state;
+       }

locale is only used in this one place, so we can remove that var and avoid writing that same code block twice by rolling the deterministic locale check directly into the first set of checks:

if ((pg_database_encoding_max_length() > 1 &&
         GetDatabaseEncoding() != PG_UTF8) ||
        !OidIsValid(collation) ||
        !like_bmh_pattern_is_eligible(p, plen, &literal_len) ||
        !pg_newlocale_from_collation(collation)->deterministic)

Cheers,
Greg

pgsql-hackers by date:

Previous
From: Ayush Tiwari
Date:
Subject: Re: pgoutput: schema cache cleanup after streamed 2PC
Next
From: Vik Fearing
Date:
Subject: Re: ANSI SQL proposal: SELECT DISTINCT ON (... ORDER BY ...) and UNION DISTINCT ON (... ORDER BY ...)