Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns

From: Atsushi Ogawa <atsushi(dot)ogawa001(at)gmail(dot)com>
To: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Cc: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns
Date: 2026-09-18 14:40:27
Message-ID: CAEah3=P9wOCK=LRtCJnn7tMaRaKJ5k6pwQaGPW8F9gvz2D+Gbg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Greg,

Thanks for the suggestions.

The attached v4 updates the copyright notices in both new files and folds
the deterministic locale check into the initial checks, removing the local
variable and duplicate fallback block.

Regards,
Atsushi Ogawa

2026年9月17日(木) 21:35 Greg Sabino Mullane <htamfids(at)gmail(dot)com>:

> 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
>
>

Attachment Content-Type Size
v4-0001-Use-Boyer-Moore-Horspool-for-simple-LIKE-patterns.patch application/octet-stream 28.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-09-18 14:41:04 Re: [PATCH] Reject nonpositive Bloom filter element estimates
Previous Message Alvaro Herrera 2026-09-18 14:29:20 Re: Race conditions in logical decoding