Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wD17k-002WTd-0Z for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2026 14:21:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wD17e-00HLNL-30 for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2026 14:21:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wD12r-00GUKM-1v for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2026 14:16:46 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wCy4i-00000001CRM-0JNz for pgsql-hackers@postgresql.org; Wed, 15 Apr 2026 11:06:30 +0000 Received: from [10.0.2.15] (unknown [130.41.208.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4fwdcX668vzyPs; Wed, 15 Apr 2026 14:06:20 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1776251182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i7nyx8AVSTdiYJSHrODXgTtDtxBlG1NNlIxWtC3ISuo=; b=KbM7o7LXHhhpOwWwE9WhaES0vEh81/FbiFcDad/dE32fMIZs7ZF3ONsBIxH+kdEZSBdjp3 9pON0cpzFMSl3wGZMqkR1DB3y/Fjkv0qHDy+WDqY80TzM+tzjLHUd1YtEwJnCE5HXlfTMX 90nrBX9M9w2VKOYHvZuKhGVHN5d1CIA= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1776251182; b=Ja5OZyBuCAhTHov7YTKRITK6/lER/hF+bjiqeVnKZME5ZHX8HJqT6SoNBGG0wcilWD71gO 3WpYrAo0JOY1aVEz7QK/WSigED+C32jjQNMAYg5py/AGGC/ikplPzGUwESK9KAGa5xwzY4 di96kZXFWFu+3OhOOtlLP1HbFzHkDBg= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1776251182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i7nyx8AVSTdiYJSHrODXgTtDtxBlG1NNlIxWtC3ISuo=; b=qmSVFjoZFIhYULKnfEZtWYpkgyHIvNbRto8fcR1GjhPVq7JSqEaV8u/9po5pZrAq2xw8Jd CkbTTwzOgQIJMUf/1NPCZTS1HmO8BX5jmcmPaoUQtPYOJIaYTJiOiAkpbpWOFulHlPq4Qt 4F6J7NBH6cme3sq1Rrb658qvjDFyjW0= Message-ID: <195097d6-64cd-4adb-b8a3-1d86ae31c411@iki.fi> Date: Wed, 15 Apr 2026 14:06:14 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reduce build times of pg_trgm GIN indexes To: David Geier , Tom Lane , Peter Eisentraut Cc: Matthias van de Meent , pgsql-hackers References: <5d366878-2007-4d31-861e-19294b7a583b@gmail.com> <9ac3931a-180e-4283-a7a8-05eb66099206@iki.fi> <2e11134f-02c3-43da-8c39-fb520a1a251d@iki.fi> <66620ec7-0f81-4813-9cf1-b901a56efcc3@gmail.com> <2a76b5ef-4b12-4023-93a1-eed6e64968f3@gmail.com> <6439c655-e281-409d-b884-6586750d5820@iki.fi> <342012.1776017102@sss.pgh.pa.us> <8f3fab0e-02e1-4948-9683-224fe54e30ae@iki.fi> <77cc23dd-ac53-4bb9-9e90-0019c9ff58df@gmail.com> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <77cc23dd-ac53-4bb9-9e90-0019c9ff58df@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 14/04/2026 10:02, David Geier wrote: >> 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. This was briefly discussed when PointerGetDatum() was changed from a macro to a static inline function [1]. On that email, Peter pointed out that the compiler was doing the same deduction that Coverity did now, i.e. that if you pass the Datum returned by PointerGetDatum(&foo) to a function, it cannot change *foo. I'm surprised we dismissed that worry so quickly. If the compiler optimizes based on that assumption, you can get incorrect code. Three alternative fixes were discussed on that thread. Here's a fourth one that I think is better; #define PointerGetDatum(X) \ ((Datum) (uintptr_t) (true ? (X) : NULL)) I found this trick with the dummy conditional expression at [2]. It always evaluates to just (X), but it has the effect that you get a compiler error if (X) is not a pointer. [1] https://www.postgresql.org/message-id/812568f2-ff1d-ebd9-aee6-e00d8f2e0fb6%40enterprisedb.com [2] See "TO_VOID_PTR_EXPR()" at https://medium.com/@pauljlucas/generic-in-c-d7ab47e3b5ab > Ah, that could be it. > Is there a way for me to run Coverity on a patch to test that out? Not really I'm afraid. I can commit a fix and we'll see if it helps the next time that Coverity runs (= Sunday). > Which Coverity CI do we actually use? Is it this one here [1]? > > [1] https://scan.coverity.com/projects/209? Yeah, that's the one, but only the security team has access. - Heikki