Re: Reduce build times of pg_trgm GIN indexes

David Geier <geidav.pg@gmail.com>

From: David Geier <geidav.pg@gmail.com>
To: Heikki Linnakangas <hlinnaka@iki.fi>, Tom Lane <tgl@sss.pgh.pa.us>
Cc: Matthias van de Meent <boekewurm+postgres@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-04-14T07:02:10Z
Lists: pgsql-hackers
> I didn't do it for performance, but because I find the function easier
> to read that way. We could change it back.
> 
> It's a pretty scary thought that a compiler might misoptimize that
> though. In the same function we have 'nullFlags', too, as a local
> variable, even before this commit. Not sure why Coverity doesn't
> complain about that.
> 
>> /*
>>  * PointerGetDatum
>>  *        Returns datum representation for a pointer.
>>  */
>> static inline Datum
>> PointerGetDatum(const void *X)
>> {
>>     return (Datum) (uintptr_t) X;
>> }
> 
> Hmm, is that 'const' incorrect? This function doesn't modify *X, but the
> resulting address will be used to modify it. Maybe changing it to non-
> const "void *X" would give Coverity a hint.

Ah, that could be it.
Is there a way for me to run Coverity on a patch to test that out?

Which Coverity CI do we actually use? Is it this one here [1]?

[1] https://scan.coverity.com/projects/209?

--
David Geier



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Change PointerGetDatum() back to a macro

  2. Replace deprecated StaticAssertStmt() with StaticAssertDecl()

  3. Optimize sorting and deduplicating trigrams

  4. Optimize sort and deduplication in ginExtractEntries()

  5. Inline ginCompareAttEntries for speed