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.94.2) (envelope-from ) id 1uhXA0-000znm-06 for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Jul 2025 17:33:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uhX9w-002dlM-H9 for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Jul 2025 17:33:40 +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.94.2) (envelope-from ) id 1uhX9w-002dlD-7T for pgsql-hackers@lists.postgresql.org; Thu, 31 Jul 2025 17:33:40 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uhX9t-0003Ev-1t for pgsql-hackers@lists.postgresql.org; Thu, 31 Jul 2025 17:33:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56VHXZT22093713; Thu, 31 Jul 2025 13:33:36 -0400 From: Tom Lane To: Tomas Vondra cc: Peter Eisentraut , pgsql-hackers@lists.postgresql.org Subject: Bug in brin_minmax_multi_distance_numeric() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2093711.1753983215.1@sss.pgh.pa.us> Date: Thu, 31 Jul 2025 13:33:35 -0400 Message-ID: <2093712.1753983215@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Per the discussion in [1], I think we need something like - PG_RETURN_FLOAT8(DirectFunctionCall1(numeric_float8, d)); + PG_RETURN_DATUM(DirectFunctionCall1(numeric_float8, d)); in brin_minmax_multi_distance_numeric(). Peter was proposing that as cosmetic cleanup, but I think it's actually a functional bug that needs to be back-patched. It is certainly broken on 32-bit machines where the Datum result of numeric_float8 will be a pointer, so that we will convert the numeric pointer value to a float and return that, yielding a totally-garbage distance value. But I think it's broken on 64-bit machines too, because we'll be interpreting the output of numeric_float8 as a uintptr_t and applying some unwanted conversion to make that a float. It's not clear to me exactly what this function is used for, but I guess the consequences would be broken BRIN indexes on numeric columns? regards, tom lane [1] https://www.postgresql.org/message-id/2091622.1753982274%40sss.pgh.pa.us