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 1wDQYU-002xEd-1r for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Apr 2026 17:31:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDQYS-006ToB-29 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Apr 2026 17:31:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wDQYS-006To3-0w for pgsql-hackers@lists.postgresql.org; Thu, 16 Apr 2026 17:31:04 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDQYO-00000001LXU-0wuF for pgsql-hackers@postgresql.org; Thu, 16 Apr 2026 17:31:03 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (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 4fxQ5s2wxwzyQw; Thu, 16 Apr 2026 20:30:57 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1776360658; 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=sGE/c8D3Kn8HqFhyXkO/f3btk8TO0GWPqdSIppw/18M=; b=cSem1k1q/KP7HoD0xxWG4pSBYAEgeVY5mvWTHki3QYJ8THMb7F1UAK3xY9ax3cIBAbvaF2 HSk0qFKN31Hk7JhiI143evBhrJdwqmS+u7FGzw7M/W+wPhojiPXb2ux9+YkYMEtpQBNFdr FrhywTfRplZ0MHaAPR8Cw1pkJJmQonI= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1776360658; b=jVT6lXixB6C7YX5aoKWLe4h6iVICH2xhcCKF2Mh1WB0i6lz8Uf4I/puoPS/o3UjTvlnzIs u11qJnXzVy2JvKrIH35d7kp0WlG6f1sYP5T22QYX+6AU4o5PFDV5s3O0KHYzNtCJuryfWr wzYjLGD/Y2J9wfLnAgDCLxrVOAa/pZA= 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=1776360658; 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=sGE/c8D3Kn8HqFhyXkO/f3btk8TO0GWPqdSIppw/18M=; b=qgcEZWBG7H+UBCaZuA5o8R1XtcYLcHqHz7rUyNQpJjME7ETVKUxhxJwE4NspMeqNqlZ7ZQ FkfzMBDA2mEfnv3CzWr3ditLJRM82NWMa36o7dr5FV8yxPgddH36keK3ySKbXxM4+tiuUT vog9pFkUknzhOa9Fll/75ZF34QGYdB8= Message-ID: <37ce5cce-66ca-4216-ae88-af39c444042d@iki.fi> Date: Thu, 16 Apr 2026 20:30:51 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reduce build times of pg_trgm GIN indexes To: Tom Lane Cc: Peter Eisentraut , David Geier , 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> <195097d6-64cd-4adb-b8a3-1d86ae31c411@iki.fi> <2197023.1776288324@sss.pgh.pa.us> <4c1f88d7-5102-45b3-94e3-86d7e4b46b0a@eisentraut.org> <99ce20a5-793a-4182-9120-f274fbef9bfd@iki.fi> <2340004.1776350271@sss.pgh.pa.us> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <2340004.1776350271@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 16/04/2026 17:37, Tom Lane wrote: > Heikki Linnakangas writes: >> On 16/04/2026 11:45, Peter Eisentraut wrote: >>> What I'm missing here is, essentially where the previous thread stopped: >>> What is the overall message that we want to communicate with the API? > > Good point. > >>> If the default assumption is that what pointers converted to Datums >>> point to should not be modified on the other side (where the Datum is >>> converted back to a pointer), then the current declaration of >>> PointerGetDatum() is suitable, and the GIN code can be considered an >>> exception and we make a special API for that. The previous thread >>> proposed NonconstPointerGetDatum(). > > I think there can be no doubt that most functions receiving a > pass-by-ref Datum are not supposed to scribble on the pointed-to > data. So it makes sense to me that PointerGetDatum should carry > an implication of const-ness, and then we need to invent a new > notation to use in the small number of places where that's not > appropriate. I'd capitalize it as NonConstPointerGetDatum, > but other than that nit that naming suggestion seems fine to me. That makes sense. My worry is that we're changing the rules in a very subtle way: It used to be OK to use PointerGetDatum(), pass the resulting datum to something that modifies it. Now we say it's not OK, and you must use NonConstPointerGetDatum(). You don't get any compiler warnings if you use it wrong, except for this one coverity warning apparently, but it doesn't catch this reliably either. > Of course, then the *real* question is why DatumGetPointer > doesn't deliver a const pointer. But I don't see how to get > there without extremely invasive changes. Good point. >> We could have all three: > > Not excited about making massive changes for this. Having all three would be a very localized change in postgres.h. > I remain far less certain than Peter is that this discussion has > anything to do with why Coverity is complaining about > ginExtractEntries. I still think we should make some minimum-effort > change to see if the complaint goes away before expending a lot of > brain cells on choosing a final fix. I think I'm going to commit my proposal to turn PointerGetDatum() back into a macro, and see if that makes Coverity happy. Then we'll know, and we can decide on the next steps. Any objections? One open question is whether we should backpatch any of this. I guess compilers don't misoptimize this in practice, or we would've gotten more reports, but I really can't rationalize why not and a new compiler version might well start hitting this. - Heikki