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 1vRlUJ-004Pq5-1U for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Dec 2025 06:09:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRlUI-00B2oL-0B for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Dec 2025 06:09:46 +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 1vRlUH-00B2oC-2Y for pgsql-bugs@lists.postgresql.org; Sat, 06 Dec 2025 06:09:46 +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 1vRlUF-003Ohs-1l for pgsql-bugs@lists.postgresql.org; Sat, 06 Dec 2025 06:09:45 +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 5B669aWg2107638; Sat, 6 Dec 2025 01:09:37 -0500 From: Tom Lane To: Dean Rasheed cc: Oleg Ivanov , Laurenz Albe , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19340: Wrong result from CORR() function In-reply-to: <1872685.1764973053@sss.pgh.pa.us> References: <19340-6fb9f6637f562092@postgresql.org> <4ab9867066e9545dd1a7e835a480bb0ecbe1a00d.camel@cybertec.at> <375068.1764696127@sss.pgh.pa.us> <434484.1764707203@sss.pgh.pa.us> <513345.1764717860@sss.pgh.pa.us> <531516.1764721052@sss.pgh.pa.us> <545890.1764725276@sss.pgh.pa.us> <923070.1764802351@sss.pgh.pa.us> <1872685.1764973053@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 05 Dec 2025 17:17:33 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2107636.1765001376.1@sss.pgh.pa.us> Date: Sat, 06 Dec 2025 01:09:36 -0500 Message-ID: <2107637.1765001376@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > Dean Rasheed writes: >> Looking at float8_regr_accum(), I think it would be preferable to >> arrange for it to leave Sxx, Syy, and Sxy zero until distinct X and Y >> values are seen. I.e., something like this: > That seems like a good idea. I was initially worried that the extra > isnan() checks would slow down aggregation noticeably in the normal > case where we soon discover that the inputs aren't all equal. BTW, re-reading the patch, I now think we should drop the initial if (isnan(commonX) || isnan(commonY)) test, instead bulling ahead with computing tmpX/tmpY/scale, and only skip the updates of Sxx/Syy/Sxy when we have constant inputs. Using that initial test is optimizing for constant inputs at the expense of non-constant inputs, which seems like the wrong way to bet. regards, tom lane