pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Thomas de Zeeuw <thomasdezeeuw@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Parsing of hex encoding strings
Date: Mon, 05 Oct 2026 16:10:26 +0200
Message-ID: <1f2d35acc290d5644cac1217048745ff156e4af0.camel@cybertec.at> (raw)
In-Reply-To: <F330A994-8F69-4D51-A0FB-0559492B0342@gmail.com>
References: <CC9C0072-98AF-4014-820C-F65BAF575346@gmail.com>
	<088bd47f443ee4b8f657e3dbfadf611a560aa95d.camel@cybertec.at>
	<F330A994-8F69-4D51-A0FB-0559492B0342@gmail.com>

On Mon, 2026-10-05 at 12:58 +0200, Thomas de Zeeuw wrote:
> Not great that the first thing I read that this a design error, especially since
> you’re not familiar with the entire system. In any case, allow me to expand on
> why we do it this way.

I could only go by what you told us, and as you said "strings", I assumed you were
talking about character strings, not binary data.  Full-text search is no good for
binary data, even if encoded - it is only useful for natural language strings.

> We have various columns that we want to search, most of them are English text
> (or at least some kind of human language). However, one of them is a public key
> encoded as a hex string. We want to search all those columns in single query
> and since most of them are English text we decided on full text search. We
> imagined one of the words in the search vector would simply be the hex encoded
> public key. This actually works pretty well for our use case, with the exception
> of the case I’ve described in the original email.
> 
> The trigram search doesn’t work well for the English text columns we have.
> We could do the trigram search just for the hex encoded public key, but we
> thought it would return too many false positives given that we’re only
> interested in exact and prefixed matches. The similarity searching property
> of trigrams would be negative here as we could include public keys that’s
> we're not searching for.

If all you want to do is prefix matches and exact matches, I would use an
ordinary LIKE with a regular B-tree index.  That should work well, unless
the public keys are large.  In that case, you could try the ^@ operator
and an SP-GiST index.  Or resort to trigrams.

> We’ll resort to converting the hex encoded public key to a vector/query
> by casting instead of using the various functions for this.

No idea what a vector/query is, but good if it works for you.

Yours,
Laurenz Albe






view thread (5+ messages)  latest in thread

Message-ID: <1f2d35acc290d5644cac1217048745ff156e4af0.camel@cybertec.at>
Permalink:  ../1f2d35acc290d5644cac1217048745ff156e4af0.camel@cybertec.at/
Also on:    postgresql.org/message-id/1f2d35acc290d5644cac1217048745ff156e4af0.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, thomasdezeeuw@gmail.com
  Subject: Re: Parsing of hex encoding strings
  In-Reply-To: <1f2d35acc290d5644cac1217048745ff156e4af0.camel@cybertec.at>
  References: <CC9C0072-98AF-4014-820C-F65BAF575346@gmail.com> <088bd47f443ee4b8f657e3dbfadf611a560aa95d.camel@cybertec.at> <F330A994-8F69-4D51-A0FB-0559492B0342@gmail.com> <1f2d35acc290d5644cac1217048745ff156e4af0.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox